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

Feat: load analytics in cookie-less mode #2375

Merged
merged 4 commits into from
Aug 11, 2023
Merged

Feat: load analytics in cookie-less mode #2375

merged 4 commits into from
Aug 11, 2023

Conversation

katspaugh
Copy link
Member

@katspaugh katspaugh commented Aug 9, 2023

What it solves

We want to make GA more useful by tracking 100% of users. GA4 has a so-called "consent mode" which doesn't set any cookies and doesn't require a cookie consent. This PR enables this mode, and enables GA cookies only if the user opts in.

See https://www.notion.so/safe-global/Client-side-analytics-improvements-152dad5585d6410b8e6cfb20334d6c05

How to test it

  • Open the branch preview site
  • Observe that GTM events are fired w/o accepting the Cookie Banner
  • Check that the GA script is loaded with gcs: G100 parameter (which means cookies are disabled).
  • Check that no _ga cookies are set
  • Press "Accept all" in the cookie banner
  • Observe that GA cookies are added
  • Observe that GA requests now contain gcs: G101 param (meaning cookies are enabled)

@github-actions
Copy link

github-actions bot commented Aug 9, 2023

Branch preview

✅ Deploy successful!

https://cookieless_ga--walletweb.review-wallet-web.5afe.dev

@github-actions
Copy link

github-actions bot commented Aug 9, 2023

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

Copy link
Member

@usame-algan usame-algan left a comment

Choose a reason for hiding this comment

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

We can use gtag types by adding the package yarn add -D @types/gtag.js and updating the definitions.d.ts so we don't have to cast the window object to any. I Also noticed that we have a typo and missing import in the definitions file which we could fix.

The @types/gtag.js doesn't have all the consent attributes so I've opened a PR to update it accordingly: DefinitelyTyped/DefinitelyTyped#66327

src/services/analytics/TagManager.ts Outdated Show resolved Hide resolved
src/services/analytics/useGtm.ts Show resolved Hide resolved
Copy link
Member

@usame-algan usame-algan left a comment

Choose a reason for hiding this comment

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

Works nicely for me. I tried with and without cookies set and the change is reflected in tagmanager. Have we checked how cookieless-mode will affect the data in GA i.e. creating funnels might have limited options?

@types/gtag.js has been released with the changes so we could also use that if we want to have better type support.

@katspaugh
Copy link
Member Author

I don't want to include a dependency for these types, as the type of the gtag function is pretty loose anyway, it basically takes any number of any arguments.

@katspaugh
Copy link
Member Author

@francovenica we'd like to release this as a separate release sometime next week. Are you OK with that timeline?

@safe-global safe-global deleted a comment from francovenica Aug 10, 2023
@francovenica
Copy link
Contributor

Note: I've checked that the track is there with no cookies, but I haven't checked every action that triggers a tracking event in the entire app, I think that's out of the scope. I'll check during the next regression
Note2: I can only see the calls, but I'd like to see if we can see actually the tracking being saved in GA or wherever it goes when the Analytics checkbox is not enabled.

I've checke the GTM calls in the console when no cookies have been enabled.

I've checked the G100 and G101 params Depending on if the tracker is enabled or not by cookies:
image
image

I've checked that the _ga cookies show up/go away dedpending on if the tracker is enabled or not. I noticed some _ga[NUMBERS] cookies there, but those also show up the stg env when the analytics are disabled, so I assume is expected for those to be there.
image
image

@katspaugh
Copy link
Member Author

No, no cookies should be there when analytics is not enabled.

@francovenica
Copy link
Contributor

francovenica commented Aug 11, 2023

Then I'll kick it back to remove those _ga cookies.

The rest is fine

@katspaugh
Copy link
Member Author

@francovenica _ga_XXX cookies are now removed as well ✅

@francovenica
Copy link
Contributor

Looks good, the cookies are removed:
cookies

@katspaugh katspaugh merged commit fbd17fa into dev Aug 11, 2023
7 checks passed
@katspaugh katspaugh deleted the cookieless-ga branch August 11, 2023 17:04
@github-actions github-actions bot locked and limited conversation to collaborators Aug 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants