From 830a624d988671f0469e54748d1900d2bdbb59c4 Mon Sep 17 00:00:00 2001 From: Bryan Wilson Date: Wed, 12 Jul 2023 16:41:23 -0700 Subject: [PATCH 1/2] reorganize all GA and GTM code into body-extra Move out of head to avoid breaKing YouTube video/API loading --- lms/templates/body-extra.html | 14 ++-------- lms/templates/head-extra.html | 31 ---------------------- lms/templates/partials/analytics.html | 38 ++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 44 deletions(-) diff --git a/lms/templates/body-extra.html b/lms/templates/body-extra.html index 341a00be..99f2b308 100644 --- a/lms/templates/body-extra.html +++ b/lms/templates/body-extra.html @@ -2,6 +2,8 @@ <%! import hmac %> <%! import hashlib %> +<%include file="partials/analytics.html" /> + ## Renders when Cookie Banner is disabled or when it is enabled and user has dismissed (accepted) it: % if (not get_global_settings().get('cookie_notification_enabled', False)) or (get_global_settings().get('cookie_notification_enabled', False) and (request.COOKIES.get('cookieconsent_status', '') == 'dismiss')): @@ -51,16 +53,4 @@ % endif - <%! from openedx.core.djangolib.js_utils import js_escaped_string %> - <% - customer_gtm_id = get_global_settings().get('customer_gtm_id') - %> - - % if customer_gtm_id: - - - - % endif - % endif diff --git a/lms/templates/head-extra.html b/lms/templates/head-extra.html index 58eed301..2268a7da 100644 --- a/lms/templates/head-extra.html +++ b/lms/templates/head-extra.html @@ -48,7 +48,6 @@ % endif -<%include file="partials/analytics.html" /> % if get_global_settings().get('default_additional_site_head_content', ''): ${get_global_settings().get('default_additional_site_head_content')} @@ -57,36 +56,6 @@ ## Renders when Cookie Banner is disabled or when it is enabled and user has dismissed (accepted) it: % if (not get_global_settings().get('cookie_notification_enabled', False)) or (get_global_settings().get('cookie_notification_enabled', False) and (request.COOKIES.get('cookieconsent_status', '') == 'dismiss')): - <% - appsembler_ga_code = get_global_settings().get('appsembler_ga_code', ''); - client_ga_code = get_global_settings().get('client_ga_code', ''); - client_ga_enabled = get_global_settings().get('client_ga_enabled', True); - client_ga_version = get_global_settings().get('client_ga_version', 'v3'); - %> - % if SHOW_GOOGLE_ANALYTICS: - % if client_ga_code and client_ga_enabled: - ## for now Appsembler is still using v3 Universal Analytics and some customers do too. - ## once Appsembler and all customers shift to v4 we remove this condition - % if client_ga_version == 'v4': - - - - % else: - - % endif - % endif - - % endif - % if get_global_settings().get('cookie_accepted_additional_site_head_content', ''): % if request.COOKIES.get('cookieconsent_status', '') == 'dismiss': ${get_global_settings().get('cookie_accepted_additional_site_head_content')} diff --git a/lms/templates/partials/analytics.html b/lms/templates/partials/analytics.html index 1390251d..810378fa 100644 --- a/lms/templates/partials/analytics.html +++ b/lms/templates/partials/analytics.html @@ -97,6 +97,35 @@ Dimension3: Visited course name Dimension4: LMS or Studio --> + <% + appsembler_ga_code = get_global_settings().get('appsembler_ga_code', ''); + client_ga_code = get_global_settings().get('client_ga_code', ''); + client_ga_enabled = get_global_settings().get('client_ga_enabled', True); + client_ga_version = get_global_settings().get('client_ga_version', 'v3'); + %> + + % if SHOW_GOOGLE_ANALYTICS: + % if client_ga_code and client_ga_enabled: + ## for now Appsembler is still using v3 Universal Analytics and some customers do too. + ## once Appsembler and all customers shift to v4 we remove this condition + % if client_ga_version == 'v4': + + + + % else: + + % endif + % endif + + % endif <% appsemblerLmsTrackingCode = get_global_settings().get('appsembler_lms_tracking_code') @@ -119,4 +148,11 @@ % endif -% endif \ No newline at end of file +% endif + +% if customer_gtm_id: + + + +% endif From 37bfea1852b062de4246f3203ea7fe17a1dc4d0a Mon Sep 17 00:00:00 2001 From: Bryan Wilson Date: Wed, 12 Jul 2023 16:41:38 -0700 Subject: [PATCH 2/2] switch timeout on loadGTM back to 1 sec --- lms/templates/partials/analytics.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lms/templates/partials/analytics.html b/lms/templates/partials/analytics.html index 810378fa..ab87db82 100644 --- a/lms/templates/partials/analytics.html +++ b/lms/templates/partials/analytics.html @@ -68,7 +68,7 @@ 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); - };setTimeout(loadGTM.bind(null, window,document,'script','dataLayer','${customer_gtm_id | n, js_escaped_string}'), 3000); + };setTimeout(loadGTM.bind(null, window,document,'script','dataLayer','${customer_gtm_id | n, js_escaped_string}'), 1000); % endif