From 51566e2ea1106050cd6f9e66e70000b4b7475e70 Mon Sep 17 00:00:00 2001 From: mariacha Date: Wed, 23 Oct 2024 07:47:34 -0700 Subject: [PATCH 1/3] Issue #323 making googletagmanager configurable. --- modules/wri_common/js/wri_gtm.js | 2 +- modules/wri_common/wri_common.module | 1 + themes/custom/ts_wrin/templates/layout/html.html.twig | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/wri_common/js/wri_gtm.js b/modules/wri_common/js/wri_gtm.js index 60a5efffa..fd6a8e02c 100644 --- a/modules/wri_common/js/wri_gtm.js +++ b/modules/wri_common/js/wri_gtm.js @@ -1,5 +1,5 @@ (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); + drupalSettings.wri_common.analytics_url+'/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer', drupalSettings.wri_common.gtm_id); diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index cb8016d2b..59012f050 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -528,6 +528,7 @@ function wri_common_url_from_node_project($node) { */ function wri_common_page_attachments_alter(array &$attachments) { $attachments['#attached']['drupalSettings']['wri_common']['gtm_id'] = content_snippets_retrieve('gtm_id'); + $attachments['#attached']['drupalSettings']['wri_common']['analytics_url'] = content_snippets_retrieve('analytics_url'); } /** diff --git a/themes/custom/ts_wrin/templates/layout/html.html.twig b/themes/custom/ts_wrin/templates/layout/html.html.twig index a2fa4efab..139b69ad8 100644 --- a/themes/custom/ts_wrin/templates/layout/html.html.twig +++ b/themes/custom/ts_wrin/templates/layout/html.html.twig @@ -64,7 +64,7 @@ {# TODO: replace GTM-XXXX with your container ID.#} From 946af7a80afc9714f768e8486b04e1399fb86d8f Mon Sep 17 00:00:00 2001 From: mariacha Date: Wed, 23 Oct 2024 07:56:47 -0700 Subject: [PATCH 2/3] Issue #323 adding install script to update content snippets. --- .../config/install/content_snippets.items.yml | 10 +++++++++- modules/wri_common/wri_common.install | 8 ++++++++ .../config/install/content_snippets.content.yml | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/modules/wri_admin/config/install/content_snippets.items.yml b/modules/wri_admin/config/install/content_snippets.items.yml index d4a59c75f..93a23888e 100644 --- a/modules/wri_admin/config/install/content_snippets.items.yml +++ b/modules/wri_admin/config/install/content_snippets.items.yml @@ -27,7 +27,7 @@ narrative_taxonomy_view_arguments: id: 3_1_view_arguments type: textarea filter: full_html - description: 'The arguments passed to the 3+1 block''s listing view.' + description: "The arguments passed to the 3+1 block's listing view." group: 'View Arguments' weight: '10' osano_id: @@ -54,3 +54,11 @@ orto_registration_url: description: '1 hour after the scheduled end time of an event with a zoom webinar ID, send the event to this url. Example: https://ortto.wri.org/zoom/import-participants/?webinarId=[WEBINARID]&webinarName=[WEBINAR_NAME]&webinarDate=[WEBINAR_DATE]. This field accepts tokens.' group: '3rd Party' weight: '10' +analytics_url: + label: 'Analytics URL' + id: analytics_url + type: textfield + filter: full_html + description: 'example: https://www.googletagmanager.com (with no final slash)' + group: '3rd Party' + weight: '-10' diff --git a/modules/wri_common/wri_common.install b/modules/wri_common/wri_common.install index 4a8fcf33b..5bdcbc57b 100644 --- a/modules/wri_common/wri_common.install +++ b/modules/wri_common/wri_common.install @@ -158,3 +158,11 @@ function wri_common_update_10104() { } } } + +function wri_common_update_10301() { + // Import the content_snippets: + \Drupal::service('distro_helper.updates')->updateConfig('content_snippets.content', ['snippets#analytics_url'], 'wri_listing_block'); + \Drupal::service('distro_helper.updates')->updateConfig('content_snippets.items', [ + 'analytics_url', + ], 'wri_admin'); +} diff --git a/modules/wri_listing_block/config/install/content_snippets.content.yml b/modules/wri_listing_block/config/install/content_snippets.content.yml index cfb4f340c..54361b49c 100644 --- a/modules/wri_listing_block/config/install/content_snippets.content.yml +++ b/modules/wri_listing_block/config/install/content_snippets.content.yml @@ -6,3 +6,4 @@ snippets: osano_id: '' osano_params: '' orto_registration_url: 'https://ortto.wri.org/zoom/import-participants/?webinarId=[node:field_zoom_webinar_id]&webinarName=[node:title]&webinarDate=[node:field_date_time:format:default]' + analytics_url: 'https://www.googletagmanager.com' From 6cf479598a738f461693d195311334b116e10cfe Mon Sep 17 00:00:00 2001 From: mariacha Date: Wed, 23 Oct 2024 08:00:15 -0700 Subject: [PATCH 3/3] Issue #323 Update hook comment. --- modules/wri_common/wri_common.install | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/wri_common/wri_common.install b/modules/wri_common/wri_common.install index 5bdcbc57b..9c57d665f 100644 --- a/modules/wri_common/wri_common.install +++ b/modules/wri_common/wri_common.install @@ -159,6 +159,9 @@ function wri_common_update_10104() { } } +/** + * Adding the Analytics URL configuration default value. + */ function wri_common_update_10301() { // Import the content_snippets: \Drupal::service('distro_helper.updates')->updateConfig('content_snippets.content', ['snippets#analytics_url'], 'wri_listing_block');