Search code examples
wordpressfacebookgoogle-analyticsfacebook-instant-articles

Facebook Instant Article with (not set) in Google Analytics


I am running a WordPress which using Automattic/facebook-instant-articles-wp. But I realise the traffic tracked for IA showed in GA were unable to show the title.

A lot of website is recommending this for the GA 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','//www.google- analytics.com/analytics.js','ga'); ga('create', 'ANALYTICS ID', 'auto'); ga('require', 'displayfeatures'); ga('set', 'campaignSource', 'Facebook'); ga('set', 'campaignMedium', 'Social Instant Article'); ga('send', 'pageview', {title: 'POST TITLE'}); </script>

Then it end up showing 'POST TITLE' in GA. Anyone have any clue to show the article title?

Thank you.


Solution

  • GA code like this should give you correct titles:

    <script>
     ...
    ga('create', 'XX-XXXXXXXXX-X', 'auto');
    ga('require', 'displayfeatures');
    ga('set', 'campaignSource', 'Facebook');
    ga('set', 'campaignMedium', 'Social Instant Article');
    ga('set', 'title', 'IA - '+ia_document.title); // get your title 
    ga('send', 'pageview');
    </script>
    

    So with ia_document.title you can get article title correct in analytics.

    Here is a Facebook's reference to the issue: https://developers.facebook.com/docs/instant-articles/analytics#analytics-services

    Hope this helps.