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

Switch to third-party GA4 #4138

Merged
merged 4 commits into from
Feb 5, 2024
Merged

Switch to third-party GA4 #4138

merged 4 commits into from
Feb 5, 2024

Conversation

rhelmer
Copy link
Collaborator

@rhelmer rhelmer commented Feb 2, 2024

Description

GA4 loads, but we're not seeing data flowing. There appears to be a problem with the way we're loading the script. While I was investigating a fix, I noticed there's a @next/third-parties/google module that we can just drop-in, it's documented here:

https://nextjs.org/docs/app/building-your-application/optimizing/third-party-libraries#google-analytics

I left the useGa hook largely alone, but I did drop a note in there that we could replace a lot of the window.gtag setup with the sendGAEvent included in the @next/third-parties/google module. The one thing I had to do was move the check for doNotTrack to the hook, since the script is loaded in a server component now (in layout.tsx as recommended by the docs).

With this in place, I now see data flowing in the network tab in browser devtools.

@rhelmer rhelmer requested a review from mansaj February 2, 2024 19:27
@rhelmer rhelmer self-assigned this Feb 2, 2024
src/app/hooks/useGa.ts Show resolved Hide resolved
src/app/hooks/useGa.ts Show resolved Hide resolved
src/app/layout.tsx Outdated Show resolved Hide resolved
@rhelmer rhelmer merged commit 1f8562c into main Feb 5, 2024
13 checks passed
@rhelmer rhelmer deleted the switch-to-third-party-ga4 branch February 5, 2024 18:05
rhelmer added a commit that referenced this pull request Feb 5, 2024
* Switch to third-party GA4

---------

Co-authored-by: Vincent <Vinnl@users.noreply.github.com>
rhelmer added a commit that referenced this pull request Feb 6, 2024
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.

None yet

4 participants