16.09.25
Migrating from a direct gtag.js implementation to Google Tag Manager (GTM) provides greater flexibility, centralised control, and scalability in managing your website tracking and analytics setup. This tutorial explains the steps involved, addresses key questions, and outlines best practices to ensure a smooth transition.
GTM allows you to manage tracking tags (e.g. GA4, Google Ads, Meta Pixel) without directly editing your website’s code. It supports event tracking, consent mode, and enhanced measurement, all in one interface.
For most client websites, we recommend using Google Tag Manager (GTM) instead of embedding individual tracking scripts like gtag.js. GTM allows us to track events such as button clicks, form submissions, file downloads and conversions without needing to modify the site’s code. It also centralises all marketing and analytics tags, supports GDPR consent mode, and integrates smoothly with tools like Google Analytics 4, Google Ads, and Meta Pixel. For ongoing marketing and performance tracking, GTM provides the flexibility, scalability and control we need as an agency.
A: Yes. When migrating to Google Tag Manager, you should remove the existing gtag.js snippet from your site. The process includes a ‘final migration swap’ where you simultaneously remove the old tags and publish your GTM container. This ensures tracking is managed solely through GTM. Having both gtag.js and GTM in your website code can create problems such as data duplication and unpredictable tracking behaviour.
A: No. Enhanced measurement will still work. It is a GA4 feature that tracks page views, scrolls, outbound clicks, file downloads, etc., automatically. When you migrate to GTM, simply configure the GA4 tag in GTM and ensure enhanced measurement is enabled.
A: Yes, but it requires JavaScript, which is why we recommend GTM. Here’s an example code:
const button = document.getElementById(‘my-button’);
button.addEventListener(‘click’, function() {
gtag(‘event’, ‘button_click’, {
‘event_category’: ‘engagement’,
‘event_label’: ‘My Button Clicked’
});
});
This code tracks a custom event, but must be manually added to the website for each button or element so can become cumbersome.
A: Correct. With GTM, you can track button clicks using triggers and tags without editing website code. You can target buttons by ID, class, or text, and configure the event from GTM’s interface.
Signatories of:
Members of:
Innovation House
Molly Millars Close
Wokingham
RG41 2RX