Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICMSLST-2524 - Update to GA tags #1378

Merged
merged 1 commit into from
Mar 6, 2024
Merged
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
8 changes: 0 additions & 8 deletions .env.local-docker
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,6 @@ E2E_USER_PASSWORD=admin

# Google Analytics
GTM_ENABLED=False
GTM_CASEWORKER_AUTH_KEY=''
GTM_IMPORTER_AUTH_KEY=''
GTM_EXPORTER_AUTH_KEY=''

GTM_CASEWORKER_CONTAINER_ID=''
GTM_IMPORTER_CONTAINER_ID=''
GTM_EXPORTER_CONTAINER_ID=''

GTM_CASEWORKER_PREVIEW_KEY=''
GTM_IMPORTER_PREVIEW_KEY=''
GTM_EXPORTER_PREVIEW_KEY=''
12 changes: 0 additions & 12 deletions web/jinja2.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@ def environment(**options):
"get_css_rules_as_string": get_css_rules_as_string,
"get_file_base64": get_file_base64,
"gtm_enabled": settings.GTM_ENABLED,
"get_gtm_auth_key": get_gtm_auth_key,
"get_gtm_container_id": get_gtm_container_id,
"get_gtm_preview_key": get_gtm_preview_key,
}
)
env.filters["show_all_attrs"] = show_all_attrs
Expand All @@ -220,16 +218,6 @@ def get_file_base64(path: str) -> str:
return base64.b64encode(file_path.read_bytes()).decode("utf-8") # /PS-IGNORE


def get_gtm_auth_key(request: AuthenticatedHttpRequest) -> str:
current_site = request.site
return settings.GTM_AUTH_KEYS[current_site.name]


def get_gtm_container_id(request: AuthenticatedHttpRequest) -> str:
current_site = request.site
return settings.GTM_CONTAINER_IDS[current_site.name]


def get_gtm_preview_key(request: AuthenticatedHttpRequest) -> str:
current_site = request.site
return settings.GTM_PREVIEW_KEYS[current_site.name]
25 changes: 9 additions & 16 deletions web/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@
<head>
<!-- Google Tag Manager -->
{% if gtm_enabled %}
<script nonce="{{ request.csp_nonce }}">(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 + '&gtm_auth={{ get_gtm_auth_key(request) }}&gtm_preview={{ get_gtm_preview_key(request) }}&gtm_cookies_win=x';
f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', '{{ get_gtm_container_id(request) }}');</script>
<script nonce="{{ request.csp_nonce }}">
(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','{{ get_gtm_container_id(request) }}');
</script>
{% endif %}
<!-- End Google Tag Manager -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
Expand Down Expand Up @@ -48,9 +42,8 @@
<!-- Google Tag Manager (noscript) -->
{% if gtm_enabled %}
<noscript>
<iframe
src=https://www.googletagmanager.com/ns.html?id={{ get_gtm_container_id(request) }}&gtm_auth={{ get_gtm_auth_key(request) }}&gtm_preview={{ get_gtm_preview_key(request) }}&gtm_cookies_win=x
height="0" width="0" style="display:none;visibility:hidden"></iframe>
<iframe src=https://www.googletagmanager.com/ns.html?id={{ get_gtm_container_id(request) }}
height="0" width="0" style="display:none;visibility:hidden"></iframe>
</noscript>
{% endif %}
<!-- End Google Tag Manager (noscript) -->
Expand Down
16 changes: 1 addition & 15 deletions web/tests/views/test_cookie_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,28 @@

class TestGtmTags:
def test_site_names_match(self):
"""Testing that the keys used in the GTM dicts match the actual SiteName choices."""
assert set(settings.GTM_AUTH_KEYS.keys()) == set(SiteName.labels)
"""Testing that the keys used in the GTM container dict match the actual SiteName choices."""
assert set(settings.GTM_CONTAINER_IDS.keys()) == set(SiteName.labels)
assert set(settings.GTM_PREVIEW_KEYS.keys()) == set(SiteName.labels)

@override_settings(
GTM_AUTH_KEYS={"Caseworker": "cw_auth_key"},
GTM_CONTAINER_IDS={"Caseworker": "cw_container_id"},
GTM_PREVIEW_KEYS={"Caseworker": "cw_preview_key"},
)
def test_caseworker_tags_rendered_correctly(self, cw_client):
response = cw_client.get("", follow=True)
assert "gtm_auth=cw_auth_key" in response.content.decode("utf-8")
assert "gtm_preview=cw_preview_key" in response.content.decode("utf-8")
assert "id=cw_container_id" in response.content.decode("utf-8")

@override_settings(
GTM_AUTH_KEYS={"Export A Certificate": "export_auth_key"},
GTM_CONTAINER_IDS={"Export A Certificate": "export_container_id"},
GTM_PREVIEW_KEYS={"Export A Certificate": "export_preview_key"},
)
def test_export_tags_rendered_correctly(self, exporter_client):
response = exporter_client.get("", follow=True)
assert "gtm_auth=export_auth_key" in response.content.decode("utf-8")
assert "gtm_preview=export_preview_key" in response.content.decode("utf-8")
assert "id=export_container_id" in response.content.decode("utf-8")

@override_settings(
GTM_AUTH_KEYS={"Import A Licence": "import_auth_key"},
GTM_CONTAINER_IDS={"Import A Licence": "import_container_id"},
GTM_PREVIEW_KEYS={"Import A Licence": "import_preview_key"},
)
def test_import_tags_rendered_correctly(self, importer_client):
response = importer_client.get("", follow=True)
assert "gtm_auth=import_auth_key" in response.content.decode("utf-8")
assert "gtm_preview=import_preview_key" in response.content.decode("utf-8")
assert "id=import_container_id" in response.content.decode("utf-8")


Expand Down
Loading