@mrjoops opened this Issue on September 22nd 2016

AMP (Accelerated Mobile Pages) sites are gaining traction, and tracking data with this technology is a bit more complicated than with pure HTML/JS: https://www.ampproject.org/docs/reference/extended/amp-analytics.html

Sure we can use the pixel image fallback method for basic tracking, but what about becoming an AMP Analytics vendor ? This would be a great way to promote Piwik at a reasonable cost.


@mattab commented on September 22nd 2016 Owner

Thank you @mrjoops for the great suggestion! we will definitely consider it as Piwik needs to be on this list. Google is pushing hard for AMP so this is becoming very important.

If you have knowledge or able to help on this, we would very much welcome your help :+1:

@mrjoops commented on September 23rd 2016

The second link is worth a read, with example pull requests from Xiti and comScore, but I don't have the required Piwik knowledge to answer the questions raised in the document.

@FiloSottile commented on December 8th 2016

There's no need to become a vendor (which probably wouldn't work with self-hosted instances). The JSON specifying the config can be specified by the AMP page (see docs).

<amp-analytics config="https://example.com/analytics.config.json"></amp-analytics>

The PIWIK instance could return a config generated based on the site configuration (like enabling link and timer handlers), and offer a simple snippet like the above for integration in one's AMP site.

In the meantime, an example JSON would also be useful and a valid intermediate iteration.

A more complete implementation would then use the variables to submit all the information in the URL even if custom Javascript can't be run.

@tsteur commented on December 8th 2016 Owner

It would be certainly nice to have in Piwik but looking through docs etc would take quite a while. Maybe someone can work out a JSON that could be used and we add later some logic? Also what is the easiest way to test the tracking? Ideally we would also report in the UI whether AMP was used. Something like this might work but I have not tested it:

<script type="application/json">
  "requests": {
    "base": "https://example.com/analytics?a=${account}&u=${canonicalUrl}&t=${title}",
    "pageview": "${base}",
    "event": "${base}&e_c=${eventCategory}&e_n=${eventName}&e_a=${eventAction}"
  "vars": {
    "idsite": "1"
  "triggers": {
    "trackPageview": {
      "on": "visible",
      "request": "pageview"
    "trackAnchorClicks": {
      "on": "click",
      "selector": "a",
      "request": "event",
      "vars": {
        "eventName": "42",
        "eventCategory": "link",
        "eventAction": "click"
@mattab commented on December 15th 2016 Owner

There was an article written about AMP and Piwik: http://www.elftronix.com/guide-to-using-piwik-analytics-with-amp-on-wordpress/

@mattab commented on August 7th 2017 Owner

If anyone can help adding support for AMP and issuing a pull request, it would be great :+1:

@djallet commented on August 27th 2017

Mixing https://github.com/Automattic/amp-wp and http://www.elftronix.com/guide-to-using-piwik-analytics-with-amp-on-wordpress/ here is a way to use Piwik Pixel without modifying single.php of AMP :

add_action( 'amp_post_template_footer', 'xyz_amp_add_pixel' );
function xyz_amp_add_pixel( $amp_template ) {
    $post_id = $amp_template->get( 'post_id' );
    <amp-pixel src=”//www.myawesomewebsite.com/piwik/piwik.php?idsite=[ID_NUMBER]&rec=1&action_name=TITLE&urlref=DOCUMENT_REFERRER&url=CANONICAL_URL&rand=RANDOM”></amp-pixel>
@mrjoops commented on August 28th 2017

I think some people are missing the point here. As I wrote in my opening post:

Sure we can use the pixel image fallback method for basic tracking, but what about becoming an AMP Analytics vendor ? This would be a great way to promote Piwik at a reasonable cost.

The point isn't only about making Piwik "just" work with AMP, the point is to make it work the good and easy way, and also promoting Piwik.
The pixel method is too limited, you lose too much information.
The @tsteur method may work (not tested) but it's not what I'd call easy.

In my company, AMP are mainly integrated and deployed by programmatically-unskilled people (some marketing-oriented "webmasters"). They can copy/paste a tag, but don't ask them to edit even some JSON. They publish contents on the web without much consideration for the underlying technical stuff.
How many times did I found a corporate web page with a GA tracker in it, while everything in our IT used Piwik, just because they didn't know that Piwik could work with it ? The answer is: way too much.
They are very kind people, they just don't want to know how Internet works, it just have to work. As a developer, my work is to make their lives easier (for better and for worse).
My company isn't alone in this case.

So in the name of those people who think it won't work because it's not listed on https://www.ampproject.org/docs/guides/analytics/analytics-vendors, and because we want Piwik to be used by real people (not only the open-source/privacy nerds), please become an AMP analytics vendor.

Powered by GitHub Issue Mirror