AMP Analytics


We create our pages aiming to provide our audience some quality content in an appealing and fast way, get some clicks on the ads we modestly place here and there and hopefully – get it all together in a way the visitors will come back asking for more – that's a general idea. Aiming to provide a better user experience on mobiles and better Google ratings some of us will maybe try implementing copies of our pages following the AMP standard as well – at this point, this seems like an interesting opportunity nevertheless all the restrictions an HTML document has to meet in order to get verified as Accelerated Mobile Page.

However, how we keep track of what's actually going on with our work? Do somebody stops by or was it all in vain? As we discussed earlier – no other scripts, except for the native AMP one, are allowed on the AMP pages and this includes the tracking scripts we get from our favorite webmaster tools – so, what to do?

In order to try taking care of this the AMP dev team has created the so-called amp-analytics elements which purpose is measuring the activity on the AMP pages you create using AMP Portfolio Template as example and fetching the data wherever needed – like to the analytics platform you got used to or to a user-defined custom URL – in case you are using self-hosted analytics solutions like Piwik, for example.

Tips on how to utilize the Amp Analytics:

In order to be able to include amp-analytics elements in your AMP pages with AMP Map you first need to include the script handling this component in your pages <head> wrapped in a <script> tag like this: <script async custom-element="amp-analytics" src=""></script>

Next, we need to include an <amp-analytics> tag in the <body> to specify some JSON configured objects describing the details which you need to be measured and the destination of the gathered along analytics data.

The amp-analytics element is pre-configured to work with quite a few activity trackers and the list will probably grow up in time so it might be a good idea checking it out from time to time over here:

where you can also get the appropriate value for the element's type attribute like type="baiduanalytics" for example, in case you need tracking your page's activity with China's most popular tracking service.

Next, you need to configure what data you need tracked and send to the vendors.

This can be done either inline or by providing a link to an external JSON file hosted somewhere on your server and fetched via https:// If you have chosen the second option the link to the JSON file should take place as a value to the tag's config attribute. In case you have decided defining what to track inline you need to wrap the definitions in a <script> with "application/json" attribute in which following the JSON syntax the appropriate parameters should be defined.

There are plenty of stuff you might want to be tracking and most probably for each item, there is an AMP variable and available options but this is far too vast for us to consider in our overview here. All the variables for configuring your amp-analitics script you can find over here:

More information tips relating to AMP Analytics

Useful table:

You can certainly operate the <amp-analytics> element to measure activity regarding an AMP file. Inside the <amp-analytics> feature, you specify a JSON settings item that holds the detailed information for exactly what to determine and just where to launch the analytics information. You can surely send the tracking records to an analytics vendor and/or to a WEBSITE ADDRESS. There are undoubtedly numerous analytics suppliers that are pre-configured for <amp-analytics>, notice Analytics Vendors on the official web site for detailed information.


Inside of the coming next good example, we give analytics details to as soon as the AMP file is first launched, and each time an <a> tag is clicked on:

<script type="application/json">

    "pageview": "$canonicalUrl&title=$title&acct=$account",
    "event": "$eventId&elab=$eventLabel&acct=$account"
    "account": "ABC123"
      "on": "visible",
      "request": "pageview"
      "on": "click",
      "selector": "a",
      "request": "event",
        "eventId": "42",
        "eventLabel": "clicked on a link"




Specifies the form of the vendor. For aspects, check the Analytics vendors page.


This is certainly an optional property that can be chosen to launch a structure from a specified distant URL. The URL indicated should apply the HTTPS scheme. See additionally the data-include-credentials<code> characteristic below. The WEBSITE ADDRESS may utilize AMP WEBSITE ADDRESS vars. The action must use the AMP CORS security guidelines. Representation: <code> <amp-analytics config=""></amp-analytics> <amp-analytics type="googleanalytics" id="analytics1"> <script type="application/json"> "vars": "account": "UA-12345-Y" , "triggers": "trackPageview": "on": "visible", "request": "pageview" </script> </amp-analytics>


Arrangement data can be determined inline (as shown in the good example above) or fetched remotely by simply pointing out a URL inside the config feature. On top of that, the integrated configuration for popular analytical vendors can surely be chosen by utilizing the type feature.

If setup data from greater than one of these particular sources is applied, the setup materials (vars, requests, and triggers) will be combined altogether such that (i) distant settings get a lead over inline setup and (ii) inline configuration takes precedence over vendor configuration.

The <amp-analytics> settings material operates the following format :

    request-name: request-value,
    var-name: var-value,
    extraurlparam-name: extraurlparam-value,
    trigger-name: trigger-object,
    "beacon": *boolean*,
    "xhrpost": *boolean*,
    "image": *boolean*


The requests settings object determines the web links applied to transfer details to an analytics platform. The request-name is operated within the trigger arrangement to point out exactly what demand needs to be delivered in answer to a special event. The request-value is an https URL. These types of values may possibly utilize placeholder tokens that can certainly reference additional asks or variables.

  "base": "$account&u=$canonicalUrl&t=$title",
  "pageview": "$base&type=pageview",
  "event": "$base&type=event&eventId=$eventId"


