最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google Universal Analytics tracking code generating an empty page - Stack Overflow

programmeradmin1浏览0评论

It is the first time i am using the new version of Google Analytics (Universal Analytics), so when i put the below code imediatally before </head> i get blank pages for all my URLs.

Here is the code given by Google:

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics/analytics.js','ga');

  ga('create', 'UA-1234567-89', 'mysite');
  ga('send', 'pageview');

</script>

Someone knows why it is happening? Seems to be a bug, but i don't know how to solve this.

It is the first time i am using the new version of Google Analytics (Universal Analytics), so when i put the below code imediatally before </head> i get blank pages for all my URLs.

Here is the code given by Google:

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics./analytics.js','ga');

  ga('create', 'UA-1234567-89', 'mysite.');
  ga('send', 'pageview');

</script>

Someone knows why it is happening? Seems to be a bug, but i don't know how to solve this.

Share Improve this question edited Oct 22, 2013 at 11:37 Marcio Mazzucato asked Oct 21, 2013 at 18:39 Marcio MazzucatoMarcio Mazzucato 9,31511 gold badges70 silver badges81 bronze badges 9
  • 1 Try debugging in your browser's dev tools. I would open the Chrome "Network" panel to see if there are any redirects taking place, or any JS / HTML loaded that is breaking the site. Use the "Preserve Log upon Navigation" option to make sure you don't miss anything. Also look for JS errors in the Console. – providencemac Commented Oct 21, 2013 at 18:51
  • @providencemac, The page is ming totally empty. If i remove the tracking code it works normally. This is very strange – Marcio Mazzucato Commented Oct 21, 2013 at 18:55
  • 1 Can you share you site with Universal Analytics in it (the empty page)? Are there any errors in the console? – Nick Blexrud Commented Oct 21, 2013 at 19:13
  • 1 @MarcioSimao This problem is server-side, if there is no data being sent to the client as you claim. Sounds like you have a template engine that doesn't like JavaScript. – Brad Commented Oct 21, 2013 at 21:14
  • 1 @MarcioSimao Ha, I wondered. I also use Smarty and have had this exact same problem before. {literal} tags are what you need, since Smarty uses brackets by default for its delimeters. – Brad Commented Oct 21, 2013 at 22:42
 |  Show 4 more ments

1 Answer 1

Reset to default 8

Based on @Brad ment i detected that PHP Smarty was crashing with Universal Analytics code tracking, so i found this post:

Use {Literal} Smarty Tag to Add Google Analytics Tracking Code to BlogSome Hosted Blogs

And then i did like below and the tracking code works perfectly!

<script>

    {literal}

    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics./analytics.js','ga');

    ga('create', 'UA-1234567-89', 'mysite.');
    ga('send', 'pageview');

    {/literal}

</script>
发布评论

评论列表(0)

  1. 暂无评论