-
Integrating Google Analytics 4 with Inertia React in Laravel 10
Hey pals, so I’ve been working with laravel 10, which comes built in with reactjs and inertia – plus SSR – for my newest app.
I’ve decided to use this react-ga4 package, but honestly, I’m drawing a blank. Where exactly do I put the initialization code in the app root?
ReactGA.initialize("your GA measurement id");
Here’s how my
app.jsx
currently looks like:import './bootstrap'; import '../css/app.css'; import { createRoot } from 'react-dom/client'; import { createInertiaApp } from '@inertiajs/react'; import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers'; const appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Laravel'; createInertiaApp({ title: (title) =>
<span class="hljs-subst">${title}</span> - <span class="hljs-subst">${appName}</span>
, resolve: (name) => resolvePageComponent(./Pages/<span class="hljs-subst">${name}</span>.jsx
, import.meta.glob('./Pages/**/*.jsx')), setup({ el, App, props }) { const root = createRoot(el); root.render(<App {...props} />); }, progress: { color: '#4B5563', }, });Any thoughts on where this initialize and send code from react-ga4 package should go?
Log in to reply.