Categories
JavaScript Answers

How to suppress use of cookies for users who have not yet given consent with Google Analytics and JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *