feat: add google_analytics_4_id template tag for main_django.html
This commit is contained in:
@@ -28,6 +28,18 @@
|
||||
|
||||
{% optional_include "head-extra.html"|microsite_template_path %}
|
||||
|
||||
{% google_analytics_4_id as ga_4_id %}
|
||||
{% if ga_4_id %}
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id={{ ga_4_id }}"></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
|
||||
gtag('config', '{{ ga_4_id }}');
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
<meta name="path_prefix" content="{{EDX_ROOT_URL}}">
|
||||
</head>
|
||||
|
||||
|
||||
@@ -65,3 +65,12 @@ def microsite_template_path(template_name):
|
||||
"""
|
||||
template_name = theming_helpers.get_template_path(template_name)
|
||||
return template_name[1:] if template_name[0] == '/' else template_name
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def google_analytics_4_id():
|
||||
"""
|
||||
Django template tag that outputs the GOOGLE_ANALYTICS_4_ID:
|
||||
{% google_analytics_4_id %}
|
||||
"""
|
||||
return configuration_helpers.get_value("GOOGLE_ANALYTICS_4_ID", settings.GOOGLE_ANALYTICS_4_ID)
|
||||
|
||||
Reference in New Issue
Block a user