Constant Variables
A Constant Variable stores a single, static value that you reference across multiple tags, triggers, and other variables. It has one purpose: avoid hardcoding the same string in ten different places.
The concept is trivially simple, but the practice is often overlooked. Every GTM container has configuration values that appear in multiple tags — Measurement IDs, Conversion IDs, API keys, environment identifiers. When those values are hardcoded directly in each tag, updating them means opening every tag individually. When they are stored in Constant Variables, you change one value and every tag picks it up immediately.
Creating a Constant Variable
Section titled “Creating a Constant Variable”- Go to Variables in GTM and click New under User-Defined Variables.
- Select Constant as the variable type.
- Enter your static value in the Value field.
- Name the variable clearly — use a prefix like
CONST - GA4 Measurement IDorCONFIG - Measurement ID. - Save and reference it in your tags using double-brace syntax:
{{CONST - GA4 Measurement ID}}.
The GA4 Measurement ID pattern
Section titled “The GA4 Measurement ID pattern”This is the canonical use case for Constant Variables. Your GA4 Measurement ID (G-XXXXXXXXXX) belongs in a Constant Variable — not hardcoded in the Google Tag.
Why this matters:
-
When you migrate to a new GA4 property, you change one variable and every tag that uses it updates automatically — including your Google Tag and any GA4 Event tags that reference the configuration.
-
In multi-environment setups, you can replace the Constant Variable with a Lookup Table keyed to hostname, pointing to different Measurement IDs for production and staging. All tags still reference the same variable name.
-
In code reviews and audits, reviewing a tag that says
Measurement ID: {{CONFIG - GA4 Measurement ID}}is clearer than one withG-XK4J7M9P2Qhardcoded.
Variable Name: CONFIG - GA4 Measurement IDVariable Type: ConstantValue: G-XXXXXXXXXXReference in the Google Tag:
Measurement ID: {{CONFIG - GA4 Measurement ID}}What belongs in Constant Variables
Section titled “What belongs in Constant Variables”Definitely use Constant Variables for:
- GA4 Measurement IDs (
G-XXXXXXXXXX) - Google Ads Conversion IDs (the number before the
/in your conversion tag) - Google Ads Conversion Labels
- Facebook/Meta Pixel IDs
- Any vendor tag’s account or property identifier
- API endpoints used in Custom HTML tags
- Environment names (
production,staging,development)
Also useful for:
- Cookie names that appear in multiple tags
- Custom dimension names that must be consistent across tags
- Version numbers for your tracking specification
Constant Variables for Google Ads
Section titled “Constant Variables for Google Ads”Google Ads conversion tags require two values: a Conversion ID and a Conversion Label. Both should be Constant Variables:
CONFIG - Google Ads Conversion IDValue: AW-123456789
CONFIG - Google Ads Lead LabelValue: abc123DEFghi
CONFIG - Google Ads Purchase LabelValue: xyz789IJKlmnHaving separate Constant Variables for each label makes it easy to see, in the tag configuration, which conversion action is being tracked.
Upgrading a Constant to a Lookup Table
Section titled “Upgrading a Constant to a Lookup Table”The real power of Constant Variables is that they serve as a single reference point. When you need to extend from “one value” to “one value per environment,” you do not need to update every tag — you just replace the Constant Variable with a Lookup Table using the same variable name.
Before (single environment):
Variable: CONFIG - GA4 Measurement IDType: ConstantValue: G-PROD12345After (multi-environment):
Variable: CONFIG - GA4 Measurement IDType: Lookup TableInput Variable: {{Page Hostname}}Rows: example.com → G-PROD12345 staging.example.com → G-STG67890Default Value: G-DEV11111Every tag in your container that was using {{CONFIG - GA4 Measurement ID}} continues working without modification. The value each tag receives now depends on the hostname.
This is the migration path that makes GTM containers genuinely environment-aware without duplicating tags.
Naming conventions
Section titled “Naming conventions”A consistent naming prefix helps organize variables in a large container. Two common approaches:
By type:
CONST - value description
By category:
CONFIG - GA4 Measurement IDCONFIG - Ads Conversion IDCONFIG - Environment
Pick one and stick with it. The goal is that anyone looking at a tag configuration can immediately understand that {{CONFIG - GA4 Measurement ID}} is a stable, centrally-managed configuration value — not a computed or dynamic value.
Common mistakes
Section titled “Common mistakes”Hardcoding IDs directly in tags
Section titled “Hardcoding IDs directly in tags”// Tag configuration — BADMeasurement ID: G-XK4J7M9P2Q ← hardcoded
// Tag configuration — GOODMeasurement ID: {{CONFIG - GA4 Measurement ID}} ← Constant VariableWhen you have 8 tags that all hardcode the same Measurement ID and you need to change it, you will update 7 and miss one. The tag you missed will silently continue sending to the old property.
Creating one Constant per tag instead of sharing
Section titled “Creating one Constant per tag instead of sharing”If you have a CONST - GA4 ID for Google Tag and a separate CONST - GA4 ID for Event Tags, both with the same value, you have defeated the purpose. One Constant Variable, referenced by all tags that need it.
Not replacing Constants with Lookup Tables when environments differ
Section titled “Not replacing Constants with Lookup Tables when environments differ”Running GTM Preview mode on your staging site and having it send data to your production GA4 property is a real and common problem. The fix is a Lookup Table replacing your Constant Variables, keyed to hostname. Do this before you launch, not after you discover staging data in production reports.
The JavaScript Variable type as an alternative
Section titled “The JavaScript Variable type as an alternative”For values that already exist in JavaScript on the page — a window.CONFIG.measurementId set by your application — use the JavaScript Variable type instead of a Constant. It reads the value from the page at runtime rather than storing it in GTM.
This is even better than a Constant when your application already manages environment-specific configuration, because it means GTM automatically gets the right value without any GTM-side environment configuration.