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
- Open your Google Tag Manager container
- In the left sidebar, click on “Variables”
Step 2: Create a New User-Defined Variable
- Scroll down to the User-Defined Variables section
- Click the “New” button
- Name your variable: Constant – GA4 Measurement ID
Step 3: Configure the Variable
- Click “Variable Configuration”
- Choose Constant (under “Utilities”)
- In the value field, paste your GA4 Measurement ID
→ Format: G-XXXXXXXXXX
Step 4: Save the Variable
- Click Save
Now this variable is ready to be used inside any GA4 tag.
How to Use the Variable in a GA4 Tag
- Go to Tags → Choose your GA4 Configuration Tag or create a new one
- In the Measurement ID field, click the variable icon () on the right
- Select your variable: {{Constant – GA4 Measurement ID}}
This will dynamically insert the stored ID every time the tag fires.
Step 5: Preview and Test
- Click Preview to enter GTM debug mode
- Test your GA4 events to ensure they fire correctly
- Open GA4 Realtime reports or Tag Assistant to verify that the correct Measurement ID is being used