我想知道是否有办法跟踪某些广告(只是带有链接的图片)的点击次数和观看次数,这些广告将随机出现在容器div中。如果我可以通过Google Analytics页面上的广告ID获取这些值。
<center><div id="MP_AD_CONTAINER">
<a href="http://www.superbock.pt" target="_blank"><div id="super_bock_ad" class="ad"></div></a>
<div id="EDP_ad" class="ad"></div>
<div id="Sisab_ad" class="ad"></div>
</div></center>
<script>
//Array with Id of divs to show:
var Ids = ["super_bock_ad", "EDP_ad", "Sisab_ad"];
//Chose a Id randomly:
var chosenValue = Ids[Math.floor(arrayDeIds.length * Math.random())];
var chosenDiv = document.getElementById(chosenValue);
//Shows the chosenDiv inside container:
chosenDiv.style.display = "block";
// Counter to call a function giveTheViews() only once:
var count = 0;
document.getElementById('MP_AD_CONTAINER').addEventListener("click", function(){
//Google analytics code to track clicks From chosenDiv (?)
_gaq.push(['_trackEvent', 'Interactions', 'Click', chosenValue]);
});
window.onscroll = function(ev) {
//Test to know if the div was seen:
if (window.innerHeight >= (document.getElementById("MP_AD_CONTAINER").getBoundingClientRect().top +(document.getElementById("MP_AD_CONTAINER").offsetHeight / 2) )) {
if(count == 0){
getTheViews();
count = 1;
}
}
};
function getTheViews(){
//Hey Google Analytics! Save the number of people that view this ad!
_gaq.push(['_trackEvent', 'Images', 'View', chosenValue]);
}