Google AMP and Instant Articles

I did a search of the Piwik forums and was unable to find anything here.

So, quick question.

I use a Wordpress website [BESTpedia.in] and I use Piwik. I do not use Google Analytics.
I would like to make my website compatible with Google AMP and Facebook Instant Articles, but it seems that these two do not recognise the Piwik tracker. As a test, I temporarily enabled Google Analytics and it was recognised.
Is there anyway to get Piwik to work with these two? Or do I have to contact Facebook Developer support [that’s the easy bit], or Google [that’s the tough bit]?

1 Like

Ok.
So, Facebook Instant articles lets you add a custom tracking code where I have inserted my Piwik code.
However, I’m unable to find any answers for compatibility with Google AMP.

Hi,
According to the AMP project; for third-party (as stated by Google) Analytics platforms like Piwik, they have suggested getting in touch with the developers, hence I am posting this here:

Will Piwik be compatible with AMP anytime soon?

For Instant Articles I’m trying to use this script:

<!-- Piwik -->
<script>
  var _paq = _paq || [];
  _paq.push(['setCookieDomain', '*.xxx']);
  _paq.push(['setDomains', ['*.xxx']]);
  _paq.push(['setDocumentTitle', ia_document.title]);
  _paq.push(['setCustomUrl', ia_document.shareURL]);
  _paq.push(['setReferrerUrl', ia_document.referrer]);
  _paq.push(['setCampaignNameKey', 'InstantArticles']);
  _paq.push(['enableHeartBeatTimer', 5]);
  _paq.push(['trackAllContentImpressions']);
  _paq.push(['enableLinkTracking']);
  _paq.push(['trackPageView']);
  (function() {
    var u="//xxx/";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', 2]);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Piwik Code -->

Based on what I’ve found at Analytics - Instant Articles - Documentation - Facebook for Developers
ia_document.title is the title, ia_document.shareURL is the URL and ia_document.referrer is fixed to “ia. facebook .com”.

It’s working fine but I’m not getting the ReferrerUrl and CampaigName in my piwik stats. If anyone has some suggestion on how to improve my script I would really appreciate :wink:

Tip: you can test the analytics using www.ia-tracker.fbsbx.com/instant_article_test?url=[article-url] without need to open on mobile phone

I used similar code for Google Analytics and it works fine:

<!-- GoogleAnalytics -->
<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-XXXXXXXX-2', 'auto');
  ga('set', 'anonymizeIp', true);
  ga('set', 'campaignName', 'Instant Articles');
  ga('set', 'campaignSource', 'Facebook');
  ga('set', 'title', ia_document.title);
  ga('set', 'referrer', ia_document.referrer);
  ga('set', 'location', ia_document.shareURL);
  ga('send', 'pageview');
</script>
<!-- End GoogleAnalytics -->

Thanks for your help

Regards
Fabio

1 Like

Sorry for digging this out, but my tracking code for matomo (piwik) is not working in Instant articles. The came up in matomo as normal visitors (but I set a Campaign) and according to the facebook dev page I should see ia.facebook.com as referrer, right?

Hi there,

I am using the following code, and it is working perfectly for Facebook Instant articles. It amend the Page title.

<figure class="op-tracker">
    <iframe>
        <script>
            var _paq = _paq || [];
            _paq.push(["setCookieDomain", "*.xxx"]);
            _paq.push(["setDomains", ["*.xxx"]]);
            _paq.push(["setDocumentTitle", "FBAI" + ia_document.title]);
            _paq.push(["setCustomUrl", ia_document.shareURL]);
            _paq.push(["setReferrerUrl", ia_document.referrer]);
            _paq.push(["setCampaignNameKey", "InstantArticles"]);
            _paq.push(["enableHeartBeatTimer", 5]);
            _paq.push(["trackAllContentImpressions"]);
            _paq.push(["enableLinkTracking"]);
            _paq.push(["trackPageView"]);
            (function () {
                var u = "{{analytics.mysite.com}}/";
                _paq.push(["setTrackerUrl", u + "matomo.php"]);
                _paq.push(["setSiteId", 1]);
                var d = document,
                    g = d.createElement("script"),
                    s = d.getElementsByTagName("script")[0];
                g.type = "text/javascript";
                g.async = true;
                g.defer = true;
                g.src = u + "matomo.js";
                s.parentNode.insertBefore(g, s);
            })();
        </script>
    </iframe>
</figure>