Sometimes, we want to suppress use of cookies for users who have not yet given consent with Google Analytics and JavaScript.
In this article, we’ll look at how to suppress use of cookies for users who have not yet given consent with Google Analytics and JavaScript.
How to suppress use of cookies for users who have not yet given consent with Google Analytics and JavaScript?
To suppress use of cookies for users who have not yet given consent with Google Analytics and JavaScript, we can switch on consent mode.
To do this, we write
gtag("consent", "default", {
analytics_storage: "denied",
ad_storage: "denied",
});
to call gtag
with 'consent'
and an object that denies cookies on users that haven’t consented to tracking with
{
analytics_storage: "denied",
ad_storage: "denied",
}
Conclusion
To suppress use of cookies for users who have not yet given consent with Google Analytics and JavaScript, we can switch on consent mode.