How to block Klaviyo from collecting information?
Klaviyo Integration with Consentmo
Consentmo can be integrated with Klaviyo to adjust its tracking behavior according to the visitor's Marketing consent.
There are two integration approaches available, depending on how strictly you want Klaviyo to be controlled:
- Standard integration - Klaviyo's script is allowed to load, but the Klaviyo opt-out cookie is adjusted according to the visitor's Marketing consent.
- Strict integration - Klaviyo's tracking scripts are blocked from loading until Marketing consent is granted.
The Standard integration is the lighter option. It does not completely prevent the Klaviyo service or its scripts from loading, so some requests or non-cookie data may still be processed by Klaviyo.
If you need Klaviyo to be fully prevented from loading before Marketing consent, use the Strict integration instead.
Standard Klaviyo Integration
How the script works?
This integration uses Klaviyo's __kla_off cookie to communicate the visitor's Marketing consent preference.
When Marketing consent is not granted, the script sets:
__kla_off=true
When Marketing consent is granted, the cookie is removed.
This allows Klaviyo's own consent mechanism to limit its onsite tracking behavior.
Important: This is a lighter integration. It does not block the Klaviyo script itself from loading.
As a result, Klaviyo may still load on the page and process certain requests or information that does not depend on its tracking cookies. The integration is intended to prevent Klaviyo's cookie-based onsite tracking rather than completely block the service.
For additional information about Klaviyo's cookies and the __kla_off mechanism, check:
Applying the Standard integration
To apply the lighter Klaviyo integration:
- Open Shopify Admin.
- Go to Online Store.
- Open your theme options and select Edit code.
- Open the theme.liquid file.
- Find the closing **** tag.
- Add the following script before the closing **** tag:
<!-- Klaviyo integration script from Consentmo GDPR app -->
<script id="consentmo-klaviyo-integration-script">
function checkConsentForKlaviyo(isMarketingEnabled) {
if (isMarketingEnabled) {
console.log('exec klaviyo');
document.cookie = "__kla_off=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
} else {
console.log('blocked klaviyo');
document.cookie = "__kla_off=true";
}
}
document.addEventListener('consentmoSignal_onLoad', function(eventData) {
const csmLoadSignal = eventData.detail || {isActive:false};
if (!csmLoadSignal.isActive) {
checkConsentForKlaviyo(true);
} else {
document.addEventListener('consentmoSignal', function(event) {
const csmPreferences = event.detail.preferences;
checkConsentForKlaviyo(csmPreferences.marketing);
});
}
});
</script>
- Click Save.
The script listens for Consentmo's consent signals and updates Klaviyo's opt-out cookie whenever the visitor's Marketing preference changes.
Strict Klaviyo Integration
How the Strict integration works?
The Strict integration goes a step further.
In addition to setting the Klaviyo __kla_off cookie to true, it prevents Klaviyo scripts from loading while Marketing consent is not granted.
The script:
- Sets
__kla_off=truewhen Marketing consent is unavailable - Removes existing Klaviyo scripts from the page
- Watches for Klaviyo scripts that may be added later
- Allows and reloads Klaviyo when Marketing consent is granted
- Responds to changes in the visitor's Consentmo preferences
This option should be used when you want Klaviyo's tracking scripts to remain blocked completely until the customer has granted Marketing consent.
Applying the Strict integration
To block Klaviyo from loading before Marketing consent:
- Open Shopify Admin.
- Click Online Store in the left menu.
- Open your theme options and select Edit code.
- Open the theme.liquid file.
- Find the closing **** tag.
- Add the following snippet before the closing **** tag:
<script id="consentmo-klaviyo-strict-integration">
(function () {
'use strict';
var blockedSrcs = [];
var observer = null;
var sdkCheckInterval = null;
var sdkCheckCount = 0;
var SDK_CHECK_INTERVAL_MS = 100;
var SDK_CHECK_MAX = 80; // give up after ~8 s (Consentmo failed to load)
function isKlaviyoSrc(src) {
if (!src) return false;
var s = src.toLowerCase();
return s.indexOf('klaviyo.com') !== -1 || s.indexOf('klaviyo.js') !== -1;
}
function blockScript(node, rawSrc) {
if (rawSrc && blockedSrcs.indexOf(rawSrc) === -1) blockedSrcs.push(rawSrc);
node.parentNode && node.parentNode.removeChild(node);
}
function shouldBlockMarketing() {
var match = document.cookie.match(/(?:^|;\s*)cookieconsent_preferences_disabled=([^;]*)/);
if (!match) return true; // No decision yet → block by default
var disabled = decodeURIComponent(match[1]);
return disabled.indexOf('marketing') !== -1;
}
function startBlocking() {
document.cookie = '__kla_off=true;path=/';
// Remove any Klaviyo scripts already in the DOM
var existing = document.querySelectorAll('script[src]');
for (var i = 0; i < existing.length; i++) {
var src = existing[i].getAttribute('src');
if (isKlaviyoSrc(src)) blockScript(existing[i], src);
}
// Watch for Klaviyo scripts added later (content_for_header, GTM, etc.)
if (observer) return;
observer = new MutationObserver(function (mutations) {
for (var m = 0; m < mutations.length; m++) {
var nodes = mutations[m].addedNodes;
for (var n = 0; n < nodes.length; n++) {
var node = nodes[n];
if (node.tagName === 'SCRIPT') {
var src = node.src || '';
if (isKlaviyoSrc(src)) blockScript(node, src);
} else if (node.querySelectorAll) {
var children = node.querySelectorAll('script[src]');
for (var c = 0; c < children.length; c++) {
var csrc = children[c].getAttribute('src');
if (isKlaviyoSrc(csrc)) blockScript(children[c], csrc);
}
}
}
}
});
observer.observe(document.documentElement, { childList: true, subtree: true });
}
function stopBlocking() {
document.cookie = '__kla_off=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/';
if (observer) {
observer.disconnect();
observer = null;
}
// Re-inject Klaviyo scripts that were blocked
var target = document.head || document.documentElement;
for (var i = 0; i < blockedSrcs.length; i++) {
var src = blockedSrcs[i];
if (!document.querySelector('script[src="' + src + '"]')) {
var script = document.createElement('script');
script.src = src;
script.async = true;
target.appendChild(script);
}
}
blockedSrcs = [];
}
function clearSdkCheck() {
if (sdkCheckInterval) {
clearInterval(sdkCheckInterval);
sdkCheckInterval = null;
}
}
function startSdkCheck() {
sdkCheckInterval = setInterval(function () {
sdkCheckCount++;
if (window.Consentmo && typeof window.Consentmo.marketingAllowed === 'function') {
clearSdkCheck();
if (window.Consentmo.marketingAllowed()) {
stopBlocking();
}
return;
}
if (sdkCheckCount >= SDK_CHECK_MAX) {
clearSdkCheck();
stopBlocking();
}
}, SDK_CHECK_INTERVAL_MS);
}
// Block immediately on page load if marketing is not consented
if (shouldBlockMarketing()) {
startBlocking();
startSdkCheck();
}
// Respond to Consentmo consent decisions (visitor accepts or denies)
document.addEventListener('consentmoSignal', function (eventData) {
var prefs = eventData.detail && eventData.detail.preferences;
if (!prefs) return;
clearSdkCheck(); // decision made — SDK poll no longer needed
if (prefs.marketing) {
stopBlocking();
} else {
if (!observer) startBlocking();
}
});
})();
</script>
- Click Save.
NOTE: Make sure to remove the added integration code before deleting the Consentmo app. This prevents unused snippets from remaining in your theme. For more information, check this article from our FAQ.
Which Integration Should I Use?
The main difference between the two options is whether the Klaviyo script itself is allowed to load.
Standard integration
The Standard integration:
- Allows Klaviyo's script to load
- Uses
__kla_offto control Klaviyo's cookie-based tracking - Is a lighter implementation
- May still allow Klaviyo to process some non-cookie data or requests
Strict integration
The Strict integration:
- Prevents Klaviyo scripts from loading before Marketing consent
- Sets
__kla_off=truewhile Marketing consent is unavailable - Allows Klaviyo only after Marketing consent is granted
- Provides stricter control when prior blocking of Klaviyo is required
You should use only one of the two integrations. Do not add both scripts to the same store.
Adding the Klaviyo cookie
Once you’ve successfully added the integration, you need to add the Klaviyo cookie __kla_id into our app by navigating to Cookie bar settings tab > Management section.
- You can add the cookie from the Cookies management table, as shown below:

The __kla_id cookie can be added with the following details:
- Cookie provider - Klaviyo
- Cookie description - This cookie is used to collect information about the visitor's behaviour. This information will be stored on the website for internal use.
- Category - Marketing
- Duration - 2 years
Need help?
If you have any questions, don't hesitate to contact our support team at support@consentmo.com or from the Chat button at the bottom right corner of your browser.
Updated on: 20/08/2026
Thank you!
