-
Troubleshooting issue with Google Analytics 4 and virtual page views
Hey folks!
I’ve got a bit of a quandary on my hands. I’ve been working on integrating Google Analytics 4 into one of my React projects – I used script tags in my
index.html
to sort it. I’ve got Enhanced Measurements all switched on and according to the manual, virtual page views should just get tracked all by themselves.Here’s a screenshot from my dashboard – . Whenever I fire up the page or hit refresh,
page_view
events register just fine, but, for the life of me, I can’t get anypage_view
events to register on virtual page views. That’s using theHashRouter
from React Router to fiddle withlocation.hash
, by the way.Squinting at the debug mode, I noticed that it’s processing the
historyChange
event alright, but no event’s getting sent as a result. Here’s the exact message I’m seeing:Processing commands (1) js?id=G-*********:165 Processing data layer push: {event: "gtm.historyChange-v2", gtm.historyChangeSource: "hashchange", gtm.oldUrlFragment: "/legal", gtm.newUrlFragment: "/", gtm.oldHistoryState: null, gtm.newHistoryState: null, gtm.oldUrl: "http://localhost:3000/", gtm.newUrl: "http://localhost:3000/", gtm.triggers: "8"}
Sure, I could just throw in
page_view
events manually, but that sort of defeats the purpose. I’d really prefer to get it working as expected – out of the box.If anyone’s curious, you can check out this setup over at cra-typescript-starter@a91a6be97f3693f42289d41209e5d0273de02ee5.
Any ideas why this could be happening? Much appreciated!
Log in to reply.