Google Analytics Missing analytics.js script

2019-07-13 19:17发布

问题:

I'm stucked on copying google analytics tracking code issue. It looks like Google Tag Assistant doesn't consider the code I copied from the generated GA tracking JS for the site.

The site is in http://www.orchid.co.nz/

I added the codes on the header. This should work correctly like what I'm doing with the other sites I worked with. However, this one is weird. I can't figure what's wrong.

Anything I missed?

回答1:

Not sure if this will fix the issue, but you are telling the browsers to parse the script as "rocketscript":

<script type="text/rocketscript">
  (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.com/analytics.js','ga');
....

I don't know what rocketscript is and I guess neither does the Tag Assistant. Try to change this to "javascript" or not to use a type attribute at all.

Here is a discussion about rocketscript, apparently this is part of some Cloud technology and requires a special plugin in Wordpress.

I see tracking calls in the network tab of the browser, so it looks like the problem might very well be purely cosmetic (altough chromes GA debugger extension does not pick up the calls, either).



回答2:

This error is caused by Cloudflare as it implements rocketscript to speed up the web load speed. Disabling the cloudflare will fix this but you don't need to do that. There is simple code to make cloudflare ignore that particular javascript code. Simply Change

<script type="text/javascript">

to

<script type="text/javascript" data-cfasync="false">

This is most efficent way.. Thanks :)



回答3:

it might be late but the solution for this is : adding the option data-cfasync="false" in your analytics.js.

this has to do with cloudflare Seee reference here http://www.aodba.com/fix-redundant-hostname-warning-google-analytics/



回答4:

The quick solution. If nothing works with the code: Turn off the feture. Menü: Speed ->Rocket Loader™ BETA -> Off