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

Civic uk: Accept/reject behaviour #10685

Merged
merged 15 commits into from
Mar 11, 2024
Merged

Civic uk: Accept/reject behaviour #10685

merged 15 commits into from
Mar 11, 2024

Conversation

rcantin-w
Copy link
Contributor

@rcantin-w rcantin-w commented Mar 1, 2024

Who is this for?

Cookie work, #10657

What is it doing for them?

  • Fix logic in common/services/app/civic-uk.ts
  • Modify data layer script to load default consent config for GTM (if the toggle is on)
  • Use one customEvent for consent changes, with a detail property that gives us the new value, which can then be used for gtag() consent.
  • Created a ConsentAndScripts component that is loaded in _app and fires the Civic UK banner as well as Segment's script if it has consent to be there. See comment I left to explain about the GTM script which was there originally but I had to remove.
  • Added a dataGtmTrigger on our preference centre button so it could be our test on GTM tracking.
  • Added more keys on meta tags as they were getting doubled up (again, see comment I mentioned above). This actually changed nothing because of what I think is an identified bug, but I thought I'd leave them there as other meta tags already had them and it's recommended to avoid multiple tags.

For whoever reviews

I reckon the best thing is (1) review code but (2) let's have a call and go over tag manager tracking tests/previews.

@rcantin-w rcantin-w changed the base branch from main to civic-uk-config March 1, 2024 16:05
Copy link

github-actions bot commented Mar 1, 2024

Size Change: +30.6 kB (+3%)

Total Size: 907 kB

Filename Size Change
content/webapp/.next/static/chunks/7107-26a58cfe2165819e.js 0 B -26.6 kB (removed) 🏆
content/webapp/.next/static/chunks/pages/_app-d15613f08aab3a74.js 0 B -105 kB (removed) 🏆
content/webapp/.next/static/chunks/pages/guides/exhibitions/[id]/[type]-61b0e7a1003638cd.js 0 B -4.5 kB (removed) 🏆
identity/webapp/.next/static/chunks/pages/_app-94fdf8177aa862e7.js 0 B -98.7 kB (removed) 🏆
content/webapp/.next/static/chunks/7107-39e87b4b2cf614ba.js 20.1 kB +20.1 kB (new file) 🆕
content/webapp/.next/static/chunks/pages/_app-6de22e4eb771887f.js 124 kB +124 kB (new file) 🆕
content/webapp/.next/static/chunks/pages/guides/exhibitions/[id]/[type]-63bd8728c7f868a3.js 4.5 kB +4.5 kB (new file) 🆕
identity/webapp/.next/static/chunks/pages/_app-f53de085ca530a30.js 118 kB +118 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size
content/webapp/.next/static/chunks/00a8a139.35fd3649f0630c69.js 59 kB
content/webapp/.next/static/chunks/1002-091786cd94f69243.js 4.21 kB
content/webapp/.next/static/chunks/1135-6df3323caa574cb8.js 3.04 kB
content/webapp/.next/static/chunks/1386-116d3de22096e71b.js 4.59 kB
content/webapp/.next/static/chunks/1500-8bb4fa73be8f1d24.js 2.87 kB
content/webapp/.next/static/chunks/1716-d120d2ae60a0b111.js 12.2 kB
content/webapp/.next/static/chunks/1747-59065b5693efcd1e.js 6.08 kB
content/webapp/.next/static/chunks/2787-a5edb63dfa2a1674.js 2.23 kB
content/webapp/.next/static/chunks/2889.628569e90876051d.js 1.81 kB
content/webapp/.next/static/chunks/3734-97a9ae830dcf0e04.js 6.54 kB
content/webapp/.next/static/chunks/4696.1651dbabd4730180.js 1.22 kB
content/webapp/.next/static/chunks/4825-5736484e200c4dcc.js 7.76 kB
content/webapp/.next/static/chunks/6276-27f7a2a0cef2d925.js 2.93 kB
content/webapp/.next/static/chunks/6577-26aad86ec9c90e4e.js 3.5 kB
content/webapp/.next/static/chunks/6651-e80c2951521d8d4b.js 2.5 kB
content/webapp/.next/static/chunks/6677.09e4ad62fda8efa2.js 19.9 kB
content/webapp/.next/static/chunks/7414-eca050180aed34bd.js 5.85 kB
content/webapp/.next/static/chunks/7635-a31f50df8c54642e.js 3.5 kB
content/webapp/.next/static/chunks/7689-c29977a9895407ea.js 19.2 kB
content/webapp/.next/static/chunks/8063-9e55a417a72f3eee.js 19.3 kB
content/webapp/.next/static/chunks/8540-34ed3e85e918ed32.js 3.35 kB
content/webapp/.next/static/chunks/8651-dab2d6c1afb6a811.js 3.1 kB
content/webapp/.next/static/chunks/9065-00af56b50ac29832.js 6.45 kB
content/webapp/.next/static/chunks/9519-6c56edbb53102506.js 7.98 kB
content/webapp/.next/static/chunks/9608-6ee52cf68e6cd812.js 4.44 kB
content/webapp/.next/static/chunks/9704-ab710a499d94815f.js 3.16 kB
content/webapp/.next/static/chunks/framework-efbec734d81f6e89.js 45.2 kB
content/webapp/.next/static/chunks/main-74d7cc624ff0880f.js 30.6 kB
content/webapp/.next/static/chunks/pages/_error-ce2a222093c6d80c.js 332 B
content/webapp/.next/static/chunks/pages/404-33af99be220a02ef.js 258 B
content/webapp/.next/static/chunks/pages/500-607137af978be821.js 257 B
content/webapp/.next/static/chunks/pages/articles-449eb7a4bff0d018.js 3.52 kB
content/webapp/.next/static/chunks/pages/articles/[articleId]-8653f555f091c182.js 3.59 kB
content/webapp/.next/static/chunks/pages/books-eadb78cebf9a0102.js 3.54 kB
content/webapp/.next/static/chunks/pages/books/[bookId]-393181ae5036edea.js 1.55 kB
content/webapp/.next/static/chunks/pages/collections-493e83f03c4e7aa0.js 2.13 kB
content/webapp/.next/static/chunks/pages/concepts/[conceptId]-e8599818eedb2999.js 4.4 kB
content/webapp/.next/static/chunks/pages/covid-welcome-back-c91fa82b7c96f0a7.js 11.3 kB
content/webapp/.next/static/chunks/pages/event-series/[eventSeriesId]-5458c668a8ec55aa.js 3.56 kB
content/webapp/.next/static/chunks/pages/events-1628cf4ee48401f9.js 3.65 kB
content/webapp/.next/static/chunks/pages/events/[eventId]-418daeedbdc66846.js 8.14 kB
content/webapp/.next/static/chunks/pages/events/[eventId]/visual-stories-479def345b306105.js 1.55 kB
content/webapp/.next/static/chunks/pages/exhibitions-9c87732450c9d69a.js 3.84 kB
content/webapp/.next/static/chunks/pages/exhibitions/[exhibitionId]-9049e5c7b2d8e8f3.js 4.01 kB
content/webapp/.next/static/chunks/pages/exhibitions/[exhibitionId]/visual-stories-697d448fca13ad48.js 1.56 kB
content/webapp/.next/static/chunks/pages/guides/[pageId]-3c0d49ec57f2339c.js 2.04 kB
content/webapp/.next/static/chunks/pages/guides/exhibitions-2f748e73add0386f.js 3.61 kB
content/webapp/.next/static/chunks/pages/guides/exhibitions/[id]-b49aa71468711027.js 4.38 kB
content/webapp/.next/static/chunks/pages/index-85132438a2a5e5c6.js 1.86 kB
content/webapp/.next/static/chunks/pages/newsletter-ca9a4ef782b8d15a.js 2.37 kB
content/webapp/.next/static/chunks/pages/pages/[pageId]-a82800723afa1e41.js 2.01 kB
content/webapp/.next/static/chunks/pages/projects/[pageId]-a9e5b0b83f642082.js 2.04 kB
content/webapp/.next/static/chunks/pages/search-8ac2c36f933136cc.js 5.36 kB
content/webapp/.next/static/chunks/pages/search/events-e7c5739007192f9f.js 1.41 kB
content/webapp/.next/static/chunks/pages/search/images-8dd05a2cafa36224.js 2.12 kB
content/webapp/.next/static/chunks/pages/search/stories-a127405245558463.js 3.2 kB
content/webapp/.next/static/chunks/pages/search/works-50960a532bd4a8a4.js 4.36 kB
content/webapp/.next/static/chunks/pages/seasons/[seasonId]-754dcf835bef52f8.js 1.47 kB
content/webapp/.next/static/chunks/pages/series/[seriesId]-8e2d9fb2ec5d6ac0.js 4.03 kB
content/webapp/.next/static/chunks/pages/stories-a6070ba5f8c60a0b.js 3.61 kB
content/webapp/.next/static/chunks/pages/stories/[contentType]-d79630f02953f8ad.js 3.57 kB
content/webapp/.next/static/chunks/pages/visit-us-0a94b199ad6a1c37.js 2.46 kB
content/webapp/.next/static/chunks/pages/visual-stories/[visualStoryId]-72183051a868a1b6.js 1.53 kB
content/webapp/.next/static/chunks/pages/whats-on-d34737c8f7ecdb1f.js 202 B
content/webapp/.next/static/chunks/pages/whats-on/[period]-61bb1c8d2efc89ca.js 271 B
content/webapp/.next/static/chunks/pages/works/[workId]-f4d418a6e2cc9a2a.js 23 kB
content/webapp/.next/static/chunks/pages/works/[workId]/download-5eed014d744b7fb7.js 4.38 kB
content/webapp/.next/static/chunks/pages/works/[workId]/images-68720b37e4940c66.js 1.08 kB
content/webapp/.next/static/chunks/pages/works/[workId]/items-2973396c1999ecc1.js 2.08 kB
content/webapp/.next/static/chunks/polyfills-c67a75d1b6f99dc8.js 31 kB
content/webapp/.next/static/chunks/webpack-235535d2014f1d6e.js 1.67 kB
identity/webapp/.next/static/chunks/374.94537fd117195c86.js 2.48 kB
identity/webapp/.next/static/chunks/432.fa29da5acdb8e0b1.js 744 B
identity/webapp/.next/static/chunks/442-29780463d96993ea.js 8.35 kB
identity/webapp/.next/static/chunks/644-6570c06909c1478e.js 5.92 kB
identity/webapp/.next/static/chunks/677.a0884a27fb537187.js 19.9 kB
identity/webapp/.next/static/chunks/framework-19f3649580393c10.js 45.2 kB
identity/webapp/.next/static/chunks/main-d973a3979032d64a.js 32.2 kB
identity/webapp/.next/static/chunks/pages/_error-8e82953fa241027d.js 1.42 kB
identity/webapp/.next/static/chunks/pages/delete-requested-5e021bca8d83030a.js 3.12 kB
identity/webapp/.next/static/chunks/pages/error-17d4e8a2b11f419d.js 1.59 kB
identity/webapp/.next/static/chunks/pages/index-6abf634a87a44354.js 11.8 kB
identity/webapp/.next/static/chunks/pages/registration-43d7927ce4a379f1.js 4.02 kB
identity/webapp/.next/static/chunks/pages/success-077b471ecf00653a.js 3.19 kB
identity/webapp/.next/static/chunks/pages/validated-69c0d064cd2b3867.js 3.27 kB
identity/webapp/.next/static/chunks/polyfills-c67a75d1b6f99dc8.js 31 kB
identity/webapp/.next/static/chunks/webpack-713796e2734212eb.js 1.81 kB

