Skip to main content

Google Tag Manager Tracking Guide

Last updated: December 31, 2025

Complete guide to setting up tracking for GA4, Google Ads, and Meta Ads through Google Tag Manager, plus Google Search Console verification.

How do I set up Google Analytics 4?

  1. Go to Google AnalyticsAdminCreate Property
  2. Click through to create a web stream, name everything www.yoursite.com
  3. Copy your Measurement ID (e.g., G-TLD123456)
  4. Go to Google Tag ManagerNew Tag → select Google Tag (not Google Analytics)
  5. Paste your Measurement ID
  6. Click Preview to test
  7. Click Publish

How do I track custom events in GA4?

Custom events track specific user actions like form submissions or button clicks.

Create an event tag

  1. In GTM, go to TagsNew
  2. Click Tag ConfigurationGA4 Event
  3. Enter your Measurement ID
  4. Enter an Event Name (use lowercase with underscores):
    • form_submit
    • generate_lead
    • purchase
    • button_click

Set up the trigger

  1. Click TriggeringNew
  2. Choose trigger type (Form Submission, Click, etc.)
  3. Configure conditions (e.g., Page URL contains “/thank-you”)
  4. Save both trigger and tag
  5. Publish

Standard event names

Event NameWhen to Use
generate_leadContact form submission
purchaseCompleted transaction
sign_upAccount creation
add_to_cartItem added to cart

How do I set up Google Ads conversion tracking?

Get your Conversion ID and Label

  1. Go to Google Ads
  2. Click GoalsConversionsSummary
  3. Click + New conversion actionWebsite
  4. Select conversion type (Lead, Purchase, etc.)
  5. Choose Use Google Tag Manager
  6. Copy the Conversion ID and Conversion Label

Create the Google Ads tag in GTM

  1. In GTM, go to TagsNew
  2. Click Tag ConfigurationGoogle Ads Conversion Tracking
  3. Enter your Conversion ID (e.g., AW-123456789)
  4. Enter your Conversion Label (e.g., AbCdEfGhIjKlMnOp)
  5. Optionally add conversion value and currency

Set up the conversion trigger

  1. Click TriggeringNew
  2. Choose Page View trigger type
  3. Select Some Page Views
  4. Set condition: Page URL contains /thank-you (or your confirmation page)
  5. Name it “Thank You Page”
  6. Save and Publish
  1. Create a new tag → Google Ads Conversion Linker
  2. Set trigger to All Pages
  3. This enables cross-domain tracking and improves attribution

How do I set up Meta Ads (Facebook) tracking?

Get your Meta Pixel ID

  1. Go to Meta Events Manager
  2. Click Connect Data SourcesWebMeta Pixel
  3. Name your pixel and click Create Pixel
  4. Choose Install code manually
  5. Copy your Pixel ID (15-16 digit number)

Create the Meta Pixel tag in GTM

  1. In GTM, go to TagsNew
  2. Click Tag ConfigurationCustom HTML
  3. Paste this code (replace YOUR_PIXEL_ID):
<script>
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'YOUR_PIXEL_ID');
fbq('track', 'PageView');
</script>
  1. Set trigger to All Pages
  2. Name it “Meta Pixel - Base”
  3. Save and Publish

Track Meta Ads conversions

  1. Create a new Custom HTML tag
  2. Add this code for lead tracking:
<script>
fbq('track', 'Lead');
</script>
  1. Set trigger to your thank you page
  2. Save and Publish

Standard Meta events

EventWhen to Use
LeadForm submission
PurchaseCompleted sale
AddToCartItem added to cart
InitiateCheckoutCheckout started
ContactContact button click

How do I set up Google Search Console?

Google Search Console monitors your site’s search performance and indexing status.

Verify your site

  1. Go to Google Search Console
  2. Click Add Property
  3. Choose URL prefix (e.g., https://example.com)
  4. Select a verification method:

Verification options

MethodSteps
HTML fileDownload file → upload to public/ folder → deploy
HTML tagCopy meta tag → add to <head> in layout
DNS recordAdd TXT record to your domain’s DNS
Google AnalyticsAuto-verifies if GA4 is installed

Submit your sitemap

  1. After verification, go to Sitemaps in the left menu
  2. Enter your sitemap URL: sitemap-index.xml
  3. Click Submit

Monitor your site

  • Performance: See clicks, impressions, and rankings
  • Indexing: Check which pages are indexed
  • Experience: Review Core Web Vitals
  • Enhancements: Validate structured data

Fix common issues

IssueSolution
”Not indexed”Check robots.txt, add internal links
”Crawled - not indexed”Improve content quality
”Blocked by robots.txt”Update robots.txt rules
”Redirect error”Fix redirect chains

If you’re using Google Analytics, Meta Pixel, or other tracking tools, you need a cookie policy and consent system to comply with privacy regulations like GDPR and CCPA.

What cookies do these tools set?

ToolCookie NamePurposeDuration
Google Analytics_gaDistinguishes unique users2 years
Google Analytics_ga_*Maintains session state2 years
Google Ads_gcl_auConversion linker90 days
Meta Pixel_fbpTracks visits across sites90 days

Create a consent banner component (src/components/CookieConsent.astro) that:

  1. Shows on first visit with Accept All / Reject All / Customize options
  2. Settings modal with toggles for analytics cookies
  3. “Do Not Sell or Share My Personal Information” checkbox (CCPA requirement)
  4. Detects Global Privacy Control (GPC) browser signals and honors them automatically
  5. Stores preferences in localStorage

Example banner structure:

<div id="cookie-banner" class="fixed bottom-0 inset-x-0 bg-white shadow-lg p-4">
  <p>We use cookies to analyze site traffic.</p>
  <div class="flex gap-2">
    <button id="accept-all">Accept All</button>
    <button id="reject-all">Reject All</button>
    <button id="customize">Customize</button>
  </div>
</div>

In your base layout (src/layouts/BaseLayout.astro), set consent defaults before GTM loads:

<script>
  // Set defaults to denied before any tracking loads
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}

  gtag('consent', 'default', {
    'analytics_storage': 'denied',
    'ad_storage': 'denied',
    'ad_user_data': 'denied',
    'ad_personalization': 'denied'
  });
</script>
<!-- Then load GTM -->

When the user accepts cookies, update the consent state:

// When user accepts analytics cookies
gtag('consent', 'update', {
  'analytics_storage': 'granted'
});

// When user accepts advertising cookies
gtag('consent', 'update', {
  'ad_storage': 'granted',
  'ad_user_data': 'granted',
  'ad_personalization': 'granted'
});

In Google Tag Manager:

  1. Go to your GA4 Configuration tagAdvanced SettingsConsent Settings
  2. Check “Require additional consent for tag to fire”
  3. Add analytics_storage as a required consent type
  4. Repeat for Google Ads tags with ad_storage
See GTM Consent Settings screenshot

GTM Consent Settings showing analytics_storage requirement

Update your Privacy Policy

Your Privacy Policy page (src/pages/privacy.astro) should include:

  1. Cookie tables - Separate essential vs analytics cookies with names, purposes, and durations
  2. “Manage Cookie Preferences” button - Opens the consent settings modal
  3. California Privacy Rights (CCPA/CPRA) section covering:
    • Right to Know what personal information is collected
    • Right to Delete personal information
    • Right to Correct inaccurate information
    • Right to Opt-Out of sale/sharing of personal information
    • Right to Non-Discrimination for exercising privacy rights
    • How to submit privacy requests
    • Categories of personal information collected

Include these links in your site footer (src/components/Footer.astro):

<a href="#" id="cookie-settings">Cookie Settings</a>
<a href="/privacy#california-privacy-rights">Do Not Sell My Info</a>

The “Cookie Settings” link should open the preferences modal. The “Do Not Sell My Info” link (required for CCPA) should jump to the California privacy section.

Detect Global Privacy Control (GPC)

Honor the GPC browser signal automatically:

// Check for GPC signal
if (navigator.globalPrivacyControl) {
  // User has opted out - treat as "reject all"
  gtag('consent', 'update', {
    'analytics_storage': 'denied',
    'ad_storage': 'denied'
  });
}

Checklist

  • Cookie consent banner shows on first visit
  • Settings modal with granular controls
  • “Do Not Sell or Share” checkbox for CCPA
  • GPC browser signal detection
  • Consent Mode v2 defaults set before GTM
  • GA4 tag requires analytics_storage consent
  • Privacy Policy has cookie tables
  • Privacy Policy has CCPA section with all required rights
  • Footer has “Cookie Settings” link
  • Footer has “Do Not Sell My Info” link

Looking for expert guidance? Schedule a free consult:

Book a Free Consultation