This repository is a straight forward dependency-free implementation of a cookie consent banner which sends its data onward to Google Tag Manager using Google's new Consent Mode V2. This implementation also respects DoNotTrack and GlobalPrivacyControl signals when set.
- Add the
cookieconsent.js
to your site's HEAD tag. Be sure it is placed before your Google Tag Manager script and it is not deferred. This file must run before GTM is loaded. - Add the
cookieconsent.css
file to your site where appropriate. Feel free to edit the styles to match your site look and feel. - Add an element somewhere on your side with the class name
cookie-consent-banner-open
. This element will re-open the consent banner and allow users to change their choices. Alternatively, you can call the global functionwindow.cookieconsent.show()
to launch the banner. - In GTM, enable Consent Mode.
- Check the Consent Mode settings against your tags to be sure they are appropriately aligned.
Tip: View the index.html for a working example.