Certificate Error after enable GOOGLE_ANALYTICS_4_ID

Hi
I Install plugin GOOGLE_ANALYTICS_4_ID

from tutor import hooks

hooks.Filters.ENV_PATCHES.add_items([
    (
        "openedx-common-settings",
        "GOOGLE_ANALYTICS_4_ID = 'G-xxxxxxxxxx'"
    ),
    (
        "mfe-lms-common-settings",
        "MFE_CONFIG['GOOGLE_ANALYTICS_4_ID'] = 'G-xxxxxxxxxx'"
    ),
])

and enable tutor plugins enable GOOGLE_ANALYTICS_4_ID
certificate error

There has been a 500 error 

I add code to lms/templates/certificates/accomplishment-base.html

<%!
from django.utils.translation import gettext as _
from openedx.core.djangolib.js_utils import js_escaped_string
%>

and
lms/djangoapps/certificates/tests/test_views.py

    @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED, GOOGLE_ANALYTICS_4_ID='G-xxxxxxxxxx')
    @with_site_configuration(configuration={'platform_name': 'My Platform Site'})
    def test_html_view_with_g4(self):
        test_url = get_certificate_url(
            user_id=self.user.id,
            course_id=str(self.course.id),
            uuid=self.cert.verify_uuid
        )
        self._add_course_certificates(count=1, signatory_count=2)
        response = self.client.get(test_url)
        self.assertContains(
            response,
            'awarded this My Platform Site Honor Code Certificate of Completion',
        )
        self.assertContains(response, 'googletagmanager')

but not work

Hi. - have you followed the instructions in Configuring Google Analytics — Latest documentation? I got that link from the Tutor docs.

1 Like

Hi. @sarina
I followed the instructions.
Previously, I was using the Palm version without any issues, but after updating to the Redwood version, I encountered a 500 error status

tutor_local-lms-1            | 2025-02-05 02:59:35,967 ERROR 22 [django.request] [user 2613] [ip 10.152.253.166] log.py:241 - Internal Server Error: /certificates/61ba2a11bf38413e858b640e32c57220
tutor_local-lms-1            | Traceback (most recent call last):
tutor_local-lms-1            |   File "/openedx/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
tutor_local-lms-1            |     response = get_response(request)
tutor_local-lms-1            |                ^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1            |   File "/openedx/venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
tutor_local-lms-1            |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
tutor_local-lms-1            |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1            |   File "/opt/pyenv/versions/3.11.8/lib/python3.11/contextlib.py", line 81, in inner
tutor_local-lms-1            |     return func(*args, **kwds)
tutor_local-lms-1            |            ^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1            |   File "/openedx/edx-platform/lms/djangoapps/certificates/views/webview.py", line 455, in render_cert_by_uuid
tutor_local-lms-1            |     return render_html_view(request, str(certificate.course_id), certificate)
tutor_local-lms-1            |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1            |   File "/openedx/edx-platform/common/djangoapps/util/views.py", line 139, in inner
tutor_local-lms-1            |     return func(request, *args, **kwargs)
tutor_local-lms-1            |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1            |   File "/openedx/venv/lib/python3.11/site-packages/edx_django_utils/plugins/pluggable_override.py", line 77, in wrapper
tutor_local-lms-1            |     return prev_fn(*args, **kwargs)
tutor_local-lms-1            |            ^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1            |   File "/openedx/edx-platform/lms/djangoapps/certificates/views/webview.py", line 613, in render_html_view
tutor_local-lms-1            |     response = _render_valid_certificate(request, context, custom_template)
tutor_local-lms-1            |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1            |   File "/openedx/edx-platform/lms/djangoapps/certificates/views/webview.py", line 703, in _render_valid_certificate
tutor_local-lms-1            |     return render_to_response("certificates/valid.html", context)
tutor_local-lms-1            |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1            |   File "/openedx/edx-platform/common/djangoapps/edxmako/shortcuts.py", line 188, in render_to_response
tutor_local-lms-1            |     return HttpResponse(render_to_string(template_name, dictionary, namespace, request), **kwargs)
tutor_local-lms-1            |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1            |   File "/openedx/edx-platform/common/djangoapps/edxmako/shortcuts.py", line 178, in render_to_string
tutor_local-lms-1            |     return template.render(dictionary, request)
tutor_local-lms-1            |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1            |   File "/openedx/edx-platform/common/djangoapps/edxmako/template.py", line 82, in render
tutor_local-lms-1            |     return self.mako_template.render_unicode(**context_dictionary)
tutor_local-lms-1            |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1            |   File "/openedx/venv/lib/python3.11/site-packages/mako/template.py", line 443, in render_unicode
tutor_local-lms-1            |     return runtime._render(
tutor_local-lms-1            |            ^^^^^^^^^^^^^^^^
tutor_local-lms-1            |   File "/openedx/venv/lib/python3.11/site-packages/mako/runtime.py", line 874, in _render
tutor_local-lms-1            |     _render_context(
tutor_local-lms-1            |   File "/openedx/venv/lib/python3.11/site-packages/mako/runtime.py", line 916, in _render_context
tutor_local-lms-1            |     _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
tutor_local-lms-1            |   File "/openedx/venv/lib/python3.11/site-packages/mako/runtime.py", line 943, in _exec_template
tutor_local-lms-1            |     callable_(context, *args, **kwargs)
tutor_local-lms-1            |   File "/tmp/mako_lms/1ff981c2157d500713c1ce6bf7fdbce2/indigo/lms/templates/certificates/accomplishment-base.html.py", line 106, in render_body
tutor_local-lms-1            |     __M_writer(js_escaped_string(ga_4_id ))
tutor_local-lms-1            |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
tutor_local-lms-1            | TypeError: 'Undefined' object is not callable

The problem happened because you use tutor-indigo theme. The theme is using an outdated accomplishment-base.html version.
You can replace the accomplishment-base.html template with the one in edx-platform repository (Redwood or newer version).
After that you have to rebuild openedx image and relaunch your instance to apply the fix.

1 Like

@Anh_Vu_Nguy_n Thanks. I rebuild openedx and relaunch so working.