matomo-org / matomo

Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
https://matomo.org/
GNU General Public License v3.0
19.29k stars 2.59k forks source link

Becoming an AMP Analytics vendor #10539

Open mrjoops opened 7 years ago

mrjoops commented 7 years ago

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.

https://github.com/ampproject/amphtml/blob/master/extensions/amp-analytics/integrating-analytics.md

mattab commented 7 years ago

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 7 years ago

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 7 years ago

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 7 years ago

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:

<amp-analytics>
<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"
      }
    }
  }
}
</script>
</amp-analytics>
mattab commented 7 years ago

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

mattab commented 6 years ago

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

djallet commented 6 years ago

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>
    <?php
}
mrjoops commented 6 years ago

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.

[background-story] 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. [/background-story]

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.

saitho commented 6 years ago

@mattab Are there any plans on AMP support for Piwik in the near future?

mattab commented 6 years ago

@saitho @mrjoops Yes, we'd love to support AMP, but we're lacking resources at the moment. Would anyone be willing to help and lead this effort? we can provide support but can't lead it ourselves at the moment. Thanks

mrjoops commented 6 years ago

I could probably take a deeper look at this, read all the docs and vendor submission procedures, elaborate on a plan and maybe hack a little before the end of the year, if it could help.

sgiehl commented 6 years ago

@mrjoops would be awesome if you could handle that. If you have any questions we can help with, feel free to ask :)

ullahfahad commented 5 years ago

Did any progress happen on this front? I am in the boat of integrating Matomo now and 30% of my traffic out of 2.0million monthly sessions comes from AMP pages.

tsteur commented 5 years ago

We haven't worked on this ourselves but we'd provide any help if someone is keen to make progress on this.

mattab commented 5 years ago

FYI there was a post in the forums which possibly includes a solution: https://forum.matomo.org/t/how-to-add-piwik-to-amp-pages/18424/6

mattab commented 4 years ago

Another article for Matomo and AMP for WordPress: https://ampforwp.com/tutorials/article/how-to-add-matomo-piwik-analytics-in-amp/

mattab commented 4 years ago

What would be the effort to build AMP support for Matomo?

dannyeuu commented 3 years ago

@mattab Any updates here?

atom-box commented 2 years ago

A user wrote, asking if Amp HTML is compatible with Matomo.

He sent a link of which of our peers are used with Amp: https://amp.dev/documentation/guides-and-tutorials/optimize-and-measure/configure-analytics/analytics-vendors/

I see several of the tags are different: https://amp.dev/documentation/guides-and-tutorials/learn/spec/amphtml/

tsteur commented 6 months ago

Hello, if anyone is still interested in this please comment.