Skip to content

Commit

Permalink
Merge pull request #326 from wri/issue-323-gtm
Browse files Browse the repository at this point in the history
Issue 323 gtm
  • Loading branch information
mariacha authored Oct 23, 2024
2 parents daf2ca2 + 6cf4795 commit 8582694
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
10 changes: 9 additions & 1 deletion modules/wri_admin/config/install/content_snippets.items.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'
2 changes: 1 addition & 1 deletion modules/wri_common/js/wri_gtm.js
Original file line number Diff line number Diff line change
@@ -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);
11 changes: 11 additions & 0 deletions modules/wri_common/wri_common.install
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,14 @@ 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');
\Drupal::service('distro_helper.updates')->updateConfig('content_snippets.items', [
'analytics_url',
], 'wri_admin');
}
1 change: 1 addition & 0 deletions modules/wri_common/wri_common.module
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
2 changes: 1 addition & 1 deletion themes/custom/ts_wrin/templates/layout/html.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<!-- Google Tag Manager (noscript) -->
{# TODO: replace GTM-XXXX with your container ID.#}
<noscript>
<iframe src="https://www.googletagmanager.com/ns.html?id={{ contentSnippets.gtm_id }}" height="0" width="0" style="display:none;visibility:hidden"></iframe>
<iframe src="{{ contentSnippets.analytics_url }}/ns.html?id={{ contentSnippets.gtm_id }}" height="0" width="0" style="display:none;visibility:hidden"></iframe>
</noscript>
<!-- End Google Tag Manager (noscript) -->
<!-- Grid Layout Checker -->
Expand Down

0 comments on commit 8582694

Please sign in to comment.