Aug 25, 2018

How to enable analytics functionality with Accelerated Mobile Pages (AMP)

There are two ways to enable analytics functionality with AMP:
The Amp-Pixel Element: This is a simple tag that can be used to count page views as a typical tracking pixel would, using a GET request. There are a number of variables that can be passed through it, such as DOCUMENT_REFERRER and Title.
The Amp-Analytics Extended Component: This is a little bit more advanced than the amp-pixel. It is likely what you’ll use to implement analytics on your site because it allows for a greater level of configuration for analytics interactions.
If you aren’t trying to get Google Analytics working, amp-analytics is the way to go. You will need to add the necessary JavaScript library in the <head> and then configure it via some JSON markup in the <body> section of your page.
If you are interested in Google Analytics in AMP, check out the Google’s AMP Analytics section on their developer page. It has several examples of implementations.