compressed-size-action

@rcantin-w rcantin-w changed the title Civic uk: accept/reject behaviour WIP: Civic uk: Accept/reject behaviour Mar 1, 2024
<>
{consentState && (
<Head>
<script dangerouslySetInnerHTML={{ __html: segmentSnippet }} />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I originally also put the GTM script in this conditional, but I was experiencing what I think is this Next bug where on loading it/removing it/re-adding it, random meta tags would duplicate themselves, even if they had a key. Someone mentioned that for them it only happened when GTM was enabled, and it does seem to be the case here as well.

I think it's ok though as we set the consent to denied, so no hits are being sent.

Copy link
Contributor

Choose a reason for hiding this comment

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

so no hits are being sent.

I believe the tag still "phones home" via what the docs describe as a "cookie-less ping".

There is the possibly contentious case for adding the GTM script before consent that we still record some analytics data about these users in a legally compliant manner (so long as we set the consent state in the data layer correctly). See https://support.google.com/tagmanager/answer/13802165?sjid=2210990408479536825-EU for more details about what gets communicated to Google in the situation consent is denied.

See "Behavioral modeling for consent mode" for one of the "features" available to us. Notably modelled data for un-consented visitors is not sent via any BigQuery integration.

We should be sure we're comfortable with this, and check with @LaurenFBaily.

Choose a reason for hiding this comment

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

Had a look at this and the documentation, I'm happy with that.

@rcantin-w rcantin-w changed the title WIP: Civic uk: Accept/reject behaviour Civic uk: Accept/reject behaviour Mar 7, 2024
};

// We send toggles as an event parameter to GA4 so we can determine the condition in which a particular event took place.
// GA4 now limits event parameter values to 100 characters: https://support.google.com/analytics/answer/9267744?hl=en
// So instead of sending the whole toggles JSON blob, we only look at the "test" typed toggles and send a concatenated string made of the toggles' name
// , preceeded with a! if its value is false.
function createToggleString(toggles: Toggles | undefined): string | null {
function createABToggleString(toggles: Toggles | undefined): string | null {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I gathered, this only returns AB test strings, so I renamed to clarify.

@rcantin-w rcantin-w marked this pull request as ready for review March 7, 2024 16:50
@rcantin-w rcantin-w requested a review from a team March 7, 2024 16:50
Base automatically changed from civic-uk-config to main March 8, 2024 10:10
@@ -70,11 +70,11 @@ const CivicUK = () => (
'__utmv',
],
onAccept: function () {
const event = new CustomEvent('analyticsConsentChange', {});
const event = new CustomEvent('analyticsConsentChanged', { detail: { consent: 'granted' }});
Copy link
Contributor

Choose a reason for hiding this comment

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

👌

@@ -162,14 +162,22 @@ const PageLayoutComponent: FunctionComponent<Props> = ({
<>
<Head>
<title>{fullTitle}</title>
<meta name="description" content={description} />
<meta key="metadescription" name="description" content={description} />
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be useful to add a comment linking to the next issue describing why we're adding key here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think not here, as the Next issue is saying that this should work but doesn't. It's a recommendation from their official documentation for next/head, so "normal".

If we wanted to keep track of that issue I could add it to where we load the GTM script and explain that's why we're not removing it?

} else {
// If the feature flag is ON but consent has yet to be defined
return false;
}
} else {
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

In the future we'll need the default no consent state to be false, worth adding a comment to be double sure we do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we remove the toggle and therefore the first condition, and only keep the second condition, with a change to the comments, that's what it'll do 👍

if (consentCookie !== undefined) {
    const civicUKCookie: CivicUKCookie = JSON.parse(
      decodeURIComponent(consentCookie)
    );

    return civicUKCookie.optionalCookies?.analytics === 'accepted';
  } else {
    // If consent has yet to be defined, return false by default
    return false;
  }
}

We'll for sure test that a lot, it's why we'll requisition e2e for a bit, with all the toggle stuff out of the way 🤞

data.toggles?.cookiesWork?.value
? `function gtag(){window.dataLayer.push(arguments);}

gtag('consent', 'default', {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we need some more fields here to adhere to "consent mode v2": https://developers.google.com/tag-platform/security/guides/consent?consentmode=advanced#upgrade-consent-v2, specifically ad_user_data and ad_personalization.

I expect we'll just hard-code the values to denied though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yess I wasn't sure we used those because adding them caused me TS errors, looks like the gtag helpers don't know about them?

No overload matches this call.
  The last overload gave the following error.
    Object literal may only specify known properties, and 'ad_personalization' does not exist in type 'ConsentParams'.
Screenshot 2024-03-08 at 11 48 54

That being said, as I'm looking at this, it's only a problem in the TS code when we update the values, and not on the default/initialisation one. And we should only change the analytics_storage value if they allow analytics and the others should be denied from the get go, including ad_storage, which I currently mark as granted if analytics is. So I'll change that to add everything to the consent initialisation and only change analytics_storage on consent given.

If ever we want those to be changeable, we'll deal with TS errors then. Not a problem for now. I'll stop thinking out loud and apply changes 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can review this on Monday but changes applied:

(default setting)
Screenshot 2024-03-08 at 12 05 12

(on rescinding consent)
Screenshot 2024-03-08 at 12 05 24

Copy link
Contributor

@kenoir kenoir left a comment

Choose a reason for hiding this comment

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

Looks good, pending pairing on final review.

@rcantin-w rcantin-w merged commit 71a5e17 into main Mar 11, 2024
5 checks passed
@rcantin-w rcantin-w deleted the civic-uk-behaviour branch March 11, 2024 11:06
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.

3 participants