Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    correggere script monitoraggio click in un iframe (x tracciare adsense con analytics)

    Buon martedì a tutti

    Ho (ri)trovato, quasi per caso, questo script su Seobook, utile a chi ha un sito con entrambi google adsense + analytics installati, perchè permette di tracciare con google analytics, i click sulle unit adsense.

    Un utente "dopo un po'", nei commenti, suggerisce questi miglioramenti:

    i seguenti paragrafi sono solo estratti incompleti tratti da qui

    IE part: here the script just checks for onfocus. Better: trace onfocus (gets focus) and onblur (loses focus) and onmouseover, onmouseout as boolean flags and check for the link via onbeforeunload. This is way more accurate.

    In Firefox the iFrame swallows the mouseevent. better: track for mouseover, mouseout event and look in the beforeunload event, if you were in the iframe.

    in order to test, just create an own iframe on a page and a document with a link as the content. then replace the 'googlesyndication.com' string in the script
    Volevo realizzare la versione migliorata, ma non riesco a testarlo (non mi parte un alert() che ho messo al posto di urchintracker()... sono un po' bloccato.

    C'è tra voi un'anima pia, che sia disposta ad illustrarmi la via?

  2. #2

    Lo script

    codice:
    function as_click () {
    	urchinTracker ('/asclick');
    }
    
    // incredibly funky onload add-event scripting, for all browsers
    
    		 if(typeof window.addEventListener != 'undefined')
    		 {
    		 	//.. gecko, safari, konqueror and standard
    		 	window.addEventListener('load', adsense_init, false);
    		 }
    		 else if(typeof document.addEventListener != 'undefined')
    		 {
    		 	//.. opera 7
    		 	document.addEventListener('load', adsense_init, false);
    		 }
    		 else if(typeof window.attachEvent != 'undefined')
    		 {
    		 	//.. win/ie
    		 	window.attachEvent('onload', adsense_init);
    		 }
    
    		 //** remove this condition to degrade older browsers
    		 else
    		 {
    		 	//.. mac/ie5 and anything else that gets this far
    
    		 	//if there's an existing onload function
    		 	if(typeof window.onload == 'function')
    		 	{
    		 		//store it
    		 		var existing = onload;
    
    		 		//add new onload handler
    		 		window.onload = function()
    		 		{
    		 			//call existing onload function
    		 			existing();
    
    		 			//call adsense_init onload function
    		 			adsense_init();
    		 		};
    		 	}
    		 	else
    		 	{
    		 		//setup onload function
    		 		window.onload = adsense_init;
    		 	}
    		 }
    function adsense_init () {
    
    	if (document.all) {  //ie
    
    		var el = document.getElementsByTagName("iframe");
    	
    		for(var i = 0; i < el.length; i++) {
    			if(el[i].src.indexOf('googlesyndication.com') > -1) {
    
    				el[i].onfocus =  as_click;
    			}
    		}
    	
    	} else {   // firefox
    	
    		window.addEventListener('beforeunload', doPageExit, false);
    		window.addEventListener('mousemove', getMouse, true);
    	
    	}
    		
    }
    
    //for firefox
    var px;
    var py;
    
    function getMouse(e) {
    	px=e.pageX;
    	py=e.clientY;
    }
    
    function findY(obj) {
    	var y = 0;
    	while (obj) {
    		y += obj.offsetTop;
    		obj = obj.offsetParent;
    	}
    	return(y);
    }
    
    function findX(obj) {
    	var x = 0;
    	while (obj) {
    		x += obj.offsetLeft;
    		obj = obj.offsetParent;
    	}
    	return(x);
    }
    
    function doPageExit(e) {
    
    	ad = document.getElementsByTagName("iframe");
    	for (i=0; i<ad.length; i++) {
    		var adLeft = findX(ad[i]);
    		var adTop = findY(ad[i]);
    		var inFrameX = (px > (adLeft - 10) && px < (parseInt(adLeft) + parseInt(ad[i].width) + 15));
    		var inFrameY = (py > (adTop - 10) && py < (parseInt(adTop) + parseInt(ad[i].height) + 10));
    		
    		if (inFrameY && inFrameX) {
    
    			urchinTracker('/asclick');
    		
    		}
    	}
    
    }
    
    //end for firefox

  3. #3

  4. #4

  5. #5
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649
    ciao Petro_suse,
    ho dato un' occhiata solo alla parte di firefox
    il concetto alla base del sistema secondo me non e' affidabile
    perche' rileva le coordinate all' onmousemove finche ci si muove nel documento,
    mentre quando il movimento si produce sul documento nell' iframe questo chiaramente non scatta

    quindi se ti avvicini lentamente all' iframe puo' funzionare
    se muovi rapidamente il puntatore l' ultima posizione rilevata puo' facilmente non rientrare in questo range
    codice:
    var inFrameX = (px > (adLeft - 10) && px < (parseInt(adLeft) + parseInt(ad[i].width) + 15));
    		var inFrameY = (py > (adTop - 10) && py < (parseInt(adTop) + parseInt(ad[i].height) + 10));
    (che tra l' altro ampliano di un arbitrario 10 e 15 px)

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.