> For the complete documentation index, see [llms.txt](https://docs.jentis.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.jentis.com/jentis-dcp-elements/codes/workaround-for-consent.md).

# Activate Code Elements with Consent

Code elements are currently not assigned to any vendor in the JENTIS consent engine, so no consent information is checked or applied to them within the JENTIS Tag Manager framework by default. If consent is an important factor in your custom code, we'd propose that you add a custom JS function that will evaluate a vendors consent state, await consent updates and then activate the actual code snippet.

Find below an example. Replace the following sections so your code activates with consent:

* `VENDOR_ID`: fill in the "" value with the ID of the respective vendor. You'll find the vendor ID in JENTIS account section: "Legal Hub": "Vendors", select a vendor and the ID will be presented in the top right corner (next to the name)
* `executeMyCode()` function - this will be executed based on the consent default and update events, if consent is granted for the respective vendor this function is called; which is the place where your actual code snippet goes.

{% hint style="info" %}
"adobeanalytics" is an example for a vendor ID; please replace this with the relevant vendor ID for your use case. If you are not sure which vendor ID it is, you can just run the `jentis.consent.engine.getVendorFullData()` function in your website (developer tools: console) to get all currently installed vendors in your container on the website.
{% endhint %}

{% code lineNumbers="true" %}

```javascript
const VENDOR_ID = "adobeanalytics"; 

function executeMyCode() {
    /*
     *Your custom code here.
    */
}

// DO NOT CHANGE:
var eventTarget;

if (
    typeof window.jentis !== "undefined" &&
    window.jentis.consent &&
    window.jentis.consent.engine
) {
    // SDK already loaded, so listen on the consent engine directly.
    eventTarget = window.jentis.consent.engine;
} else {
    // SDK not loaded yet, so listen on document for the init event.
    eventTarget = document;
}


function onVendorChange(event) {
    var consentStatus = event.detail && event.detail[VENDOR_ID];

    if (consentStatus === true) {
        executeMyCode();
    }
}

function onConsentInit() {
    var engine = window.jentis && window.jentis.consent && window.jentis.consent.engine;
    var vendorConsent;

    if (!engine) {
        return;
    }

    vendorConsent = engine.getVendorConsent(VENDOR_ID);

    if (vendorConsent === true) {
        executeMyCode();
    } else {
        engine.addEventListener("jentis.consent.engine.vendor-change", onVendorChange);
    }
}

eventTarget.addEventListener("jentis.consent.engine.init", onConsentInit);
```

{% endcode %}

Here is what the code element might look like in an active configuration in the JENTIS Tag Manager User Interface:

<figure><img src="/files/25cqBrvKKeBHnXp2lqTb" alt=""><figcaption></figcaption></figure>

More details on working with the consent engine can be found here: [Consent SDK Basics](/developer-guide/consent-javascript-sdk.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.jentis.com/jentis-dcp-elements/codes/workaround-for-consent.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
