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.
1 answers
1
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.
- Navigate to Appearance > Editor > Theme Header (header.php) from your WordPress Dashboard;
- Include the AMP Analytics script below, between the <head></head> tags;
- 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>
— Support WizardAnswer 1