const start = Date.now();
const events = ["canplay","play","pause"];
var mediaData = [];
function sendData(mediaID,action,value) {
	var xhr = new XMLHttpRequest();
	xhr.open("POST","https://bauland-aeby.ch/opolytics/media-tracker.php?register_action=" + action,true);
	xhr.addEventListener("load",function() {
		console.log("Tracker returned: " + this.responseText);
	});
	xhr.send();
}
window.addEventListener("load",function() {
	console.log("Starting Opolytics Media Tracking...");
	var audio = document.getElementsByTagName("audio");
	var video = document.getElementsByTagName("video");
	var data = [];
	var i;
	for (i = 0; i < video.length; i++) {
		var mediaID = video[i].getAttribute("mediaID");
		video[i].setAttribute("mediaID",Date.now());
		sendData(mediaID,"register","somevalue");
		video[i].addEventListener("canplay",sendData.bind(this,mediaID,"canplay",Date.now()));
		video[i].addEventListener("play",sendData.bind(this,mediaID,"play",Date.now()));
	}
	console.log("Opolytics Media Tracking found: ");
	console.log(video);
	console.log(audio);
});