The amp-analytics element determines a lot of helpful variables which can possibly be employed in requests. A listing of all such variables is certainly obtainable in the amp-analytics Variables Guide. In addition, each of the variables sustained by AMP HTML Substitutions Guide are also supported.

The vars settings item can be used to detail new key-value pairs or else override occurring variables which can possibly be related in request values. New variables are generally applied to define author particular data. Arrays can easily be used to identify a selection of values that ought to be URL inputted separately while preserving the comma delimiter.

  "account": "ABC123",
  "countryCode": "tr",
  "tags": ["Swift,Jonathan", "Gulliver's Travels"]


The triggers configuration object defines when an analytics demand ought to be sent out. The triggers characteristic provides a key-value pair of trigger-name and trigger-configuration. A trigger-name can possibly be any string composed of alphanumeric characters (a-zA-Z0-9). Triggers created by a setup with lower precedence are certainly bypassed with triggers through the very same names from a setup with much higher precedence.

Like an illustration, the going next configuration can surely be operated to experience 50% of the inquiries based upon aimless input or at 1% based upon user id

    'on': 'visible',
    'request': 'request',
      'sampleOn': '$random',
      'threshold': 50,
    'on': 'visible',
    'request': 'request',
      'sampleOn': '$clientId(cookieName)',
      'threshold': 1,

Feature selector

Certain triggers just like click and visible enable specifying an one element or a variety of features utilizing the selector properties. Various triggers are able to utilize different constraints and translations on selected components, for example, if a selector involves all matched components or else the first one, or what features can possibly be fit: everyone or else only AMP elements. Check out the documentation for each and every suited trigger intended for extra details.

The selector properties are:

- selector This kind of feature is employed to search for an element or a variety of elements working with CSS/DOM query. The semantics of just how the element is undoubtedly suit can be modified applying selectionMethod. The value of this attribute can possibly be one of:

* a correct CSS selector, e.g. #ad 1 or amp-ad.

* : root - a specialized selector which fit the document root.

- selectionMethod When defined, this feature can have one of two values: scope or closest. scope allows selection of element inside of the parent feature of amp-analytics tag. closest look for the closest ancestor of the amp-analytics tag that satisfies the supplied selector. The default value is scope.

Inserted render launching trigger

AMP elements that implanted additional files inside iframes (e.g., adds) may possibly reveal a render beginning event (" on": " render-start"). This kind of happening is typically emitted as quickly as it's feasible to affirm that rendering of the planted record has launched. Seek advice from the documentation of a particular AMP feature to spot whether it produces this occasion.

The trigger for the embed feature should involve a selector that points to the embedding component:

    "on": "render-start",
    "request": "request",
    "selector": "#embed1"

The render beginning event is additionally given off by document in itself and can possibly be managed as:

    "on": "render-start",
    "request": "request"

Initial load event

The initial load activity (" on": "ini-load") is triggered once the basic materials of an AMP feature or else an AMP document have been actually loaded.

The "initial load" is simply identified in relation to the container and its initial measurements. Even more specifically:

To a document: all of the features in the first viewport.

To an embed component: all of the content components inside of the inserted file that is installed just within the primary proportions of the embed component.

For a plain AMP element (e.g. amp-img): the resources itself, including an illustration or a video.

The trigger for an embed or an AMP element need to involve a selector which points to the component:

    "on": "ini-load",
    "request": "request",
    "selector": "#embed1"

The initial load occurrence is additionally produced by document itself and can be managed as:

    "on": "ini-load",
    "request": "request"

Webpage and component visibility activation

Apply the page visibility trigger ("on": "visible") to fire a request as soon as the page gets obvious. The firing of this particular trigger can surely be built using visibilitySpec.

    "on": "visible",
    "request": "pageview",

The component visibility activator can possibly be configured for any sort of AMP web builder component or a document root applying selector. The trigger will certainly fire when the specified component suit the visibility parameters that can be customized utilizing the visibilitySpec.

    "on": "visible",
    "request": "elementview",
    "selector": "#ad1",
    "visibilitySpec": /* optional visibility spec */

Visibility Specification

The visibilitySpec is a group of states and attributes that can possibly be utilised to visible or else hidden causes to alter once they fire. If numerous properties are specified, they need to all be true usable for a inquiry to fire. Settings properties promoted in visibilitySpec are:

Apart from the states aforementioned, visibilitySpec also helps specific variables that are recorded here.

    "on": "visible",
    "request": "pageview",
    "selector": "#ad1",
      "waitFor": "ini-load",
      "visiblePercentageMin": 20,
      "totalTimeMin": 500,
      "continuousTimeMin": 200

In addition to the variables presented as part of triggers, you are able to likewise establish additional/ overrides for variables just as data characteristic. If used, these data qualities ought to be part of feature identified just as the selector.

