Closed shortcircuit3 closed 4 years ago
Looking through the changes you've made here,I think this is the wrong there is a better approach and we already provide a way to do what you want.
What you want to do is add your own gatsby-browser.js file, add the code from this page here: https://github.com/benjaminhoffman/gatsby-plugin-segment-js/blob/master/src/gatsby-browser.js
Then in the trackSegmentPage
function you would add your window.analytics.ready()
code. Once the code in trackSegmentPage
is ran, you're guaranteed to have the window.analytics
code loaded. If you need to run it only once, you can add a boolean for that that you flip after the code has run. Does that make sense?
Thank you for the reply! This approach worked for me :). Maybe a PR with an explanation of adding code would be helpful for noobies like me.
I need this to add google analytics auto linking. I dont think this is the best implementation, but it's the only way I could figure out how. Please make suggestions and I can fix @Kilian @benjaminhoffman
Fixes #22