How to Add Google Analytics to AMP Pages on WordPress

How to Add Google Analytics to AMP Pages on WordPress

After installing AMP plugins, you have probably discovered that by default the Google Analytics code is stripped out from all AMP pages. To help with that, we’re going to show you how to add Google Analytics to AMP WordPress using AMP Plugin by Automattic.

 

Add Google Analytics to AMP WordPress

We’ll show you the complete process to this step – the only thing we’ll assume is that you already have added google analytics to your WordPress Site.

AMP By Automattic defines an analytics option to enable the addition of amp-analytics in your posts. When the plugin is active, an AMP top-level menu appears in the Dashboard (1) with sub-menu. Find the sub-menu ‘Analytics’ (2) and click on it:

AMP WordPress
Add Google Analytics to AMP WordPress

Selecting  Analytics in the sub-menu AMP options menu takes us to an Analytics Options entry page, where we can define the analytics tags we want to have, by specifying the vendor type (e.g. googleanalytics) and the associated JSON configuration.

Important Note: The plugin provides very simple validation based solely on the validity of the JSON string provided. It is the user’s responsibility to make sure that the values in the configuration string and the vendor type used are coherent with the analytics requirements of their site.

A Sample JSON Configuration to Page tracking:

This JSON config allows you to measure the number of views for a particular page on your AMP pages.

{
  "vars": {
    "account": "UA-XXXXX-Y"
  },
  "triggers": {
    "trackPageview": {
      "on": "visible",
      "request": "pageview"
    }
  }
}
 Note: The property ID `UA-XXXXX-Y` should be replaced with a real property ID that you own in the code snippet above and rest of the document.
property-ID
Find The Property ID

How to Find AMP Data in Google Analytics

To find AMP data in Google Analytics, log into your Google Analytics account and select the website in which you’d like to find the AMP data.

Go to Behavior » Site Content » All Pages. To view the data of your AMP pages only, use the search bar above the table with the keyword /amp. This will show you the traffic report of your AMP pages only.

AMP - Google Analytics
How to Find AMP Data in Google Analytics

finally,  if you’re monetizing your AMP WordPress Site with Google Analytics, you might also want to customize your AMP Pages/Posts to look like your website for that check The Best Google AMP WordPress Themes.