If you need to add a cookie consent notice to your website (for GDPR compliance, for example), you can use Google Tag Manager to manage all cookies and build a customized banner with Cookie Consent to allow your site visitors to consent to collect marketing data.
Together, this creates a holistic cookie management solution. Once complete, your visitors will see the Cookie Consent dialog and can choose whether or not the Act-On cookie is placed on their device with tracking enabled.
Notes about this guide:
- This guide uses Google Tag Manager and Cookie Consent (both free services), but may work with minor changes for other tag managers and cookie consent systems
- These steps also work to present cookie consent only, without the ability to opt-in/opt-out of tracking
- This approach can accommodate all tags on your website (Google Analytics, Optimizely, etc.), showing one consent message that covers cookies from all vendors you leverage
Process diagram
Instructions
Set up Google Tag Manager (GTM)
- Go to the Google Tag Manager site
- Sign up and log in
- Create a website container in GTM and add the container snippet to your website according to the on-screen instructions
Grab the Cookie Consent banner code
- Visit Osano's Cookie Consent configuration wizard
- Click Start Coding at the bottom right
- Under Configure, click the Compliance Type drop-down
Do not make any other changes to configuration settings in Osano, including Position, Layout, or Palette configurations. Act-On only supports configuring your Cookie Consent banner code as instructed here. - Select Ask users to opt into cookies (Advanced)
- Copy the 2 pieces of code that appear on the right-hand side
Paste and edit your Cookie Consent banner code in GTM
- Head back to Google Tag Manager
- Click Tags > New > Custom HTML Tag
- Paste both portions of your Cookie Consent code (in the order provided by Osano's website)
- Delete the last few lines of code – remove everything between the last }, through the closing </script> tag:
- Copy the below code and paste it at the end of your Custom Cookie code snippet
- This code monitors the state of your visitors' opt-in/out selection and reports it to GTM
- Note: This is a slightly altered version of code in Cookie Consent's documentation to push events to the browser’s data layer for listening
}, onInitialise: function (status) { var type = this.options.type; var didConsent = this.hasConsented(); if (type == 'opt-in' && didConsent) { // enable cookies dataLayer.push({'event':'this.hasConsented'}); } if (type == 'opt-out' && !didConsent) { // disable cookies } }, onStatusChange: function(status, chosenBefore) { var type = this.options.type; var didConsent = this.hasConsented(); if (type == 'opt-in' && didConsent) { // enable cookies dataLayer.push({'event':'this.hasConsented'}); } if (type == 'opt-out' && !didConsent) { // disable cookies } }, onRevokeChoice: function() { var type = this.options.type; if (type == 'opt-in') { // disable cookies } if (type == 'opt-out') { // enable cookies } }, "type": "opt-in" });
</script> - Before saving, set the Trigger to All Pages to ensure your cookie consent banner is always run on all pages
Create a new GTM variable
Next, create a new variable in GTM to report visitors' cookie consent status:
- Click Variables on the left of GTM, then click New in User-Defined Variables
- Select the type 1st Party Cookie, enter a Cookie Name of cookieconsent_status, and select URI-decode cookie
- Name the variable cookieconsent_status cookie and click Save
Create an opt-in trigger in GTM
Create a trigger that lets GTM listen for a visitor's first opt-in or for a change in their opt-in choice.
- Click Triggers on the left of GTM and create a new trigger
- Select the type Custom Event, event name this.hasConsented, and set the trigger to fire on Some Custom Events where Event: equals: this.hasConsented
- Name your trigger this.hasConsented and click Save
Create a trigger to run the Act-On tag
Create a final trigger to run the Act-On tag and other cookie-dropping scripts on your website (or to keep them from running):
- Click Triggers on the left of GTM and create a new trigger
- Select the type Custom Event, event name this.hasConsented, and set the trigger to fire on Some Custom Events where cookieconsent_status cookie: equals: allow
- Name your trigger Cookie Consent cookie value and click Save
Create a tag for the Act-On Beacon
Grab the Act-On Beacon code to create another GTM tag:
-
- In Act-On, go to Settings > Other Settings > Beacon Settings
- Ensure that Standard Mode is set – GTM will control whether the beacon code runs
- Copy the Beacon code
- Head to Google Tag Manager
- Click Tag > New > Custom HTML Tag and paste your Act-On Beacon code
- Set the trigger for Cookie Consent cookie value
- Name the Tag Act-On Beacon and click Save – you now have the Act-On tag set to run only when the opt-in status trigger fires
Heads up!
If you have additional website code that needs to obey users' cookie preference (e.g., an on-page chat tool), add that code in new GTM tags using the same Cookie Consent Cookie Value trigger – they will fire only after your site visitor has accepted the use of cookies.
This allows you to manage your scripts and tags on your entire website without working through a web developer and updating your website directly. It also ensures that you get a single cookie notification/consent dialog that covers all of your cookies, which is the best experience for your visitors.
Preview and submit your changes in GTM
- Preview your changes in GTM
- When you open your site in preview mode, the GTM configuration will be applied to you only; you'll also see a helpful debug window below your site
- This is great for troubleshooting and checking your work after making changes
- Submit your changes in GTM – they will go live immediately
Next Steps
Almost there! The last step is to add the GTM code to all your Landing Pages so that these tags will actually fire. Once you've done that, default tracking and placement of Act-On cookies will be off for these pages, and GTM will manage the use of cookies and tags.