# Enforce Consent From 3rd Party (e.g. GTM)

## Overview

The "Enforce Consent From 3rd Party" feature allows HandL UTM Grabber to respect consent decisions made through third-party consent management platforms, such as Google Tag Manager (GTM). When enabled, this feature ensures that HandL UTM Grabber only collects and stores data after receiving proper consent from the user, as determined by the third-party consent management system.

## Enabling the Feature

To enable this feature:

- Navigate to your WordPress admin panel.
- Go to the HandL UTM Grabber settings page.
- Find the "Require Third-Party Consent" option.
- Check the box next to "Require consent from third-party services (e.g., Google Tag Manager) before tracking".
- Save your changes.

The relevant setting can be found here:

[![](https://docs.utmgrabber.com/uploads/images/gallery/2024-10/scaled-1680-/image-1728225846990.png)](https://docs.utmgrabber.com/uploads/images/gallery/2024-10/image-1728225846990.png)

## How It Works

Once enabled, HandL UTM Grabber will:

- Monitor the dataLayer for consent update events.
- Check the consent status before running its tracking functions.
- Remove HandL cookies if consent is denied.

The main logic for this feature is implemented in the following JavaScript functions:

```javascript
isConsentDenied();
removeHandLCookies();
```

You may use these functions as you see fit in your project. The `isConsentDenied()` function returns a Boolean value indicating whether consent is denied. The `removeHandLCookies()` function removes all HandL-related cookies (e.g., when consent is denied).

### Consent Status Check

The plugin checks for consent using the `getConsentStatus()` and `isConsentDenied()` functions. These functions look for consent information in the `dataLayer` object, which is commonly used by consent management platforms.

### Handling Consent Changes

When a consent update is detected, the `handleConsentStatus()` function is called. This function either runs HandL UTM Grabber's tracking (if consent is granted) or removes HandL cookies (if consent is denied).

## Integration with Google Tag Manager (GTM)

To use this feature with Google Tag Manager:

- Set up your consent management platform in GTM. You can use any 3rd party tool (CookieHub, Cookiebot etc)
- Ensure that your consent management platform is updating the dataLayer with consent information. (According to GTM's best practises) 
- HandL UTM Grabber will automatically detect these updates and act accordingly.

## Compatibility

This feature is designed to work with various consent management platforms that use the dataLayer to communicate consent status. It has been tested with Google Tag Manager but should be compatible with other similar systems.

## Troubleshooting

If you're experiencing issues with this feature:

- Ensure that your consent management platform is correctly updating the dataLayer.
- Check your browser's console for any error messages related to HandL UTM Grabber.
- Verify that the "Require Third-Party Consent" option is enabled in the HandL UTM Grabber settings.

## Important Notes

- This feature relies on the presence and proper configuration of a third-party consent management system.
- If no consent information is found in the dataLayer, HandL UTM Grabber will default to its standard behavior.
- Enabling this feature may impact data collection if users do not provide consent.

By implementing this feature, you're taking an important step towards respecting user privacy and complying with data protection regulations.