Google has started rolling out GA4 for web, android and iOS. Website publishers have now started exploring the new dashboard and migrating their different properties to the new Google Analytics 4. After all, this is the dashboard which every website publishers checks before starting & wrapping their day.
Although the implementation on regular web pages is very simple and guided via steps but setting it up for the AMP pages is seeming to be a challenge as no proper documentation is available on amp.dev or any other parallel official channels.
Team Sortd. has been doing research on AMP tracking behaviour and how you could easily integrate new GA4 analytics in your AMP pages.
Follow below steps for easy integration of GA4 on your AMP pages :
1. Create GA4 property and keep the tracking id ready. Please check the below screenshot for reference.
2. Place / Check the below AMP Analytics code in your AMP page <head> section :
<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>
3. Place the below code in your AMP page, just after <body> tag :
<amp-analytics type="googleanalytics" config="https://www.<Your-site>.com/ga4.json" data-credentials="include">
<script type="application/json">
{
"vars": {
"GA4_MEASUREMENT_ID": "G-XXXXXXXXXX",
"GA4_ENDPOINT_HOSTNAME": "www.google-analytics.com",
"DEFAULT_PAGEVIEW_ENABLED": true,
"GOOGLE_CONSENT_ENABLED": false,
"WEBVITALS_TRACKING": false,
"PERFORMANCE_TIMING_TRACKING": false,
"SEND_DOUBLECLICK_BEACON": false
}
}
</script>
</amp-analytics>
You could enable and disable different analytics configuration variables inside tracking code i.e Pageviews, Core Web Vitals tracking etc. Please ensure you keep “DEFAULT_PAGEVIEW_ENABLED : true” to make sure all pageviews are getting tracked.
Keep following this space for more updates on the AMP Analytics and similar topics.
If you are a news and media publisher, Increase your website monetisation with SORTD. Publishers of all sizes rely on Sortd. to deliver rich content and better engagement to their customers & increase the revenue with high quality, customisable mobile web solutions.
Feel free to reach out to us on helpdesk@sortd.mobi for any queries.