Click trigger

Apply the click activator ("on": "click") to start a request as soon as a determined element is clicked. Apply selector to deal with which elements will certainly cause this request to fire. The trigger will begin for all of the features matched by the identified selector.

  "id1": "#socialButtonId",
  "id2": ".shareButtonClass"
    "on": "click",
    "selector": "a, $id1, $id2",
    "request": "event",
      "eventId": 128

Scroll trigger

Operate the scroll activator (" on": "scroll") to fire a request with a number of states as soon as the page is scrolled. This trigger provides particular vars which indicate the limits that activated a request to be sent. Employ scrollSpec to regulate when this will start:

    "on": "scroll",
      "verticalBoundaries": [25, 50, 90],
      "horizontalBoundaries": [90]
    "request": "event"

Timer trigger

Use the timer trigger (" on": "timer") to start a request on a standard time period . Utilize timerSpec to handle as soon as this will start:

- timerSpec Standards for triggers of type timer. The timer will certainly trigger swiftly (by default , can possibly be unset) and at a defined interval afterwards.

* interval Measure of the timer interval, in seconds .

* maxTimerLength Maximum interval for what the timer will launch, in seconds.

* immediate activate timer quickly or not. Boolean, defaults to true

    "on": "timer",
      "interval": 10,
      "maxTimerLength": 600
    "request": "pagetime"

Hidden trigger

Operate the hidden trigger ("on": "hidden") to launch a request when the page becomes hidden.

    "on": "hidden",
    "request": "pagehide",
      "selector": "#anim-id",
      "visiblePercentageMin": 20,
      "totalTimeMin": 3000,

A visibilitySpec can certainly be involved to make sure that an inquiry is only fired assuming that the visibility duration conditions are satisfied.

Access triggers

AMP Access system issues a number of events for other states in the access run. For details on access triggers ("on": "amp-access-*"), discover AMP Access and Analytics.


The transport configuration material indicates ways to send out a request. The value is actually an object with specialties which identity what transport techniques are suitable.

  "beacon": false,
  "xhrpost": false,
  "image": true


So here is how you can keep track on what's going on your AMP pages – surely not the most convenient way around – especially compared to the conventional "Just include the generated script" approach and we suppose here comes the place to ask ourselves – Is it worth? The time will tell. Of course, we should also consider the AMP project is still in development mode so it theoretically possible this procedure to become a bit more lightweight in the future.

Check a number of youtube video information about Amp Analytics:

Linked topics:

AMP Analytics official documents

AMP Analytics given with some good examples

AMP Analytics information by Google

Best Free AI Website Builder

Generate AI websites with a simple prompt! Type in any language, export in zip.

AI Website Builder

Best Free Website Builder Software

Create awesome websites offline! No coding. 9900+ templates. Edit and save locally, upload wherever.

Free website builder download for Win, Mac, Linux!

Latest Posts

  1. AI website maker and generator - experience the future of website creation with AI .
  2. Free AI website generator and creator - create a website design with AI.
  3. Best Website Builder AIBest Free AI Website Builder - Create Website with AI
  4. Best Website Builder for Interior Designs, Digital Marketing Agencies, Travel Agencies
  5. Best Website Builder for Churches, Authors, Consultants, Magazines
  6. Website Builder for Education, Software Companies, Designers, Videos
  7. Website Builder for Beginners, Bloggers, Writers, IT Companies
  8. Website Builder for Online Stores, Restaurants, Musicians, Real Estate
  9. Podcasts and affiliate marketing Website Builder
  10. Best Website Builder For therapists and nonprofits
  11. Website Builder For SEO and portfolio
  12. Best Website Builder For Kids & Musicians
  13. Photographer & Artist Website Builder
  14. HTML Code Generator - HTML Code Generator
  15. Web Design Tool - Web Design Program
  16. Landing Page Maker - Landing Page Generator
  17. Easiest Website Builder For Beginners - No Coding Website Builder
  18. Fantastic HTML Constructor with Drag and Drop or Full Code Editor
  19. Eye-catching HTML Generator You Should Try
  20. Best QR Code Generator Free
  21. Top 11 Wix App Alternative Website Builders
  22. Top 11 Free Wordpress Alternatives Services
  23. Instagram Feed Embed
  24. Really Convenient Business Website Builder Overview
  25. AMP format overview
  26. amp-live-list AMP Blog component
  27. AMP Layout & Media queries
  28. Image galleries and AMP
  29. AMP Font
  30. Using AMP with Bootstrap
  31. AMP SEO
  32. AMP and Wordpress
  33. Facebook Instant Articles vs. Google AMP
  34. AMP Form - amp-form extended examples and tricks
  35. AMP Carousel, amp-carousel advanced examples and tricks
  36. AMP AD
  37. AMP HTML Advanced Examples, Codes, Tags
  38. AMP IFrame - amp-iframe examples and tricks
  39. AMP Validator - Test AMP pages
  40. What is AMP? - Overview