# Implementing Custom Consent Management with HandL UTM Grabber Plugin

## UTM attribution overview

This guide explains Implementing Custom Consent Management with HandL UTM Grabber Plugin. It helps you respect consent choices while preserving UTM parameters for compliant WordPress attribution and keep the marketing context needed for accurate reporting across forms, bookings, signups, and sales.

To integrate your custom consent management system with the HandL UTM Grabber plugin, follow these steps:  

1. Check for Consent Status: Determine if the user has given consent.
1. Run HandL UTM Grabber: If consent is given, call the RunHandL() function.
1. Remove Cookies: If consent is not given, call the removeAllHandLCookies() function.

Here is an example implementation using JavaScript:


```
window.addEventListener('ConsentUpdated', function() {
    if (typeof ConsentTool !== 'undefined') {
        const consentString = Cookies.get('CookiesForConsentData');

        // Assuming consent data is available in cookies or as an event
        const consentData = parseConsentString(consentString);

        if (consentData.good2go === 1) {
            RunHandL();
        } else {
            removeAllHandLCookies();
        }
    }
});

function parseConsentString(consentString) {
    // Parse the consent string to extract consent data
    // This is a placeholder function, implement the actual parsing logic as needed
    return {
        good2go: consentString.includes('good2go=1') ? 1 : 0
    };
}
```

### Explanation
1. Event Listener: The window.addEventListener listens for a custom event CustomConsentUpdated which is triggered by your consent management system.
1. Check Consent Management System: Ensure that the custom consent management system is available.
1. Get Consent Status: Retrieve the consent status from event or cookies.
1. Run or Remove Cookies: Depending on the consent status, either run the RunHandL() function or call removeAllHandLCookies() to remove all cookies