diff --git a/lms/templates/main_django.html b/lms/templates/main_django.html
index cc6ebaf24a..4d93c4f09a 100644
--- a/lms/templates/main_django.html
+++ b/lms/templates/main_django.html
@@ -28,6 +28,18 @@
{% optional_include "head-extra.html"|microsite_template_path %}
+ {% google_analytics_4_id as ga_4_id %}
+ {% if ga_4_id %}
+
+
+ {% endif %}
+
diff --git a/openedx/core/djangoapps/site_configuration/templatetags/configuration.py b/openedx/core/djangoapps/site_configuration/templatetags/configuration.py
index b5242a53b5..9de10d3bb0 100644
--- a/openedx/core/djangoapps/site_configuration/templatetags/configuration.py
+++ b/openedx/core/djangoapps/site_configuration/templatetags/configuration.py
@@ -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)