If you are setting up tracking for a web project, you will eventually face a decision: should I use Google Tag Manager or hardcode my tracking? It is a debate that often pits marketing teams against developers.
Marketers love Google Tag Manager (GTM) because it gives them the autonomy to deploy tracking codes, conversion pixels, and heatmaps without waiting for development sprint cycles. Developers, on the other hand, often dislike GTM. They view it as a security risk and a performance bottleneck that bypasses standard code reviews and fills the site with unoptimized third-party JavaScript.
The truth is that both approaches have clear tradeoffs. The choice between them depends entirely on who is managing your site, how often your marketing campaigns change, and how strictly you need to optimize for web performance.
The case for Google Tag Manager: agility and control
Google Tag Manager is a tag management system that allows you to manage and deploy marketing pixels through a single container snippet. Instead of editing your site's source code, you write triggers and variables inside the GTM web interface.
The advantages of this approach are significant:
- Autonomy for marketing: Once developers install the main GTM container, the marketing team can deploy new tags for Google Ads, Meta, LinkedIn, and newsletter signups on their own. This removes the developer bottleneck entirely.
- Centralized organization: All tracking tags, custom variables, and trigger logic live in one dashboard. You do not have to search through dozens of theme templates or code files to figure out where a specific conversion event is defined.
- Standardized events: GTM makes it easy to track complex user behaviors, like form submissions, video progress, scroll depth, and outbound link clicks, using built-in trigger templates. Doing this with custom code requires writing custom event listeners.
For companies running active paid acquisition campaigns across multiple platforms, GTM is almost always the default choice because it allows the marketing team to test new tools quickly.
The case for hardcoding: speed, security, and version control
Hardcoding involves pasting the raw JavaScript snippets (such as the global gtag.js script or the Meta pixel base code) directly into the header or footer of your site's HTML templates.
For performance-first engineering teams, this is the preferred method:
- Maximum loading speed: GTM adds an extra layer of JavaScript that the browser must download, parse, and execute before it can run the actual tracking scripts. Hardcoding removes this GTM container wrapper, allowing the browser to load the primary analytics script immediately.
- Clean version control: Hardcoded tags are part of your codebase. They go through your standard git workflow, peer code reviews, and testing environments. This prevents a non-technical teammate from accidentally publishing a broken script that breaks your checkout flow.
- Enhanced security: GTM represents a single point of failure. If a malicious actor gains access to your GTM account, they can inject custom HTML tags containing scripts to steal customer data or insert spam. Hardcoding limits your exposure.
If your site is relatively static, has low marketing complexity, and priorities speed above all else, hardcoding is the superior choice.
Want a website that turns visitors into customers, not just compliments?
Book a 15-min introThe GTM bloat problem: hurting your Core Web Vitals
The most critical argument against GTM is tag accumulation. Because GTM makes it incredibly easy to add new scripts, containers often become digital junk drawers.
I routinely audit GTM containers that load:
- Three different analytics packages (GA4, Hotjar, Microsoft Clarity).
- Retargeting pixels for ad platforms the company stopped using in 2024.
- Custom HTML scripts designed to test a UI change that was built into the main theme months ago.
Every active tag inside GTM represents an external network request and CPU execution time in the user's browser. Even if the tag does not fire, the browser still has to evaluate the trigger logic.
This accumulation directly drags down your Core Web Vitals. Having dozens of active event listeners waiting for user clicks will clog the browser's main thread. When a user tries to interact with the page, the browser hesitates, resulting in a poor Interaction to Next Paint (INP) score. If you struggle with site speed, the solution is often pruning your GTM container, not optimizing your server.
B2B SaaS: performance vs. marketing agility
For B2B SaaS platforms, the tradeoff is particularly sharp. A SaaS site needs to load fast to convert organic search traffic and pass core speed requirements. However, it also requires detailed campaign tracking to justify ad spend.
For these sites, I recommend a hybrid approach:
- Hardcode your primary tag: Hardcode your primary analytics tool (like Google Analytics 4) directly in the HTML. This ensures it loads as fast as possible and captures the maximum number of visits before users bounce.
- Use GTM for temporary marketing pixels: Deploy Meta, LinkedIn, and temporary conversion tracking tags through GTM.
- Establish a strict tag governance policy: Treat GTM with the same respect as your codebase. Set a schedule to audit the container every quarter, deleting any tag that is not actively feeding a live reporting dashboard.
The ultimate compromise: server-side GTM
If you have a complex tracking setup and cannot compromise on page speed, the modern solution is server-side GTM.
Under this setup, you load a single, lightweight GTM container on your site. Instead of running twenty marketing scripts in the browser, the container sends a single data stream to a cloud server container you control. That server then processes the events and forwards them to Google, Meta, and LinkedIn behind the scenes.
This gives you the interface control of GTM while keeping the performance profile of a hardcoded site. Your frontend does not load any third-party marketing scripts, resolving your Core Web Vitals issues while preserving marketing's ability to configure conversions.
If your GTM container has become a disorganized mess that drags down your Lighthouse scores, a structured performance and tag audit can identify the bloat. Strip out the dead weight and design a tracking architecture that supports your growth without sacrificing your site speed.