The Challenge: One GTM Container, Multiple Live Sites
You’re managing multiple live websites or domains using the same GTM container:
- Main company site (
yourcompany.com
) - E-commerce store (
shop.yourcompany.com
) - Blog or content site (
blog.yourcompany.com
) - Multiple client sites (for agencies)
- Different product lines or brands
The problem: Each site needs its own GA4 property for proper reporting, but managing separate GTM containers creates maintenance nightmares and inconsistent implementations.
The solution: Dynamic measurement ID switching based on the current domain, all within one GTM container.
Why This Advanced Setup Matters
For businesses with multiple properties:
- Clean data separation between different sites/brands
- Unified GTM management (one container to maintain)
- Consistent tracking implementation across all properties
- Simplified tag and trigger management
- Easy addition of new sites without duplicating work
Real-world scenarios:
- Agency managing multiple client websites
- Company with separate e-commerce and content sites
- Multi-brand organizations with distinct properties
- SaaS companies with separate product sites
- Franchise businesses with location-specific sites
Prerequisites
This tutorial builds on our previous posts in this GTM series:
- How to Filter Development Traffic in GA4 Using GTM
- How to Stop Marketing Pixels from Firing on Development Sites
You’ll need:
- Multiple live websites or domains to track
- Separate GA4 properties set up (one for each site)
- Understanding of GTM variables and lookup tables
- Admin access to your GTM container
The Complete Setup
Step 1: Create GA4 Properties for Each Site
In Google Analytics:
Create separate GA4 properties for each site:
- Main Site:
G-MAIN123456
(yourcompany.com
) - E-commerce:
G-SHOP789012
(shop.yourcompany.com
) - Blog:
G-BLOG345678
(blog.yourcompany.com
) - Client A:
G-CLIENTA901234
(clienta.com
)
Pro tip: Use descriptive property names like “YourCompany – Main Site” and “YourCompany – E-commerce” to avoid confusion in reporting.
Step 2: Create Your Domain-to-Site Mapping Variable
Create a new GTM Variable:
Variable name: Regex Table - Site Mapping
Variable type: Regex Table
Input Variable: {{Page Hostname}}
Pattern/Output Configuration:
Pattern: yourcompany.com
Output: main_site
Pattern: shop.yourcompany.com
Output: ecommerce
Pattern: blog.yourcompany.com
Output: blog
Pattern: clienta.com
Output: client_a
Pattern: clientb.com
Output: client_b
Default Value: unknown_site
Advanced Settings:
- ✅ Ignore Case (checked)
- ❌ Full Matches Only (unchecked)
- ❌ Enable Capture Groups (unchecked)
Why this approach: Using descriptive site identifiers makes the lookup table more readable and maintainable than using measurement IDs directly.
Step 3: Create the Dynamic Measurement ID Variable
Variable name: GA4 - Measurement ID - Dynamic
Variable type: Lookup Table
Input Variable: {{Regex Table - Site Mapping}}
Input/Output Configuration:
Input: main_site
Output: G-MAIN123456
Input: ecommerce
Output: G-SHOP789012
Input: blog
Output: G-BLOG345678
Input: client_a
Output: G-CLIENTA901234
Input: client_b
Output: G-CLIENTB567890
Default Value: G-DEFAULT999999
Why use a default: If a new site is added that doesn’t match any patterns, it uses a designated “catch-all” GA4 property rather than breaking tracking.
Step 4: Update Your GA4 Configuration Tag
Edit your main GA4 Configuration tag:
- Tag Type: Google Analytics: GA4 Configuration
- Measurement ID:
{{GA4 - Measurement ID - Dynamic}}
- Trigger: Initialization – All Pages
Remove any hard-coded measurement IDs from this tag. The dynamic variable now handles environment detection automatically.
Step 5: Add Site-Specific Custom Dimensions
Add site identification to all properties:
In your GA4 Configuration tag, add:
- Parameter:
site_identifier
- Value:
{{Regex Table - Site Mapping}}
This creates a custom dimension showing which site each hit came from, useful for:
- Cross-site reporting in GA4
- Debugging tracking issues
- Understanding traffic patterns across properties
Advanced Configuration Options
Option 1: Site-Specific Event Configuration
Different conversion values by site:
Variable name: GA4 - Default Currency - Site
Variable type: Lookup Table
Input Variable: {{Regex Table - Site Mapping}}
Configuration:
Input: main_site
Output: USD
Input: ecommerce
Output: USD
Input: client_a
Output: EUR
Input: client_b
Output: GBP
Option 2: Site-Specific Enhanced Measurement
Control enhanced measurement per site:
Variable name: GA4 - Enhanced Measurement - Site
Variable type: Lookup Table
Input Variable: {{Regex Table - Site Mapping}}
Configuration:
Input: main_site
Output: true
Input: ecommerce
Output: true
Input: blog
Output: false
Input: client_a
Output: true
Add to GA4 Configuration:
- Parameter:
allow_enhanced_conversions
- Value:
{{GA4 - Enhanced Measurement - Site}}
Option 3: Site-Specific Custom Parameters
Add site-specific context:
Variable name: GA4 - Site Type - Classification
Variable type: Lookup Table
Input Variable: {{Regex Table - Site Mapping}}
Configuration:
Input: main_site
Output: corporate
Input: ecommerce
Output: ecommerce
Input: blog
Output: content
Input: client_a
Output: client_site
Testing Your Dynamic Setup
Test 1: Main Company Site
In GTM Preview Mode:
- Connect to your main site (
yourcompany.com
) - Click Initialization event
- Verify in GA4 Configuration tag:
- Measurement ID shows
G-MAIN123456
- Site identifier shows
main_site
- Currency shows
USD
(if configured)
- Measurement ID shows
Test 2: E-commerce Site
In GTM Preview Mode:
- Connect to your e-commerce site (
shop.yourcompany.com
) - Click Initialization event
- Verify in GA4 Configuration tag:
- Measurement ID shows
G-SHOP789012
- Site identifier shows
ecommerce
- Enhanced measurement enabled
- Measurement ID shows
Test 3: Client Site
In GTM Preview Mode:
- Connect to a client site (
clienta.com
) - Click Initialization event
- Verify in GA4 Configuration tag:
- Measurement ID shows
G-CLIENTA901234
- Site identifier shows
client_a
- Correct currency and site type
- Measurement ID shows
Test 4: Real-Time Verification
Check that data reaches the correct GA4 properties:
- Go to each GA4 property’s Real-time report
- Navigate to the corresponding site
- Verify traffic appears in the correct property only
- Check that custom dimensions populate correctly
Enterprise-Level Enhancements
Multi-Brand Company Setup
For companies with multiple brands:
Variable name: Brand - Domain Mapping
Variable type: Regex Table
Input Variable: {{Page Hostname}}
Pattern examples:
Pattern: brandone.com
Output: brand_one
Pattern: brandtwo.com
Output: brand_two
Pattern: shop.brandone.com
Output: brand_one_shop
Then create measurement ID lookup:
Input: brand_one
Output: G-BRAND1MAIN
Input: brand_one_shop
Output: G-BRAND1SHOP
Input: brand_two
Output: G-BRAND2MAIN
Franchise or Multi-Location Setup
For franchise businesses or multi-location companies:
Pattern: denver.yourfranchise.com
Output: location_denver
Pattern: chicago.yourfranchise.com
Output: location_chicago
Pattern: newyork.yourfranchise.com
Output: location_newyork
Each location gets its own GA4 property while maintaining consistent GTM implementation.
Dynamic Marketing Pixel Configuration
Use the same site mapping for marketing pixels:
Variable name: Facebook Pixel ID - Site
Variable type: Lookup Table
Input Variable: {{Regex Table - Site Mapping}}
Input: main_site
Output: 1234567890
Input: ecommerce
Output: 0987654321
Input: client_a
Output: 1122334455
This ensures each site uses the correct Facebook Pixel, LinkedIn tag, etc.
Troubleshooting Common Issues
Wrong measurement ID being used:
- Check that domain patterns are specific enough and don’t overlap
- Verify the lookup table has all sites covered
- Test the site mapping variable in GTM preview mode
Data not appearing in expected GA4 property:
- Confirm the measurement IDs are correct in the lookup table
- Check that the GA4 Configuration tag is firing on Initialization
- Verify network requests in browser dev tools show the correct measurement ID
Cross-site data contamination:
- Ensure domain patterns are specific and don’t match multiple sites
- Check for hardcoded measurement IDs in other tags
- Verify that each site’s data appears only in its designated GA4 property
New sites not tracking correctly:
- Add the new domain pattern to the site mapping variable
- Create corresponding measurement ID in the lookup table
- Test the new pattern matches correctly in preview mode
Performance Considerations
GTM container size:
- This setup adds minimal overhead to your GTM container
- Variables are evaluated once per page load
- Lookup tables are more efficient than complex JavaScript
Cross-domain tracking:
- If sites need to share user sessions, configure cross-domain tracking
- Add linker parameters to the GA4 Configuration tag
- Ensure consistent measurement IDs for related sites
Maintenance and scalability:
- Adding new sites requires only variable updates
- No need to duplicate tags, triggers, or complex configurations
- Version control friendly (all logic in GTM workspace)
When to Use This Advanced Setup
Perfect for:
- Agencies managing multiple client websites
- Companies with separate brands or product lines
- Multi-domain e-commerce operations
- Franchise businesses with location-specific sites
- Organizations with distinct content and commerce properties
Probably overkill for:
- Single-site businesses
- Sites that can share the same GA4 property
- Teams without dedicated analytics expertise
- Simple blog or brochure websites
Professional Implementation Services
This advanced setup demonstrates enterprise-level GTM capabilities, but complex implementations often benefit from professional guidance:
Common scenarios requiring expert help:
- Multi-brand GTM governance and strategy
- Complex e-commerce tracking across multiple sites
- Cross-domain tracking and attribution setup
- Advanced conversion tracking and audience building
- Team training on GTM best practices and maintenance
What’s included in professional multi-site GTM consulting:
- Complete multi-site tracking architecture design
- Site-specific analytics strategy and implementation
- Cross-site reporting and attribution setup
- Documentation and team training
- Ongoing optimization and governance
Managing multiple websites with complex GTM tracking needs? Contact Knihter for expert multi-site GTM consulting and implementation services. We specialize in scalable tracking architectures for agencies and multi-brand organizations.
Related Posts in This Series:
- How to Filter Development Traffic in GA4 Using GTM
- How to Stop Marketing Pixels from Firing on Development Sites
Related Services: