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 [] 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

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.

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 -->
  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]);
  (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);
<!-- 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[article-url] without need to open on mobile phone

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

<!-- GoogleAnalytics -->
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  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');
<!-- End GoogleAnalytics -->

Thanks for your help


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 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">
            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]);
            (function () {
                var u = "{{}}/";
                _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);