2

I want to share with you the following issue. I have implemented the Facebook Instant articles on my WordPress website via the Instant Articles for WP plugin. The articles show up nicely on Facebook, however, the tracking of an Instant article does not get recorded by Google Analytics. Please help, the code I use in the plugin is as follows (the code is added in the 'embed code' field of the plugin:

<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.com/analytics.js','__gaTracker');

__gaTracker('create', 'MyGAID', 'auto');
__gaTracker('set', 'forceSSL', false);
__gaTracker('send','pageview', {title: 'POST TITLE'});</script>

I have researched the issue on the Internet and still did not find the solution, the above code is suggested here:

https://github.com/Automattic/facebook-instant-articles-wp/issues/321

Another highly relevant topic to the issue is this one: How to track content Statistics for Facebook Instant Articles with Google Analytics

Do you have any ideas/improvement suggestions how to get the Instant Articles tracking by Google Analytics work?

1

Google Analytics recently updated its tracking code to the Global Site Tag or gtag.js format. Below is the Google Analytics embed code for Instant Articles using gtag.js:

<figure class="op-tracker">
<iframe>

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-X"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments)};
gtag('js', new Date());

gtag('set', 'page_title', 'Instant Articles: '+ia_document.title);

gtag('config', 'UA-XXXXXXXX-X');
</script>

</iframe>
</figure>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.