keepcalculator

06 Numbers and Powers

Migrate Analytics & Marketing Tags to Google Tag Manager

Card No. 06·42305 · Updated · Standard formula, shown below

Migrating your analytics and marketing tags (like Google Analytics, Facebook Pixel, or LinkedIn Insight) into Google Tag Manager (GTM) centralizes tag management, speeds up page loads, and lets you update tracking without touching code. This guide walks you through moving existing tags into GTM, from planning to publishing, and includes common pitfalls and troubleshooting.

What You’ll Need

  • Administrative access to your website’s code (or a developer who can add a snippet).
  • Access to your current tag accounts (e.g., Google Analytics, Google Ads, Facebook Pixel) to copy IDs and verify data.
  • A Google account to create a GTM container.
  • A list of all tags currently on your site—use a browser extension like Wappalyzer or inspect your page source.
  • Optional but recommended: a staging or test environment to verify before going live.

Step-by-Step

  1. Inventory Your Existing Tags. Open your site in a browser, view source (Ctrl+U or Cmd+U), and search for common tag snippets: gtag('config', 'UA-XXXX'), fbq('init'), LinkedIn, Hotjar, etc. Note each tag’s provider, ID, and the pages it fires on. Also check your tag management tools (e.g., GA admin, Facebook Events Manager) for any custom events you’ve set up.
  2. Create a GTM Container. Go to tagmanager.google.com, sign in, and click Create Account. Enter an account name (usually your company), a container name (your website domain), and select Web as the target platform. Click Create and accept the terms.
  3. Install the GTM Snippet. After creating the container, GTM shows two code snippets. Copy the first snippet and paste it into your site’s <head> section, as high as possible. Copy the second snippet and paste it immediately after the opening <body> tag. If you use a CMS like WordPress, use a plugin (e.g., Insert Headers and Footers) or a theme option. If you have a developer, they can add it to your template.
  4. Recreate Your Tags in GTM. In GTM, go to Tags > New. Choose a tag type—for Google Analytics, pick Google Analytics: Universal Analytics or Google Analytics: GA4 Configuration depending on your version. For Facebook Pixel, choose Facebook Pixel. Fill in the tracking ID or Pixel ID from your inventory. For GA4, you’ll need your Measurement ID (starts with G-).
  5. Set Up Triggers for Each Tag. Every tag needs a trigger to tell GTM when to fire. For a basic pageview tag, select All Pages trigger. For event tags (e.g., form submissions, button clicks), create a trigger based on the event—like Click > All Elements and set a condition (e.g., Click Text contains “Submit”).
  6. Add Variables for Dynamic Data. If your tags need dynamic values (e.g., product price, user ID), create variables in GTM. Go to Variables > New, choose a variable type (e.g., Data Layer, DOM Element, Cookie). For data layer variables, you’ll need to push data via dataLayer.push() in your site’s code.
  7. Test in Preview Mode. Click Preview in GTM. This opens a debug console. Enter your website URL and click Connect. Your site will load with GTM in debug mode, showing which tags fire on each page and why. Verify that your tags fire correctly on the intended pages and events.
  8. Submit and Publish. Once testing passes, click Submit in GTM. Name your version (e.g., “Migrate GA + FB”), add a description, and click Publish. The new tags go live immediately.
  9. Remove Old Tags. After confirming GTM tags are firing (check your analytics real-time reports), remove the old tag snippets from your site’s code. This reduces page weight and avoids double-counting. Be careful to remove only the old snippets, not the GTM snippet.
  10. Verify Data Flow. Wait 24-48 hours and compare data in your analytics tools. Check that pageviews, events, and conversions match previous levels. If numbers drop, you may have missed a tag or trigger.

Common Mistakes

  • Forgetting to remove old tags—this causes duplicate tracking, inflating your analytics and potentially skewing ad optimization.
  • Using the wrong trigger type—e.g., firing a click tag on all pageviews, or a pageview tag on every click.
  • Not testing thoroughly—skipping preview mode can lead to broken tags that go live.
  • Ignoring data layer—if your site relies on dataLayer for ecommerce or custom events, you must ensure it’s implemented correctly in GTM, or you’ll lose that data.
  • Publishing without a rollback plan—GTM versions allow rollback, but you need to know how to do it quickly.

Tips

  • Use a consistent naming convention for tags, triggers, and variables (e.g., “GA4 – Pageview – All Pages”) to keep your workspace organized.
  • Leverage GTM’s built-in variables (e.g., Click URL, Page Path) to reduce custom code.
  • For complex migrations, create a migration document mapping each old tag to its new GTM tag and trigger.
  • Use GTM’s Tag Sequencing to control the order of tags that depend on each other.
  • Enable Built-in Variables like Page URL and Referrer to make triggers easier.

Troubleshooting

  • Tags not firing in preview: Check the trigger conditions—often the trigger is too restrictive (e.g., Page Path doesn’t match). Use the debug console’s tag list to see why a tag didn’t fire (e.g., “Condition not met”).
  • Double counting in analytics: This usually means old tags are still present. Use browser dev tools to check for multiple instances of the same tracking ID. Remove the old snippets.
  • Data layer variables returning undefined: Ensure your dataLayer.push() calls happen before GTM loads, or use a Data Layer variable with a default value. Also check that the variable name matches exactly (case-sensitive).
  • Tags fire on wrong pages: Review your trigger’s conditions. For example, a trigger with “Page Path contains /checkout” will also fire on /checkout-success. Use “equals” or “matches regex” for precision.
  • GTM container not loading: Verify the GTM snippet is in the correct location (head and body). Check for JavaScript errors in the console that might prevent GTM from executing.
  • Rollback needed: Go to Versions in GTM, find the last working version, click the three-dot menu, and choose Restore. Then submit and publish the restored version.

Frequently Asked Questions

Do I need to keep the old tags after migrating?

No, you should remove them after verifying GTM tags are firing correctly. Keeping them causes duplicate data.

Can I migrate Google Analytics 4 (GA4) and Universal Analytics at the same time?

Yes, but you’ll need separate tags for each. If you’re still using Universal Analytics, create a UA tag; for GA4, create a GA4 Configuration tag. You can run both during a transition period.

What if I don’t have access to the website code?

You’ll need a developer or someone with CMS admin access to install the GTM snippet. Without it, GTM cannot load.

How long does the migration take?

It depends on the number of tags. A simple site with 5 tags can be done in a few hours, including testing. Complex sites with many custom events may take days.

Will migrating affect my historical analytics data?

No, historical data remains in your analytics tools. The migration only affects future data collection.

Can I use GTM for tags that are not from Google?

Yes, GTM supports many third-party tags like Facebook Pixel, LinkedIn Insight, Hotjar, and custom HTML tags.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →