Shahi LegalFlowSuite

Integrate Google Tag Manager

Set Up GTM with Consent-Aware Tag Firing

GTM Setup Prerequisites

Step 1: Create GTM Account

`
Visit: https://tagmanager.google.com/
Click: “Create Account”
Account Name: “Your Website Name”
Container Name: “Web Container”
Target Platform: “Web”
`

Step 2: Install GTM Container

`
SLOS → Integrations → Google Tag Manager → Container Setup
`

Add GTM Code to Theme:
`html



`

Add GTM Noscript (Body):
`html



`

Configure Consent Variables

Step 1: Create Consent Variables

`
GTM Dashboard → Variables → New → User-Defined Variables
`

SLOS Consent Variable (Custom JavaScript):
`javascript
function() {
if (window.SLOS && window.SLOS.getConsentState) {
return window.SLOS.getConsentState();
}
return {};
}
`

Category-Specific Variables:

Analytics Consent:
`javascript
function() {
if (window.SLOS && window.SLOS.hasConsent) {
return window.SLOS.hasConsent(‘analytics’);
}
return false;
}
`

Marketing Consent:
`javascript
function() {
if (window.SLOS && window.SLOS.hasConsent) {
return window.SLOS.hasConsent(‘marketing’);
}
return false;
}
`

Preferences Consent:
`javascript
function() {
if (window.SLOS && window.SLOS.hasConsent) {
return window.SLOS.hasConsent(‘preferences’);
}
return false;
}
`

Step 2: Create Consent Triggers

Consent Granted Trigger:
`
GTM Dashboard → Triggers → New → Custom Event
Event Name: slosconsentgranted
This trigger fires on: Some Custom Events
`

Consent Updated Trigger:
`
GTM Dashboard → Triggers → New → Custom Event
Event Name: slosconsentupdated
This trigger fires on: Some Custom Events
`

Category-Specific Triggers:

Analytics Consent Granted:
`javascript
function() {
return {{SLOS Analytics Consent}} === true;
}
`

Marketing Consent Granted:
`javascript
function() {
return {{SLOS Marketing Consent}} === true;
}
`

Set Up Consent-Aware Tags

Step 1: Google Analytics 4 Setup

`
GTM Dashboard → Tags → New → Google Analytics: GA4 Configuration
`

Configuration:
`
Tag Name: GA4 Configuration
Measurement ID: G-XXXXXXXXXX
Trigger: Consent Granted (Analytics)
`

Advanced Settings:
`javascript
// Only fire when analytics consent is granted
{
“consentSettings”: {
“analytics_storage”: “{{SLOS Analytics Consent}}”,
“ad_storage”: “{{SLOS Marketing Consent}}”
}
}
`

Step 2: Google Ads Conversion Tracking

`
GTM Dashboard → Tags → New → Google Ads Conversion Tracking
`

Configuration:
`
Tag Name: Google Ads Conversion
Conversion ID: XXXXXXXXX
Conversion Label: XXXXXXXX
Trigger: Marketing Consent Granted
`

Step 3: Facebook Pixel Setup

`
GTM Dashboard → Tags → New → Facebook Pixel
`

Configuration:
`
Tag Name: Facebook Pixel
Pixel ID: XXXXXXXXXXXXXXXX
Trigger: Marketing Consent Granted
`

Custom Events:
`javascript
// Fire only with marketing consent
if ({{SLOS Marketing Consent}}) {
fbq(‘track’, ‘PageView’);
fbq(‘track’, ‘Lead’);
}
`

Configure Advanced Event Tracking

Step 1: Consent Event Tracking

`
GTM Dashboard → Tags → New → Google Analytics: GA4 Event
`

Consent Granted Event:
`javascript
{
“eventname”: “consentgranted”,
“parameters”: {
“consent_categories”: “{{SLOS Consent State}}”,
“consent_source”: “banner”,
“consent_timestamp”: “{{Event Time}}”
}
}
`

Consent Updated Event:
`javascript
{
“eventname”: “consentupdated”,
“parameters”: {
“updated_categories”: “{{SLOS Consent State}}”,
“update_source”: “portal”,
“update_timestamp”: “{{Event Time}}”
}
}
`

Step 2: Custom Consent Events

Category-Specific Events:
`javascript
// Analytics consent event
{
“eventname”: “analyticsconsent”,
“parameters”: {
“consent_granted”: “{{SLOS Analytics Consent}}”,
“consent_timestamp”: “{{Event Time}}”
}
}

// Marketing consent event
{
“eventname”: “marketingconsent”,
“parameters”: {
“consent_granted”: “{{SLOS Marketing Consent}}”,
“consent_timestamp”: “{{Event Time}}”
}
}
`

Implement Consent Blocking

Step 1: Tag Sequencing

`
GTM Dashboard → Tags → [Your Tag] → Advanced Settings → Tag Sequencing
`

Setup Tag:
`
Fire a tag before [Your Tag] fires: Consent Check Tag
`

Consent Check Tag:
`javascript
function() {
var consent = {{SLOS Consent State}};
if (consent.analytics && consent.marketing) {
return true;
}
return false;
}
`

Step 2: Blocking Triggers

Block Marketing Tags:
`javascript
// Block trigger for marketing tags
function() {
return !{{SLOS Marketing Consent}};
}
`

Block Analytics Tags:
`javascript
// Block trigger for analytics tags
function() {
return !{{SLOS Analytics Consent}};
}
`

Set Up Data Layer Integration

Step 1: Push Consent Events to Data Layer

`javascript
// SLOS consent event listener
document.addEventListener(‘slosconsentgranted’, function(event) {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
‘event’: ‘slosconsentgranted’,
‘consent_categories’: event.detail.categories,
‘consent_timestamp’: event.detail.timestamp
});
});

document.addEventListener(‘slosconsentupdated’, function(event) {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
‘event’: ‘slosconsentupdated’,
‘updated_categories’: event.detail.categories,
‘update_timestamp’: event.detail.timestamp
});
});
`

Step 2: Data Layer Variables

Consent Categories Variable:
`javascript
function() {
return {{Data Layer Variable – consent_categories}} || [];
}
`

Consent Timestamp Variable:
`javascript
function() {
return {{Data Layer Variable – consent_timestamp}} || null;
}
`

Configure Cross-Domain Consent

Step 1: Cross-Domain Tracking

`
GTM Dashboard → Variables → New → Google Analytics Settings
`

Cross-Domain Configuration:
`javascript
{
“allowLinker”: true,
“linkerDomains”: [“example.com”, “blog.example.com”, “shop.example.com”],
“consentSettings”: {
“analytics_storage”: “{{SLOS Analytics Consent}}”,
“ad_storage”: “{{SLOS Marketing Consent}}”
}
}
`

Step 2: Consent Synchronization

`javascript
// Sync consent across domains
function syncConsentAcrossDomains() {
var consent = {{SLOS Consent State}};
var domains = [‘example.com’, ‘blog.example.com’, ‘shop.example.com’];

domains.forEach(function(domain) {
document.cookie = ‘slos_consent=’ + JSON.stringify(consent) +
‘; domain=’ + domain + ‘; path=/; max-age=31536000’;
});
}
`

Set Up Enhanced Ecommerce

Step 1: Ecommerce Consent Configuration

`
GTM Dashboard → Tags → New → Google Analytics: GA4 Event
`

Purchase Event (Consent-Aware):
`javascript
{
“event_name”: “purchase”,
“parameters”: {
“currency”: “USD”,
“value”: “{{Purchase Value}}”,
“items”: {{Purchase Items}}
},
“consent_required”: [“analytics”, “marketing”]
}
`

Step 2: Ecommerce Triggers

`javascript
// Only fire ecommerce events with proper consent
function() {
var consent = {{SLOS Consent State}};
var requiredConsent = {{Tag Consent Requirements}};

return requiredConsent.every(function(category) {
return consent[category] === true;
});
}
`

Implement Server-Side Tagging

Step 1: Set Up Server Container

`
GTM Dashboard → Admin → Container → New → Server
`

Step 2: Configure Server-Side Tags

Server-Side GA4:
`javascript
// Server-side tag configuration
{
“consentSettings”: {
“analytics_storage”: “{{Client Consent – Analytics}}”,
“ad_storage”: “{{Client Consent – Marketing}}”
}
}
`

Step 3: Client-Side Integration

`javascript
// Send consent data to server
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
‘event’: ‘client_consent’,
‘consent’: {{SLOS Consent State}}
});
`

Test GTM Integration

Step 1: GTM Debug Mode

`
GTM Dashboard → Preview
Enter your website URL
Click: “Connect”
`

Debug Checklist:

    1. [ ] GTM container loads correctly
    2. [ ] Consent variables populate
    3. [ ] Tags fire based on consent
    4. [ ] Events track properly
    5. [ ] Cross-domain works
    6. [ ] Server-side tags function
    7. Step 2: Consent Testing

      Test Analytics Consent:

    8. Accept only analytics cookies
    9. Check GA4 events fire
    10. Verify marketing tags blocked
    11. Test Marketing Consent:

    12. Accept only marketing cookies
    13. Check ad pixels fire
    14. Verify analytics tags blocked
    15. Test Full Consent:

    16. Accept all categories
    17. Verify all tags fire
    18. Check event parameters
    19. Step 3: Real-Time Monitoring

      `
      Google Analytics → Real-Time → Events
      Google Tag Manager → Debug Console
      `

      Monitor GTM Performance

      Step 1: Tag Performance

      `
      GTM Dashboard → Admin → Container → Settings → Performance
      `

      Performance Metrics:

    20. Tag load times
    21. Consent check delays
    22. Event processing times
    23. Error rates
    24. Step 2: Consent Analytics

      Consent Event Tracking:
      `javascript
      // Track consent decisions
      gtag(‘event’, ‘consent_decision’, {
      ‘consent_type’: ‘analytics’,
      ‘consent_granted’: true,
      ‘page_location’: window.location.href
      });
      `

      Tag Firing Analysis:

    25. Tags fired per session
    26. Consent blocking effectiveness
    27. Performance impact
    28. Error tracking
    29. Advanced GTM Features

      Step 1: Custom Templates

      `
      GTM Dashboard → Templates → New
      `

      Consent-Aware Template:
      `javascript
      // Custom tag template with consent checking
      const hasConsent = data.consent_category ?
      require(‘getCookieValues’)(‘slos‘ + data.consentcategory)[0] === ‘true’ :
      true;

      if (hasConsent) {
      // Fire tag logic here
      }
      `

      Step 2: Built-in Consent Integration

      `javascript
      // Use GTM’s built-in consent
      gtag(‘consent’, ‘default’, {
      ‘analytics_storage’: {{SLOS Analytics Consent}} ? ‘granted’ : ‘denied’,
      ‘ad_storage’: {{SLOS Marketing Consent}} ? ‘granted’ : ‘denied’,
      ‘functionality_storage’: {{SLOS Preferences Consent}} ? ‘granted’ : ‘denied’,
      ‘personalization_storage’: {{SLOS Preferences Consent}} ? ‘granted’ : ‘denied’,
      ‘security_storage’: ‘granted’
      });
      `

      Troubleshooting GTM Issues

      Common Problems

      Tags Not Firing:

    30. Check consent variables
    31. Verify trigger conditions
    32. Test in debug mode
    33. Check for JavaScript errors
    34. Consent Not Syncing:

    35. Verify data layer pushes
    36. Check variable configurations
    37. Test cross-domain settings
    38. Review cookie policies
    39. Performance Issues:

    40. Optimize tag loading
    41. Reduce unnecessary triggers
    42. Cache consent decisions
    43. Minimize custom scripts
    44. Debugging Steps:
      `javascript
      // Debug GTM data layer
      console.log(‘Data Layer:’, window.dataLayer);

      // Debug consent state
      console.log(‘SLOS Consent:’, window.SLOS.getConsentState());

      // Debug GTM variables
      console.log(‘GTM Variables:’, googletagmanager[{{Container ID}}].dataLayer.get());
      `

      Maintenance and Updates

      Step 1: Regular GTM Audits

    45. Review tag configurations quarterly
    46. Update consent mappings
    47. Audit tag performance
    48. Clean up unused tags
    49. Step 2: Version Control

    50. Use GTM workspaces for changes
    51. Test in staging environment
    52. Document tag changes
    53. Backup container versions
    54. Support Resources

    55. Google Tag Manager Help Center
    56. Google Analytics for Developers
    57. Consent management guides
    58. Performance optimization tips

Share this article

Was this article helpful?

Help us improve our documentation

Still need help?

Our support team is ready to assist you with personalized guidance for your workspace.

Submit a support ticket