From b77bcd706abd3c3529f5a4989b0581193946770e Mon Sep 17 00:00:00 2001 From: Jan Henk Hazelaar Date: Fri, 9 Aug 2024 18:07:16 +0200 Subject: [PATCH 1/2] Added consent_grants options to gtm script type --- resources/views/scripts.antlers.html | 22 +++++++--------------- src/Scripts/Blueprint.php | 26 +++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/resources/views/scripts.antlers.html b/resources/views/scripts.antlers.html index 9ddfc14..36d9c67 100644 --- a/resources/views/scripts.antlers.html +++ b/resources/views/scripts.antlers.html @@ -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 }}'); - + {{ /if }} {{ /if }} {{ if script_type === 'meta-pixel' }} diff --git a/src/Scripts/Blueprint.php b/src/Scripts/Blueprint.php index c84d36f..88444ec 100644 --- a/src/Scripts/Blueprint.php +++ b/src/Scripts/Blueprint.php @@ -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' => [ @@ -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, ], ], @@ -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, ], ], From bb6dca9d2e28bb6476c9fc522f4340dcc156e5be Mon Sep 17 00:00:00 2001 From: Jan Henk Hazelaar Date: Fri, 9 Aug 2024 18:12:13 +0200 Subject: [PATCH 2/2] Anlters code alignment --- resources/views/scripts.antlers.html | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/resources/views/scripts.antlers.html b/resources/views/scripts.antlers.html index 36d9c67..69b81c5 100644 --- a/resources/views/scripts.antlers.html +++ b/resources/views/scripts.antlers.html @@ -22,22 +22,22 @@ {{ if consent_grants }} + gtag('consent', 'update', gtag('consent', 'update', {{$ json_encode(array_fill_keys($consent_grants, 'denied')) $}})) + } + }) + {{ /if }} {{ /if }}