How To Add Google Analytics To AMP WordPress Websites

Looking to add Google Analytics to your AMP WordPress website? All you may need is to include the AMP Analytics scripts to your header.php file in WordPress.

Tracking page views in Google Analytics

To track page views in Google Analytics on your AMP WordPress website you need to follow the following steps below.

  1. Navigate to Appearance > Editor > Theme Header (header.php) from your WordPress Dashboard;
  2. Include the AMP Analytics script below, between the <head></head> tags;
  3. Include the AMP Analytics page view JSON right after your <body> tag.

Between the <head></head> tags:

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

After the opening <body> tag:

<amp-analytics type="googleanalytics">
<script type="application/json">
  {
    "vars": {
    "account": "UA-your-GA-tracking-code"
  },
  "triggers": {
    "trackPageview": {
      "on": "visible",
      "request": "pageview"
     }
  }
}
</script>
</amp-analytics>