I'm trying to get GA's autotrack plugin ( https://github.com/googleanalytics/autotrack ) installed on my WordPress-based blog, but things didn't work out.
My code is as below:
<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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-91255353-1', 'auto');
ga('send', 'pageview');
ga('require', 'autotrack');
</script>
<script async src="http://s01.appmifile.com/stat/autotrack.js"></script>
and here's the url of my blog: pickydigest.com
After my research, I guess the problem is coming from the JavaScript <script async src="http://s01.appmifile.com/stat/autotrack.js"></script>
. Why I'm saying this is that I see No plugin url set for "autotrack".
in the GA debugger no matter how I tried to paste the code in different sequences and different ways.
Moreover, when I used the same method to install the analytics.js plugin ( <script async src="https://www.google-analytics.com/analytics.js"></script>
) as the autotrack Github page suggested, GA failed, not even sending basic pageviews.
However, I can see requests sent to autotrack.js all the time from the Chrome devtools.
I wonder if this is a specific problem to my blog, my browser or anything else, but due to my limited knowledge of JS and other technical stuffs, I don't think I could solve this all by myself, so any help will be appreciated. Thanks in advance :)
Move this line
ga('require', 'autotrack');
before this one :
ga('send', 'pageview');
The documentation says :
Note: It's important that you require the plugin after creating the tracker and before sending the pageview.
After I changed the code to:
ga('require', 'eventTracker');
ga('require', 'outboundLinkTracker');
ga('require', 'urlChangeTracker');
......
It started working. I'm not quite sure why but if anyone happens to have the same problem as I do, maybe this will help. And thanks for @Sanjucta, the ga('require', 'autotrack');
must run before pageview is sent, that's indeed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.