Асинхронный код Google Analytics - PullRequest
1 голос
/ 22 июня 2010

Я использую новый асинхронный код Google Analytics. Было бы правильно дважды вызывать GA.js на одной странице, если нет, есть ли способ сделать это?

Моя проблема в том, что мне нужно зарегистрировать два PageViews в форме бронирования, используя флэш, проблема в том, что пользователю не нужно обязательно переходить ко второму этапу, а закрывать окно на первом этапе.

  <!-- 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);
  })();

  }

1 Ответ

1 голос
/ 23 июня 2010

Должно работать следующее:

  <!-- 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']);    
  }

Затем при желании вызвать completed() со вспышки.

...