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

Add Cookie banner and Google Tag Manager snippet #19

Merged
merged 28 commits into from
Nov 12, 2024

Conversation

kacperpONS
Copy link
Contributor

@kacperpONS kacperpONS commented Nov 5, 2024

What is the context of this PR?

We wanted to add the DS cookies banner as part of our base template.

Things that were changed and require some explanation:

  • Logic for handling the language of the banner
    Even though multi-language isn't yet supported, I added placeholder logic for displaying the Banner in Welsh if the LANGUAGE_CODE is set to cy and in English for all other lang codes.

  • Removed the Tracking site setting model and added the migration
    After the changes in this PR we pass the settings as env variables and don't use the Tracking model anymore to store the values. After consultation with @zerolab, we've decided to remove the model and migrate the database.
    A side effect of this change is that when we'll want to change the value of any of the env variables, an app reload will be required (which might require some downtime depending on how we go about it on the infrastructure level)

  • Old version of Design System
    This project is using release 70.0.17 of the Design System, the November prototype is using 72.0.0 and the latest version is 72.0.1.
    As a result I had to use an old name of a template variable, that does not appear on the Design System website, so there's currently a mismatch that needs to be noted because it will break the banner when we update the DS version.
    In release 72.0.0 of the DS the variable settingsLinkTextURL has been renamed to settingsLinkURL . In this PR I'm using the old version
    (See: Update param name settingsLinkTextURL to settingsLinkURL in Cookies Banner component design-system#3300)

How to review

Describe the steps required to test the changes (include screenshots if appropriate).

  1. Spin up the project locally
  2. Make sure that the tests pass
  3. Go to localhost:8000 in Incognito and make sure that the banner is displayed
  4. Change the LANGUAGE_CODE in settings to "cy" and confirm that the banner is displayed in Welsh

Testing GTM connection

You can also test that the GTM snippet works correctly by going to https://tagmanager.google.com/, creating an account and retrieving a GTM Container ID and passing it in the Docker-compose file.

As part of this card I've tested this too, see the screenshots below to know what to expect to see in the GTM console.

  1. GTM container id is set up correctly on the page, but consent isn't yet given.
Screenshot 2024-11-05 at 12 36 27
  1. The user accepts the cookies on the banner
Screenshot 2024-11-05 at 12 37 20
  1. The page is detected in the GTM console
Screenshot 2024-11-05 at 12 37 38

Follow-up Actions

  • Discuss updating the Design System version to latest

Link to the Jira card

https://jira.ons.gov.uk/browse/CMS-189

@kacperpONS kacperpONS requested a review from a team as a code owner November 5, 2024 15:35
@ababic
Copy link
Contributor

ababic commented Nov 5, 2024

Hi @kacperpONS. I think you might find (as I did for the prototype) that using https://www.ons.gov.uk/cookies as the management URL will produce some strange inconsistencies, especially in environments that aren't using the ons.gov.uk domain. Essentially, changes made on https://www.ons.gov.uk/cookies might not 'filter through' to the active environment, whereas clicking the buttons in the banner directly will.

On the prototype, we had to add our own version of the https://www.ons.gov.uk/cookies page, following the advice in the design system. You might find that you need the URL and view changes from ONSdigital/dis-wagtail-alpha#112 too.

@kacperpONS
Copy link
Contributor Author

Replying to @ababic, we've decided that for the time being the cookies page will not reside in Wagtail and we'll point to the existing Cookies page on the ONS domain. This is noted on the card in Jira CMS-189

The risk that Andy mentions is known and that has been confirmed at today's stand up meeting. 👍

@kacperpONS
Copy link
Contributor Author

A small comment to the above commit:

Now that we take the settings for the Cookie banner as env variables rather than a model in the db we won't be able to dynamically change the app settings to test that custom values are being picked up correctly. The app settings are loaded on app startup from the settings file and per Django docs you shouldn’t alter settings in your applications at runtime.

I've therefore removed the test checking that the custom values of the env variables have been picked up, and only left the one that checks that sensible/expected default values are set.

Copy link
Contributor

@zerolab zerolab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work @kacperpONS.
Left a few notes and suggestions

@kacperpONS
Copy link
Contributor Author

^ Comment to the above commit:
I've just spotted that the because I've used a custom value for the settingsLinkText the custom text ("Manage settings")on the Welsh version of the banner was still appearing in English.
I've removed that field completely because it wasn't a requirement on this card (I've accidentally copied that from the Nov prototype version). We can still add it back at some point but that would need to be complemented by a translation for it to work as expected.

@sanjeevz3009 sanjeevz3009 self-requested a review November 8, 2024 14:59
Copy link
Contributor

@zerolab zerolab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One non-blocking suggestion from me.
Otherwise LGTM

Copy link
Contributor

@sanjeevz3009 sanjeevz3009 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulled down the branch, tested the features locally and the tests all passes. LGTM!

Minor: The branch is out of date with main.

@kacperpONS
Copy link
Contributor Author

@sanjeevz3009 @zerolab can I get a re-review plz 🙏

Copy link
Contributor

@MebinAbraham MebinAbraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

@zerolab zerolab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@kacperpONS kacperpONS merged commit 4fac1fb into main Nov 12, 2024
7 checks passed
@kacperpONS kacperpONS deleted the CMS-189-cookie-banner branch November 12, 2024 14:21
nehakerung added a commit that referenced this pull request Nov 19, 2024
* Standard_pages app creation

* Django models for information page updated and the template for the information page tweaked

* Replace `pytest` with Django's built-in runner (#18)

* Release calendar pages (#16)

* Replace Docker Desktop setup with Colima (#24)

* Add Cookie banner and Google Tag Manager snippet (#19)

* Analysis page and series (#20)

* Addition of equation partials

* Repeated code remove, /media added to .gitignore, media file removed

* Related pages InlinePanel added. Add Info Template updated.

---------


Co-authored-by: Neha <[email protected]>
Co-authored-by: Sanjeev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants