How to block Klaviyo from collecting information?
How the script works?
We are setting the Klaviyo cookie __kla_off to true, which should stop Klaviyo from tracking onsite activity data, if the customer has opted out of the Marketing cookie group through our app.
For additional reference on how the script works, feel free to check the documentation for Klaviyo here - About Cookies in Klaviyo
Applying the script
In order to block the tracking from Klaviyo so that no information is being collected if a customer has opted out of the Marketing cookie group, you would need to add an additional script in your main theme file. Here are the steps that you would need to follow:
- Open Shopify Admin.
- Click on Online Store link in the left menu bar.
- Click on the Action drop down button and select Edit Code from there.
- A new page will open with a list of files on the left side of the screen. Open the theme.liquid file.
- Find the closing < /head > tag there.
- When you do, you can copy and add the following snippet before the closing < /head > 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 on the Save button.
Adding the Klaviyo cookie
Once you’ve successfully added the script, 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: 19/07/2026
Thank you!
