Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi, so I was wondering if there is a way to stop the propagation of the Shopify _tracking_consent cookie to the subdomains of a main domain. For example:
_tracking_consent should be on the domain.com site
but not on the subdomain.domain.com site.
So my question is: is it possible to change this cookie's domain scope? from .domain.com to domain.com
Thanks!
Hi,
It can be done by correctly setting up domain attribute
Example script that you can add to your theme’s theme.liquid or use through Google Tag Manager:
document.addEventListener('DOMContentLoaded', function() {
// Check if the existing cookie is set to the current domain
var trackingConsentCookie = document.cookie.match(/_tracking_consent=([^;]*)/);
if (trackingConsentCookie) {
// Delete the existing cookie with .domain.com
document.cookie = "_tracking_consent=; path=/; domain=.domain.com; expires=Thu, 01 Jan 1970 00:00:00 UTC;";
// Set the cookie specifically to domain.com
document.cookie = "_tracking_consent=" + trackingConsentCookie[1] + "; path=/; domain=domain.com; SameSite=Lax;";
}
});
Thanks! I will test and let you know if this works on my store!
Hi, it's me again here, Tested this approach, but it did not work. Tried many variants of this code, but in general, the following happens:
The cookie is deleted (this is OK)
when setting the new cookie up only for the main domain, it automatically gets set on the .domain.com ... Not sure if I did something wrong, please let me know 🙂
Is there also any other approach to this?
Thanks a lot!
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024