Google Tag Manager

⌘K
  1. Home
  2. Google Tag Manager
  3. Google Tag Manager Tracki...
  4. Storing GA4 Measurement ID in a User-Defined Variable

Storing GA4 Measurement ID in a User-Defined Variable

Objective

To store your Google Analytics 4 (GA4) Measurement ID inside a User-Defined Variable in GTM so it can be reused across multiple tags and updated in one place.

Why This Approach?

  • Easier maintenance: You only need to update your Measurement ID in one place.
  • Cleaner tag setup: Makes tags easier to manage, especially if you have multiple environments (e.g., staging vs production).
  • Reduces human error when duplicating tags.

Step 1: Go to GTM → Variables

  1. Open your Google Tag Manager container
  2. In the left sidebar, click on “Variables”

Step 2: Create a New User-Defined Variable

  1. Scroll down to the User-Defined Variables section
  2. Click the “New” button
  3. Name your variable: Constant – GA4 Measurement ID

Step 3: Configure the Variable

  1. Click “Variable Configuration”
  2. Choose Constant (under “Utilities”)
  3. In the value field, paste your GA4 Measurement ID
    → Format: G-XXXXXXXXXX

Step 4: Save the Variable

  1. Click Save

Now this variable is ready to be used inside any GA4 tag.

How to Use the Variable in a GA4 Tag

  1. Go to Tags → Choose your GA4 Configuration Tag or create a new one
  2. In the Measurement ID field, click the variable icon () on the right
  3. Select your variable: {{Constant – GA4 Measurement ID}}

This will dynamically insert the stored ID every time the tag fires.

 Step 5: Preview and Test

  1. Click Preview to enter GTM debug mode
  2. Test your GA4 events to ensure they fire correctly
  3. Open GA4 Realtime reports or Tag Assistant to verify that the correct Measurement ID is being used

How can we help?