/
google_tag_manager.twig
90 lines (82 loc) · 3.78 KB
/
google_tag_manager.twig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{% if google_tag_value %}
<script>
var google_tag_value = '{{ google_tag_value }}';
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); };
var cookie_content = document.cookie.split(';').map(s => s.trim());
function cookie_contains(value) {
return cookie_content.indexOf(value) !== -1;
};
var no_track = cookie_contains('no_track=1');
var active_consent = cookie_contains('active_consent_choice=1');
var marketing_consent = !no_track && active_consent
&& (cookie_contains('greenpeace=2') || cookie_contains('greenpeace=4'));
var analytical_consent = !no_track && active_consent
&& (cookie_contains('greenpeace=3') || cookie_contains('greenpeace=4'));
var cookie_consent = marketing_consent || analytical_consent;
{#
If Google Consent Mode is enabled,
set default ad storage and analytics storage to 'denied' as first action on every page until consent is given.
If consent given, update consent on every page.
#}
{% if cookies.enable_google_consent_mode %}
if ( cookie_consent ) {
var capabilities = {
ad_storage: marketing_consent ? 'granted' : 'denied',
{% if cookies.enable_analytical_cookies %}
...{'analytics_storage': analytical_consent ? 'granted' : 'denied'}
{% endif %}
};
gtag('consent', 'update', capabilities);
dataLayer.push({event: 'updateConsent', ...capabilities});
} else {
var capabilities = {
ad_storage: 'denied',
{% if cookies.enable_analytical_cookies %}
...{'analytics_storage': 'denied'}
{% endif %}
};
gtag('consent', 'default', capabilities);
dataLayer.push({event: 'defaultConsent', ...capabilities});
}
{% endif %}
dataLayer.push({
'pageType' : '{{ page_category }}',
'signedIn' : '{{ p4_signedin_status }}',
'visitorType' : '{{ p4_visitor_type }}',
'userID' : '',
'post_tags': '{{ post_tags }}',
'gPlatform': 'Planet 4'
});
{% if not post.password_required %}
var cf_campaign_name = '{% if cf_campaign_name is defined and cf_campaign_name is not null %}{{ cf_campaign_name|raw }}{% endif %}';
var cf_project_id = '{% if cf_project_id is defined and cf_project_id is not null %}{{ cf_project_id|raw }}{% endif %}';
var cf_local_project = '{% if cf_local_project is defined and cf_local_project is not null %}{{ cf_local_project|raw }}{% endif %}';
var cf_basket_name = '{% if cf_basket_name is defined and cf_basket_name is not null %}{{ cf_basket_name|raw }}{% endif %}';
var cf_scope = '{% if cf_scope is defined and cf_scope is not null %}{{ cf_scope|raw }}{% endif %}';
var cf_department = '{% if cf_department is defined and cf_department is not null %}{{ cf_department|raw }}{% endif %}';
if ( cf_campaign_name || cf_basket_name || cf_scope || cf_department ) {
dataLayer.push({
'gCampaign' : cf_campaign_name,
'gLocalProject' : cf_local_project,
'projectID' : cf_project_id,
'gBasket' : cf_basket_name,
'gScope': cf_scope,
'gDepartment': cf_department,
});
}
{% endif %}
var gtm_allow = '{{ enforce_cookies_policy }}' ? cookie_consent : true;
if ( google_tag_value && gtm_allow ) {
(function (w, d, s, l, i) {
w[l] = w[l] || [];
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', google_tag_value);
}
</script>
{% endif %}