Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added consent_grants options to gtm script type #85

Draft
wants to merge 2 commits into
base: 9.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 16 additions & 24 deletions resources/views/scripts.antlers.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,25 @@
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','{{ gtm_container_id }}');</script>

<script>
window.CookieNotice.on('accepted', (consentGroup) => {
if (consentGroup === '{{ group }}') {
console.log('provided consent')
{{ if consent_grants }}
<script>
window.CookieNotice.on('accepted', (consentGroup) => {
if (consentGroup === '{{ group }}') {
console.log('provided {{ consent_grants | ampersand_list }} consent')

gtag('consent', 'update', {
ad_user_data: 'granted',
ad_personalization: 'granted',
ad_storage: 'granted',
analytics_storage: 'granted'
})
}
})
gtag('consent', 'update', {{$ json_encode(array_fill_keys($consent_grants, 'granted')) $}})
}
})

window.CookieNotice.on('declined', (consentGroup) => {
if (consentGroup === '{{ group }}') {
console.log('revoked consent')
window.CookieNotice.on('declined', (consentGroup) => {
if (consentGroup === '{{ group }}') {
console.log('revoked {{ consent_grants | ampersand_list }} consent')

gtag('consent', 'update', {
ad_user_data: 'denied',
ad_personalization: 'denied',
ad_storage: 'denied',
analytics_storage: 'denied'
})
}
})
</script>
gtag('consent', 'update', gtag('consent', 'update', {{$ json_encode(array_fill_keys($consent_grants, 'denied')) $}}))
}
})
</script>
{{ /if }}
{{ /if }}

{{ if script_type === 'meta-pixel' }}
Expand Down
26 changes: 23 additions & 3 deletions src/Scripts/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,31 @@ public static function blueprint(): StatamicBlueprint
'instructions' => __('You can find this at the top right of your Google Tag Manager account. Usually starts with `GTM-`.'),
'if' => ['script_type' => 'equals google-tag-manager'],
'validate' => [
'required_if:script_type,google-tag-manager',
'required_if:{this}.script_type,google-tag-manager',
new ValidGtmContainerID,
],
],
],
[
'handle' => 'consent_grants',
'field' => [
'type' => 'checkboxes',
'display' => __('Default grants consent'),
'instructions' => __('What consent needs to default be granted when accepting this group.'),
'options' => [
'ad_storage' => 'ad_storage',
'ad_user_data' => 'ad_user_data',
'ad_personalization' => 'ad_personalization',
'analytics_storage' => 'analytics_storage'
],
'inline' => true,
'default' => ['ad_storage', 'ad_user_data', 'ad_personalization', 'analytics_storage'],
'if' => ['script_type' => 'equals google-tag-manager'],
'validate' => [
'array',
],
],
],
[
'handle' => 'meta_pixel_id',
'field' => [
Expand All @@ -74,7 +94,7 @@ public static function blueprint(): StatamicBlueprint
'instructions' => __('You can find this in your Meta Events Manager account.'),
'if' => ['script_type' => 'equals meta-pixel'],
'validate' => [
'required_if:script_type,meta-pixel',
'required_if:{this}.script_type,meta-pixel',
new ValidMetaPixelID,
],
],
Expand All @@ -89,7 +109,7 @@ public static function blueprint(): StatamicBlueprint
'mode_selectable' => false,
'if' => ['script_type' => 'equals other'],
'validate' => [
'required_if:script_type,other',
'required_if:{this}.script_type,other',
new ValidInlineJavaScript,
],
],
Expand Down
Loading