相关疑难解决方法(0)

新的Google Analytics代码到外部文件中

新的Google Analytics代码如下所示:

<script type="text/javascript">

 var _gaq = _gaq || [];
 _gaq.push(['_setAccount', 'UA-0000000-00']);
 _gaq.push(['_trackPageview']);

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

</script>
Run Code Online (Sandbox Code Playgroud)

如何将全新的Google Analytics异步跟踪代码移动到外部JavaScript文件中?

我特别要问"var _gaq = _gaq || []; [...]"因为我知道可以移动其余部分,例如

的index.html

<script type="text/javascript">

 var _gaq = _gaq || [];
 _gaq.push(['_setAccount', 'UA-0000000-00']);
 _gaq.push(['_trackPageview']);

</script>
<script src="include.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)

include.js

function includeGA()
{
 var ga = document.createElement('script'); ga.type = 'text/javascript'; …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery google-analytics

14
推荐指数
3
解决办法
2万
查看次数

标签 统计

google-analytics ×1

html ×1

javascript ×1

jquery ×1