我正在使用Google Analytics的新异步代码,在同一页面中两次调用GA.js是否正确,如果没有,有没有办法做到这一点?
我的问题是我需要使用flash在预订表格上考虑两个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);
})();
}
答案 0 :(得分:1)
以下内容应该有效:
<!-- 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()
。