Skip to content

Commit

Permalink
COC | updated Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Monti authored and l-besenyei committed May 16, 2024
1 parent 9e88352 commit 7ec03f3
Showing 1 changed file with 51 additions and 23 deletions.
74 changes: 51 additions & 23 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ See the demo: [Cookieconsent](https://brainsum.github.io/cookieconsent/)

## Default look

![Cookieconsent modal](cc_modal_75.png "Cookieconsent modal")
![Cookieconsent modal](cc_modal_75.png 'Cookieconsent modal')

## Features

Expand Down Expand Up @@ -199,32 +199,60 @@ The script is being controlled mainly by a configuration object which is passed

```javascript
<!-- Google Tag Manager -->
<script>
window.dataLayer = window.dataLayer || []
function gtag(){dataLayer.push(arguments);}

if(localStorage.getItem('consentMode') === null) {
gtag('consent', 'default', {
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'analytics_storage': 'denied'
});
} else {
gtag('consent', 'default', JSON.parse(localStorage.getItem('consentMode')));
}

(function(w,d,s,l,i){
w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer', ---GTM ID---);</script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
const defaultSettings = {
ad_storage: 'granted',
ad_user_data: 'granted',
ad_personalization: 'granted',
analytics_storage: 'granted',
};
const defaultRegionalSettings = {
ad_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied',
analytics_storage: 'denied',
region: [
'AT',
'BE',
'IS',
'LI',
'NO',
],
};
if (localStorage.getItem('consentMode') === null) {
gtag('consent', 'default', defaultSettings);
gtag('consent', 'default', defaultRegionalSettings);
} else {
gtag('consent', 'default', {
...defaultRegionalSettings,
...JSON.parse(localStorage.getItem('consentMode')),
});
gtag('consent', 'default', {
...defaultSettings,
...JSON.parse(localStorage.getItem('consentMode')),
});
}
(function (w, d, s, l, i) {
w[l].push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' });
var f = d.getElementsByTagName(s)[0],
j = d.createElement(s),
dl = l != 'dataLayer' ? '&l=' + l : '';
j.async = true;
j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', '---GTM-ID---');
</script>

<!-- End Google Tag Manager -->
```

Whenever a consent option is modified by the user, an update is sent to Google Tag Manager setting the new consent configuration.
This example implements [regional consent mode](https://developers.google.com/tag-platform/security/guides/consent?consentmode=advanced#region-specific-behavior). Adjust this snippet as needed.

## Sponsors

Contributed to diginomica by Brainsum, sponsored by ![diginomica](diginomica-24.png "diginomica").
Contributed to diginomica by Brainsum, sponsored by ![diginomica](diginomica-24.png 'diginomica').

0 comments on commit 7ec03f3

Please sign in to comment.