Skip to content
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
12 changes: 12 additions & 0 deletions lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,18 @@ def _make_mako_template_dirs(settings):
GOOGLE_ANALYTICS_TRACKING_ID = None
GOOGLE_ANALYTICS_4_ID = None

################### GOOGLE TAG MANAGER ##################
# .. setting_name: GOOGLE_TAG_MANAGER_ID
# .. setting_default: None
# .. setting_description: The container ID for Google Tag Manager.
# Set this in the site configuration, if you want to enable Google Tag Manager (GTM) on your site.
# GTM allows you to manage marketing and analytics tags (like Google Analytics).
# When set, the GTM script will be injected into pages.
# Example: "GOOGLE_TAG_MANAGER_ID": "GTM-XXXXXXX" or with environment-specific parameters:
# "GOOGLE_TAG_MANAGER_ID": "GTM-XXXXXXX&gtm_auth=abc&gtm_preview=env-1&gtm_cookies_win=x"
# If you don’t use GTM, you can leave this setting as None.
GOOGLE_TAG_MANAGER_ID = None

######################## BRANCH.IO ###########################
BRANCH_IO_KEY = ''

Expand Down
9 changes: 9 additions & 0 deletions lms/templates/certificates/accomplishment-base.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@
gtag('config', '${ga_4_id | n, js_escaped_string}');
</script>
% endif

<% gtm_id = static.get_value("GOOGLE_TAG_MANAGER_ID", settings.GOOGLE_TAG_MANAGER_ID) %>
% if gtm_id:
<script>(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);
})(window,document,'script','dataLayer', '${gtm_id}');</script>
% endif
</head>

<body class="layout-accomplishment view-valid-accomplishment ${dir_rtl} certificate certificate-${course_mode_class}" data-view="valid-accomplishment">
Expand Down
9 changes: 9 additions & 0 deletions lms/templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@
</script>
% endif

<% gtm_id = static.get_value("GOOGLE_TAG_MANAGER_ID", settings.GOOGLE_TAG_MANAGER_ID) %>
% if gtm_id:
<script>(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);
})(window,document,'script','dataLayer', '${gtm_id}');</script>
% endif

<% branch_key = static.get_value("BRANCH_IO_KEY", settings.BRANCH_IO_KEY) %>
% if branch_key and not is_from_mobile_app:
<script type="text/javascript">
Expand Down
8 changes: 8 additions & 0 deletions lms/templates/main_django.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
</script>
{% endif %}

{% if google_tag_manager_id %}
<script>(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);
})(window,document,'script','dataLayer', '{{ google_tag_manager_id }}');</script>
{% endif %}

<meta name="path_prefix" content="{{EDX_ROOT_URL}}">
</head>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,12 @@ def google_analytics_4_id():
{% google_analytics_4_id %}
"""
return configuration_helpers.get_value("GOOGLE_ANALYTICS_4_ID", settings.GOOGLE_ANALYTICS_4_ID)


@register.simple_tag
def google_tag_manager_id():
"""
Django template tag that outputs the GOOGLE_TAG_MANAGER_ID:
{% google_tag_manager_id %}
"""
return configuration_helpers.get_value("GOOGLE_TAG_MANAGER_ID", settings.GOOGLE_TAG_MANAGER_ID)
Loading