文件
瀏覽文件

Track AMP pages with Privatus Analytics

Count pageviews on AMP pages with amp-analytics and the Privatus Analytics pixel endpoint, keep the referrer and report pages under your own domain.

以 Markdown 檢視

AMP pages can't run custom JavaScript, so the tracker doesn't load there. Use amp-analytics to call the pixel endpoint instead.

Add the component script in <head>:

html
<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>

And this in <body>:

html
<amp-analytics>
  <script type="application/json">
    {
      "requests": {
        "pageview": "https://privatusanalytics.com/api/pixel?s=pa_YOURSITEID&u=${canonicalUrl}&r=${documentReferrer}"
      },
      "triggers": {
        "trackPageview": { "on": "visible", "request": "pageview" }
      },
      "transport": { "beacon": false, "xhrpost": false, "image": true }
    }
  </script>
</amp-analytics>
  • u=${canonicalUrl} reports the page under your own domain, so AMP cache domains (cdn.ampproject.org) don't matter.
  • r=${documentReferrer} keeps the traffic source.

AMP pageviews use the no-JavaScript collection path, so there's no time on page, scroll depth or events (see pixel limitations).