0

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!

Community
  • 1
  • 1
query_question
  • 35
  • 1
  • 1
  • 6

2 Answers2

0

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.

weekender
  • 111
  • 1
  • 3
0

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>
Shawn
  • 513
  • 9
  • 18
  • trying to follow the logic here. why declare var title = ia_document.title; if you type it out again in {title: ia_document.title} – 1Bladesforhire Feb 22 '17 at 22:31
  • You're right. You wouldn't. That was from Facebook's docs. ia_document should be globally available for you in production articles. – Shawn Feb 22 '17 at 22:34
  • Thanks. I was wondering if you needed the top script for the bottom script to work. – 1Bladesforhire Feb 22 '17 at 23:01