> For the complete documentation index, see [llms.txt](https://kluvos.gitbook.io/kluvos-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kluvos.gitbook.io/kluvos-docs/set-up/woocommerce-integration.md).

# Woocommerce integration

## Set-Up

#### Step-by-Step Guide:

* Create an account on Kluvos. [(create one here)](https://kluvos/users/sign_up)
* Click "Add Property" in the Properties section of the dashbaord
* After creating an account, confirm consent settings in "Set-Up"
* Install the official Kluvos plugin on your Woocommerce store
* Authenticate your WooCommerce store

## Visual Guide

## Privacy & Compliance

Kluvos’ WooCommerce tracking script is built to respect privacy-by-design guidelines. It only starts collecting data after you (the merchant) confirm that the visitor granted consent. This guide explains how the script works, what responsibilities sit with you, and how to wire it up with popular consent managers.

#### 1. How the Kluvos Loader Works

```html
https://track.kluvos.com/v2/scripts/woocommerce/<PROPERTY_TOKEN>.js
```

the loader:

1. Exposes window\.kluvos with helper methods (consent.grant, consent.revoke, consent.update, track, etc.).
2. Stays idle until you explicitly pass consent.
3. When you call window\.kluvos.consent.grant(...), it fetches the analytics bundle (/v2/scripts/woocommerce/\<property\_token>/bundle) and runs kpixel.core.kluvosInit()—the real tracking engine.
4. If consent is revoked, window\.kluvos.consent.revoke(...) clears caches/cookies and stops the session.

By default, the loader expects both “analytics” and “marketing” consent scopes. You can override that via window\.kluvos.configure({ requiredScopes: \[...] }), but the supplied examples assume both are needed.

#### 2. Merchant Responsibilities

You need to:

* Load the consent-aware script in your theme/layout.
* Call window\.kluvos.consent.grant only after the visitor opts in.
* Call window\.kluvos.consent.revoke (or consent.update) if they withdraw consent.
* Keep the consent.revoke hook wired to your banner so tracking stops immediately if the visitor changes their mind.
* State in your privacy policy that you trigger Kluvos only after consent (we pass the signal, but you control when).

Without consent, Kluvos does nothing—no cookies, no analytics, no data post.

#### Basic Setup Template

```html
<!-- 1. Include the consent-aware loader -->
<script src="https://track.kluvos.com/v2/scripts/woocommerce/<PROPERTY_TOKEN>.js" async></script>

<script>
  // 2. Grant consent once your CMP or banner confirms “all” tracking allowed
  function enableKluvos() {
    window.kluvos.consent.grant({
      consent_given: true,
      scopes: ['analytics', 'marketing'], // loader requires both by default
      source: 'Cookie banner'
    });
  }

  // 3. Optionally revoke if the visitor opts out later
  function disableKluvos() {
    window.kluvos.consent.revoke({ source: 'Cookie banner revoke' });
  }
</script>
```

If your property is configured for "auto" mode (the default), the loader auto-grants on page load and you don’t need a manual call. Switch the property to "manual" mode if you rely on a CMP.

#### 4. Connecting to Consent Managers

#### 4.1 Cookiebot

```html
<script>
  window.addEventListener('CookiebotOnAccept', function () {
    if (Cookiebot.consent.marketing && Cookiebot.consent.statistics) {
      window.kluvos.consent.grant({
        consent_given: true,
        scopes: ['analytics', 'marketing'],
        source: 'Cookiebot'
      });
    }
  });

  window.addEventListener('CookiebotOnDecline', function () {
    window.kluvos.consent.revoke({ source: 'Cookiebot' });
  });
</script>  
```

(Cookiebot splits “statistics” vs “marketing”, so wait until both are allowed.)

#### 4.2 Complianz

```html
<script>
  document.addEventListener('cmplzEnableCategory', function (event) {
    if (event.detail.category === 'all') {
      window.kluvos.consent.grant({
        consent_given: true,
        scopes: ['analytics', 'marketing'],
        source: 'Complianz'
      });
    }
  });

  document.addEventListener('cmplzDisableCategory', function () {
    window.kluvos.consent.revoke({ source: 'Complianz' });
  });
</script>
```

Complianz fires 'all' when every category (including marketing) has been accepted—perfect for our combined-scopes expectation.

#### 4.3 CookieYes

```html
<script>
  document.addEventListener('cookieyesConsentUpdate', function (event) {
    var detail = event.detail || {};
    if (detail.accepted.includes('marketing') && detail.accepted.includes('analytics')) {
      window.kluvos.consent.grant({
        consent_given: true,
        scopes: ['analytics', 'marketing'],
        source: 'CookieYes'
      });
    } else {
      window.kluvos.consent.revoke({ source: 'CookieYes' });
    }
  });
</script>
```

Adjust the property names if CookieYes uses different keys in your implementation.

#### 4.4 Custom Banner Example

```html
<script>
  const acceptBtn = document.querySelector('#acceptCookies');
  const denyBtn   = document.querySelector('#denyCookies');

  acceptBtn.addEventListener('click', function () {
    window.kluvos.consent.grant({
      consent_given: true,
      scopes: ['analytics', 'marketing'],
      source: 'custom-banner'
    });
  });

  denyBtn.addEventListener('click', function () {
    window.kluvos.consent.revoke({ source: 'custom-banner' });
  });
</script>
```

If your UI supports partial consent, map it to the scope array accordingly.

#### 4.5 Copy and Paste Template (manual mode)

```html
<!-- Kluvos WooCommerce Consent Loader -->
<script src="https://track.kluvos.com/v2/scripts/woocommerce/<PROPERTY_TOKEN>.js" async></script>

<script>
  window.kluvos = window.kluvos || {};

  // Optional: adjust required scopes before triggering consent
  // window.kluvos.configure({ requiredScopes: ['analytics', 'marketing'] });

  function enableKluvosTracking(source) {
    window.kluvos.consent.grant({
      consent_given: true,
      scopes: ['analytics', 'marketing'],
      source: source || 'CMP'
    });
  }

  function disableKluvosTracking(source) {
    window.kluvos.consent.revoke({ source: source || 'CMP' });
  }
</script>
```

Hook your CMP events into enableKluvosTracking / disableKluvosTracking.

## FAQ & Troubleshooting

#### Nothing happens after calling consent.grant

* Make sure you’re passing both scopes (\['analytics','marketing']) or that you’ve reconfigured requiredScopes.
* Check console logs: console.info messages prefixed \[KluvosConsent] tell you the loader status.

#### Consent flips to “no” but script keeps running

* Ensure you call window\.kluvos.consent.revoke when the visitor opts out. That pathway clears cookies and cached data.

#### CMP fires multiple times

* The loader is idempotent. It will only fetch the bundle and call kluvosInit once. Extra grant calls after initialization simply flush queued events.

#### Do I need to change the snippet if I go back to “auto” mode?

* In auto mode you can still wire up revoke/grant, but the loader will call consent.grant on window\.load automatically.
