From 89ffbb0e0c2051ac22d7c8ffdfb5754530d090f4 Mon Sep 17 00:00:00 2001 From: Sagirov Eugeniy Date: Mon, 27 Mar 2023 14:12:18 +0300 Subject: [PATCH] feat: Add GA 4 support to edX platform feat: add a snippet to public_video_share_embed.html feat: add google_analytics_4_id template tag for main_django.html fix: add js_escaped_string filter for ga_4_id --- lms/envs/common.py | 1 + lms/envs/production.py | 1 + .../certificates/accomplishment-base.html | 13 ++ lms/templates/main.html | 12 ++ lms/templates/main_django.html | 12 ++ lms/templates/public_video_share_embed.html | 129 ++++++++++++++++++ .../templatetags/configuration.py | 9 ++ 7 files changed, 177 insertions(+) create mode 100644 lms/templates/public_video_share_embed.html diff --git a/lms/envs/common.py b/lms/envs/common.py index 9845f2f1a23c..31092d9301d8 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -971,6 +971,7 @@ def _make_mako_template_dirs(settings): GOOGLE_SITE_VERIFICATION_ID = '' GOOGLE_ANALYTICS_LINKEDIN = 'GOOGLE_ANALYTICS_LINKEDIN_DUMMY' GOOGLE_ANALYTICS_TRACKING_ID = None +GOOGLE_ANALYTICS_4_ID = None ######################## BRANCH.IO ########################### BRANCH_IO_KEY = '' diff --git a/lms/envs/production.py b/lms/envs/production.py index a98a5764c55c..cef5d412b33a 100644 --- a/lms/envs/production.py +++ b/lms/envs/production.py @@ -668,6 +668,7 @@ def get_env_setting(setting): GOOGLE_ANALYTICS_TRACKING_ID = AUTH_TOKENS.get('GOOGLE_ANALYTICS_TRACKING_ID') GOOGLE_ANALYTICS_LINKEDIN = AUTH_TOKENS.get('GOOGLE_ANALYTICS_LINKEDIN') GOOGLE_SITE_VERIFICATION_ID = ENV_TOKENS.get('GOOGLE_SITE_VERIFICATION_ID') +GOOGLE_ANALYTICS_4_ID = AUTH_TOKENS.get('GOOGLE_ANALYTICS_4_ID') ##### BRANCH.IO KEY ##### BRANCH_IO_KEY = AUTH_TOKENS.get('BRANCH_IO_KEY') diff --git a/lms/templates/certificates/accomplishment-base.html b/lms/templates/certificates/accomplishment-base.html index 1fe0456469c4..554bb607ccbb 100644 --- a/lms/templates/certificates/accomplishment-base.html +++ b/lms/templates/certificates/accomplishment-base.html @@ -19,6 +19,19 @@ ${document_title} <%static:css group='style-certificates'/> + + + <% ga_4_id = static.get_value("GOOGLE_ANALYTICS_4_ID", settings.GOOGLE_ANALYTICS_4_ID) %> + % if ga_4_id: + + + % endif diff --git a/lms/templates/main.html b/lms/templates/main.html index 48edc767a132..1e9761ffcecb 100644 --- a/lms/templates/main.html +++ b/lms/templates/main.html @@ -160,6 +160,18 @@ % endif +<% ga_4_id = static.get_value("GOOGLE_ANALYTICS_4_ID", settings.GOOGLE_ANALYTICS_4_ID) %> +% if ga_4_id: + + +% endif + <% branch_key = static.get_value("BRANCH_IO_KEY", settings.BRANCH_IO_KEY) %> % if branch_key and not is_from_mobile_app: + + {% endif %} + diff --git a/lms/templates/public_video_share_embed.html b/lms/templates/public_video_share_embed.html new file mode 100644 index 000000000000..cb81c7e15cce --- /dev/null +++ b/lms/templates/public_video_share_embed.html @@ -0,0 +1,129 @@ +## coding=utf-8 + +<%page expression_filter="h"/> +<%! main_css = "style-main-v1" %> + +<%namespace name='static' file='static_content.html'/> +<%! +import six +from lms.djangoapps.branding import api as branding_api +from django.utils.translation import gettext as _ +from django.utils.translation import get_language_bidi +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.djangolib.js_utils import js_escaped_string +from openedx.core.release import RELEASE_LINE +from openedx.core.djangolib.markup import HTML +%> + +<%def name="course_name()"> + <% return _("{course_number} Courseware").format(course_number=course.display_number_with_default) %> + + + + + + + + + + + <%def name="pagetitle()" /> + ${static.get_page_title_breadcrumbs(course_name())} + + <% + jsi18n_path = "js/i18n/{language}/djangojs.js".format(language=LANGUAGE_CODE) + ie11_fix_path = "js/ie11_find_array.js" + %> + + + <% favicon_url = branding_api.get_favicon_url() %> + + + <%static:css group='style-vendor'/> + % if '/' in self.attr.main_css: + % if get_language_bidi(): + <% + rtl_css_file = self.attr.main_css.replace('.css', '-rtl.css') + %> + + % else: + + % endif + % else: + <%static:css group='${self.attr.main_css}'/> + % endif + + <%static:js group='main_vendor'/> + <%static:js group='application'/> + + <%static:webpack entry="commons"/> + + <%static:css group='style-course-vendor'/> + <%static:css group='style-course'/> + + <%include file="widgets/segment-io.html" /> + + + <% google_site_verification_id = configuration_helpers.get_value('GOOGLE_SITE_VERIFICATION_ID', settings.GOOGLE_SITE_VERIFICATION_ID) %> + % if google_site_verification_id: + + % endif + + + +<% ga_acct = static.get_value("GOOGLE_ANALYTICS_ACCOUNT", settings.GOOGLE_ANALYTICS_ACCOUNT) %> +% if ga_acct: + +% endif + +<% ga_4_id = static.get_value("GOOGLE_ANALYTICS_4_ID", settings.GOOGLE_ANALYTICS_4_ID) %> +% if ga_4_id: + + +% endif + +<% branch_key = static.get_value("BRANCH_IO_KEY", settings.BRANCH_IO_KEY) %> +% if branch_key and not is_from_mobile_app: + +% endif + + + + + +
+ ${HTML(fragment.body_html())} +
+ + <%static:js group='courseware'/> + ${HTML(fragment.foot_html())} + + diff --git a/openedx/core/djangoapps/site_configuration/templatetags/configuration.py b/openedx/core/djangoapps/site_configuration/templatetags/configuration.py index e142a7a385e6..f73d9b2f8fad 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)