Reputation: 35
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?
Appreciate your help!
Upvotes: 0
Views: 890
Reputation: 533
You also can map into ia_document
object in javascript. Documentation for that is here.
<figure class="op-tracker">
<iframe>
<script>
// The URL the user shared
var urlSharedByUser = ia_document.shareURL;
// The article title
var title = ia_document.title;
// Referrer is always set to 'ia.facebook.com'
var referrer = ia_document.referrer;
</script>
</iframe>
With that template, you can map this into your Wordpress Instant Articles settings like so:
<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','ga');
ga('create', 'UA-XXXXXXXX-X', 'auto');
ga('require', 'displayfeatures');
ga('set', 'campaignSource', 'Facebook');
ga('set', 'campaignMedium', 'Social Instant Article');
ga('send', 'pageview', { title: ia_document.title });
</script>
Upvotes: 0
Reputation: 111
My script looks like this:
<figure class="op-tracker">
<iframe>
<!-- Google Analytics Code -->
<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-XXXXXXX-XX', 'auto'); // Replace with your Google Analytics Account
ga('set', 'campaignSource', 'Facebook');
ga('set', 'campaignMedium', 'Social Instant Article');
ga('send', 'pageview', {title: 'POST TITLE'}); // Replace POST TITLE with real post title
</script>
<!-- End Google Analytics -->
</iframe>
</figure>
Remember you have to put that into body-part of your instant article.
Upvotes: 0