# Ketch Integration

**Step 1: Set Up Ketch Purposes**

In your Ketch dashboard, edit the **Targeted Advertising** purpose. Under Legal Basis Assignment, set it to **Consent - Opt In** for each jurisdiction you want to identify.

<figure><img src="/files/Vm0dNvva9NiKnefZAm8u" alt=""><figcaption></figcaption></figure>

**Step 2: Set Up Ketch Experiences**

In your Ketch dashboard, edit your consent Experience. Set the primary button action to **Accept All (Full Consent)**.

<figure><img src="/files/LNOKI16GiLa8TYts4pq2" alt=""><figcaption></figcaption></figure>

**Step 3: Install the Ketch Smart Tag**

Paste your Ketch Smart Tag just below the `<head>` of your site (make sure to replace `YOUR-KETCH-ORG-CODE` and `YOUR-KETCH-PROPERTY` with your Ketch organization code and property name).

{% code overflow="wrap" %}

```
<script>!function(){window.semaphore=window.semaphore||[],window.ketch=function(){window.semaphore.push(arguments)};var e=document.createElement("script");e.type="text/javascript",e.src="https://global.ketchcdn.com/web/v3/config/YOUR-KETCH-ORG-CODE/YOUR-KETCH-PROPERTY/boot.js",e.defer=e.async=!0,document.getElementsByTagName("head")[0].appendChild(e)}();</script>
```

{% endcode %}

Script can be found at Ketch dashboard

<figure><img src="/files/zAeDgaOblYFvU3Cl4n8z" alt=""><figcaption></figcaption></figure>

**Step 4: Install the IntentWave Tracking Script**

Paste the following script below your Ketch Smart Tag (make sure to replace `YOUR-INTENTWAVE-SITE-ID` with your IntentWave site ID). This script only loads IntentWave after consent is granted through Ketch.

{% code overflow="wrap" %}

```
<script>
    function buildIntentWaveCategories(purposes) {
        var categories = [];
        if (purposes.essential_services) categories.push("necessary");
        if (purposes.analytics) categories.push("analytics", "performance");
        if (purposes.targeted_advertising) categories.push("emailmarketing", "ads", "social");
        return categories;
    }

    function generateConsentId() {
        return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
            var r = Math.random() * 16 | 0;
            var v = c === "x" ? r : (r & 0x3 | 0x8);
            return v.toString(16);
        });
    }

    var intentWaveLoaded = false;

    function loadIntentWaveScript(callback) {
        if (intentWaveLoaded) {
            if (callback) callback();
            return;
        }
        intentWaveLoaded = true;
        var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
        g.type = 'text/javascript'; g.async = true; g.defer = true;
        g.src = 'https://cdn.intentwave.com/track.js';
        g.setAttribute('data-name', 'IntentWave');
        g.setAttribute('data-id', 'YOUR-INTENTWAVE-SITE-ID');
        g.onload = callback;
        s.parentNode.insertBefore(g, s);
    }

    function buildConsentCookie(purposes) {
        return {
            categories: buildIntentWaveCategories(purposes),
            consentTimestamp: new Date().toISOString(),
            consentId: generateConsentId(),
            provider: "ketch",
            consentURL: window.location.href
        };
    }

    function waitForIntentWaveReady(purposes) {
        var attempts = 0;
        var maxAttempts = 50;
        var interval = setInterval(function () {
            attempts++;
            if (typeof IntentWave !== "undefined" && typeof IntentWave.customConsent === "function") {
                clearInterval(interval);
                IntentWave.customConsent(buildConsentCookie(purposes));
            } else if (attempts >= maxAttempts) {
                clearInterval(interval);
            }
        }, 200);
    }

    function loadIdentifyScript(consentCookie) {
        var hasEmailMarketing = consentCookie.categories.indexOf("emailmarketing") !== -1;
        if (!hasEmailMarketing || !IntentWave.consent.granted || typeof IntentWave.getConfiguration !== "function") return;
        IntentWave.getConfiguration().then(function (config) {
            if (config && config.identify && config.identify.enabled) {
                var filtersEnabled = config.identify.filters && config.identify.filters.enabled;
                if (filtersEnabled) {
                    IntentWave.filterMonitor.start(
                        config.identify.filters,
                        function (context) {
                            IntentWave.loadScript("identify", config);
                        }
                    );
                } else {
                    IntentWave.loadScript("identify", config);
                }
            }
        });
    }

    function passConsentToIntentWave(consent) {
        var purposes = consent.purposes || consent;
        if (!purposes) return;
        if (!intentWaveLoaded) {
            loadIntentWaveScript(function () {
                waitForIntentWaveReady(purposes);
            });
        } else if (typeof IntentWave !== "undefined" && typeof IntentWave.customConsent === "function") {
            var consentCookie = buildConsentCookie(purposes);
            IntentWave.customConsent(consentCookie);
            loadIdentifyScript(consentCookie);
        }
    }

    ketch('on', 'consent', passConsentToIntentWave);
</script>
```

{% endcode %}

Once all three are added in the `<head>` of your website you can verify that consent is passing correctly by accepting all categories on the Ketch consent banner. Open your browser's DevTools Console to confirm there are no errors and check your IntentWave dashboard for a new consent record.

For additional support please contact us at [**support@intentwave.com**](mailto:support@intentwave.com)**.**


---

# Agent Instructions: 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:

```
GET https://documentation.intentwave.com/consent-banner-integrations/ketch-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
