2010-06-22 8 views
1

J'utilise un nouveau code asynchrone de Google Analytics, serait-il correct d'appeler GA.js deux fois dans la même page, sinon, y at-il un moyen de faire cela? Mon problème est que j'ai besoin de comptabiliser deux pages vues sur un formulaire de réservation en utilisant le flash, le problème est que l'utilisateur ne doit pas forcément arriver à la deuxième étape mais fermer la fenêtre dans la première étape.Google Analytics Async Code

<!-- Step one, I need to record a pageview --> 

    var _gaq = _gaq || []; 
    _gaq.push(['_setAccount', 'UA-6173481-3']); 
    _gaq.push(['_trackPageview', '/Step1']); 
    (function() { 
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
    })(); 

    <!-- Step two of the process i define a function that will get called by flash and record another pageview--> 

    function completed(){ 

    var _gaq = _gaq || []; 
    _gaq.push(['_setAccount', 'UA-6173481-3']); 
    _gaq.push(['_trackPageview', '/Step2']); 
    (function() { 
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
    })(); 

    } 

Répondre

1

Ce qui suit devrait fonctionner:

<!-- Step one, I need to record a pageview --> 
    var _gaq = _gaq || []; 
    _gaq.push(['_setAccount', 'UA-6173481-3']); 
    _gaq.push(['_trackPageview', '/Step1']); 
    (function() { 
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
    })(); 

    <!-- Step two of the process i define a function that will get called by flash and record another pageview--> 
    function completed(){ 
    _gaq.push(['_trackPageview', '/Step2']);  
    } 

appellent ensuite completed() de flash quand on le souhaite.