benjaminhoffman / gatsby-plugin-segment-js

Gatsby plugin for segment.com's analytic.js snippet
https://www.npmjs.com/package/gatsby-plugin-segment-js
MIT License
40 stars 28 forks source link

page tracking not fired on initial page load #26

Closed chriswhong closed 4 years ago

chriswhong commented 4 years ago

After experimenting a bit with this plugin with trackPage: true, I saw that page tracking events only happened when navigating within the app using client-side routing. The initial load of a page didn't show up in the segment debugger.

I experimented by trying to add window.analytics && window.analytics.page(); to some of the SSR API functions in gatsby, but wasn't able to get it working.

Am I missing something, or is the page tracking only triggered when client-side route changes?

benjaminhoffman commented 4 years ago

oh that's super weird. definitely not our intention. do you have any thoughts on a potential fix? i can investigate myself much later because i'm super swamped but always open for some PRs! :)

chriswhong commented 4 years ago

Sorry, ended up using gatsby-plugin-segment-analytics for our site.

benjaminhoffman commented 4 years ago

hi @chriswhong, i think this issue is now solved. im not super sure but according to @TomPridham, it may! but i don't have the details to recreate it. thanks again for opening this issue.