bugfix(site): analytics - ga4 initialization - #52
Conversation
There was a problem hiding this comment.
maybe mention in the PR description that this is a two-parter--one that preps to use the new analytics solution (this one), and another that implements specific tracking.
i see ```Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
- You might have mismatching versions of React and the renderer (such as React DOM)
- You might be breaking the Rules of Hooks
- You might have more than one copy of React in the same app
See https://react.dev/link/invalid-hook-call for tips about how to debug and fix this problem.```
logged upon request for any route, so some refactoring must be in order there or maybe just a swap to use client:only="react".
lastly, be sure to keep documentation in line with changes.
mbwatson
left a comment
There was a problem hiding this comment.
nice fixes. seems to be working!
because the analytics stuff is not inherently tied to React, i'd say long-term i'd like to see this in plain javascript. notice this is only an effect that returns null, so this is effectively a script with React overhead.
|
|
||
| Dug search interactions push analytics events to `window.dataLayer`. | ||
| To route those events to GA4, configure Google Tag Manager and set: | ||
| This app uses direct Google Analytics 4 with `gtag.js`, not Google Tag Manager. Analytics events may still pass through `window.dataLayer` as part of the standard GA4 setup.` |
There was a problem hiding this comment.
minor nitpick: trailing backtick on this line
This PR is the first part of a two-part analytics update.
It moves GA4 initialization out of
AnalyticsController.tsxand into the<head>ofBase.astro, and it renames the environment variable fromPUBLIC_GTM_IDtoPUBLIC_GA_ID.This change prepares the site to use the new direct GA4 analytics setup. A follow-up PR will implement specific tracking behavior on top of that foundation.
Analytics events are being sent to google analytics and have been confirmed in the dashboard.