UTMSimple Consent Mode Guide (GDPR)

UTMSimple now supports conditional consent mode that integrates seamlessly with Google Tag Manager (GTM) and other consent management systems.

How It Works

When UTMSIMPLE_CONSENT_MODE = true is set globally, UTMSimple will not automatically initialize. Instead, you can manually call HandL.init() when consent is granted.

Basic Implementation

Set the global flag before loading UTMSimple:

<script>
    window.UTMSIMPLE_CONSENT_MODE = true;
</script>
<script src="path/to/utmsimple.js"></script>

2. Initialize When Consent is Granted

// When user grants consent
window.UTMSIMPLE_CONSENT_MODE = false;
HandL.init();

GTM Integration

Method 1: Using GTM Variables and Triggers

  1. Create a GTM Variable for consent status:

    • Variable Type: Custom JavaScript
    • Code: return window.UTMSIMPLE_CONSENT_MODE || false;
  2. Create a Trigger for consent granted:

    • Trigger Type: Custom Event
    • Event Name: consent_granted
    • Or use GTM's built-in consent mode triggers
  3. Create a Custom HTML Tag to initialize UTMSimple:

    <script>
    if (typeof HandL !== 'undefined') {
        window.UTMSIMPLE_CONSENT_MODE = false;
        HandL.init();
    }
    </script>
    

Method 2: Using GTM Consent Mode

Advanced Usage

UTMSimple provides a method to delete all cookies it has created:

// Delete all UTMSimple cookies and localStorage data
const result = HandL.deleteAllCookies();

// Result object contains:
// - deletedCount: number of cookies deleted
// - cookiesDeleted: array of cookie names that were deleted

This method:

Event Listeners

UTMSimple fires custom events that you can listen to:

// Listen for successful initialization
document.addEventListener('UTMSimpleLoaded', function() {
    console.log('UTMSimple loaded successfully');
});

// Listen for cookie setting
document.addEventListener('UTMSimpleCookiesSet', function() {
    console.log('UTMSimple cookies have been set');
});

// Listen for cookie deletion
document.addEventListener('UTMSimpleCookiesDeleted', function(event) {
    console.log(`UTMSimple cookies deleted: ${event.detail.deletedCount} cookies removed`);
});

Example Implementation

Best Practices

Troubleshooting

Script Not Initializing

GTM Integration Issues

Console Errors


Revision #2
Created 17 September 2025 19:07:38 by UTMSimple
Updated 17 September 2025 19:08:06 by UTMSimple