-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7167 from uktrade/fix/google-tag-manager
Reorganize Google Tag Manager snipped and initialization
- Loading branch information
Showing
10 changed files
with
63 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
src/templates/_includes/google-tag-manager/consent-needed.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{# | ||
This is a set-up of Google Tag Manager for external users | ||
(currently anyone who accessess /exportwins/review/*), | ||
for whom we need to manage consent to use Google Analytics cookies. | ||
#} | ||
{% if GOOGLE_TAG_MANAGER_KEY %} | ||
{% include "_includes/google-tag-manager/gtag-definition.njk" %} | ||
<script nonce='{{ cspNonce }}'> | ||
window.gtag('consent', 'default', { | ||
ad_storage: 'denied', | ||
analytics_storage: localStorage.getItem('cookie-consent') || 'denied', | ||
ad_user_data: 'denied', | ||
ad_personalization: 'denied', | ||
wait_for_update: 500 | ||
}); | ||
</script> | ||
{% include "_includes/google-tag-manager/snippet.njk" %} | ||
{% endif %} |
22 changes: 22 additions & 0 deletions
22
src/templates/_includes/google-tag-manager/consent-not-needed.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{# | ||
This is a set-up of Google Tag Manager for internal users, | ||
who are assumed that they have given consent for using | ||
Google Analytics cookies. | ||
#} | ||
{% if GOOGLE_TAG_MANAGER_KEY %} | ||
{% include "_includes/google-tag-manager/gtag-definition.njk" %} | ||
<script nonce='{{ cspNonce }}'> | ||
window.gtag({ | ||
userId: '{{user.id}}', | ||
userUserId: '{{user.sso_user_id}}', | ||
}) | ||
if ('{{userFeatureGTMEvent}}') { | ||
window.gtag({ | ||
name: '{{userFeatureGTMEvent.name}}', | ||
event: '{{userFeatureGTMEvent.event}}', | ||
}) | ||
} | ||
</script> | ||
{% include "_includes/google-tag-manager/snippet.njk" %} | ||
{% endif %} |
4 changes: 4 additions & 0 deletions
4
src/templates/_includes/google-tag-manager/gtag-definition.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<script nonce='{{ cspNonce }}'> | ||
window.dataLayer = window.dataLayer || [] | ||
window.gtag = function() { dataLayer.push(arguments); } | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% if GOOGLE_TAG_MANAGER_KEY %} | ||
<!-- Google Tag Manager (noscript) --> | ||
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id={{ GOOGLE_TAG_MANAGER_KEY }}" | ||
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> | ||
<!-- End Google Tag Manager (noscript) --> | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- Google Tag Manager --> | ||
<meta property="WTF" content="window,document,'script','dataLayer','{{ GOOGLE_TAG_MANAGER_KEY }}')"/> | ||
<script nonce='{{ cspNonce }}'>(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_MANAGER_KEY }}');</script> | ||
<!-- End Google Tag Manager --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters