Google Analytics 4 + AMP pages

Teguh Arief

Aug 09, 2023

Share article to

Google Analytics 4 + AMP pages.

Currently Google Analytics 4 the only analytics processing data and working from July 1, 2023. Including AMP pages requires Google Analytics 4.

Google Analytics 4 tracking solution for AMP pages, supports the integration with the consent module from AMP.

All the needed pieces of AMP pages tracking information available to perform a fully working tracking with Google Analytics 4, including the session tracking and the needed switched to have the, first_visit, session_start, user_engagment events generated.

So let's dive in...

There are two steps to implement it.

  1. Custom Code in <body>

  2. AMP Plugin in <header>

Custom Code in <body>

<amp-analytics type="googleanalytics" config="" data-credentials="include">
<script type="application/json">
"vars": {

Note: Replace “G-XXXXXXXXXX” with your GA4 measurement ID in the above snippet and place that code in header of AMP pages.

AMP Plugin in <header>

<script async custom-element="amp-analytics" src=""></script>

Configuration Settings

Feature NameDescription
GA4_ENDPOINT_HOSTNAMEOverride the default endpoint domain. In case you want to send the hits to your own server or a Server Side GTM Instance.
GOOGLE_CONSENT_ENABLEDa &gcs parameter will be added to the payloads with the current Consent Status
WEBVITALS_TRACKINGIf you enable this a webvitals event will fire 5 seconds after the page is visible
PERFORMANCE_TIMING_TRACKINGWhatever you want to push a performance_timing event including the current page load performance timings
DEFAULT_PAGEVIEW_ENABLEDIf enabled a page_view event will fire on the page load

Related Posts