benjaminhoffman / gatsby-plugin-segment-js Goto Github PK
View Code? Open in Web Editor NEWGatsby plugin for segment.com's analytic.js snippet
Home Page: https://www.npmjs.com/package/gatsby-plugin-segment-js
License: MIT License
Gatsby plugin for segment.com's analytic.js snippet
Home Page: https://www.npmjs.com/package/gatsby-plugin-segment-js
License: MIT License
Hey!
Just wondering why you're including the entire package of npm
with this plugin? It feels a bit excessive
Theres a new version of the snippet out. its prob worth updating π―
https://segment.com/docs/sources/website/analytics.js/quickstart/#step-1-copy-the-snippet
Hey!
When I gatsby develop
locally I get this warning:
warn Plugin gatsby-plugin-segment-js is not compatible with your gatsby version 5.0.0 - It requires gatsby@^2 || ^3 || ^4
It seems to be working OK for me but I use it just to add the script, so for me it's safe to just to ignore it. I suppose there'd need to be more tests done to check more complicated functionality before declaring that it's fully working with Gatsby 5.
Thank you for your time π
Thank you, appreciate the project
Page load events are not being sent after enabling delayed loading on Gatsby.
{
resolve: `gatsby-plugin-segment-js`,
options: {
prodKey: `***************`,
trackPage: true,
delayLoad: true,
delayLoadTime: 1000
}
}
"gatsby": "^2.13.31"
"gatsby-plugin-segment-js": "^3.1.0"
Thanks!
Is there a reason why the trackPage
option only calls analtyics.page()
once on initial render, and not on every route change? Seems kinda redundant, and should definitely be documented if nothing else.
Thanks for a great plugin!
I got it working but noticed in my segment dashboard that the title
property always reflects the previous page instead of the one being reported in the pageview.
For example, navigating to /contact
from /download
shows up as:
analytics.page({
path: '/contact',
referrer: '',
search: '',
title: 'Download Qri',
url: 'http://localhost:9000/contact'
});
I'm wondering if anyone has encountered this before or has an idea what could be going wrong.
I have delayLoad
set to true and delayLoadTime
set to 1000
i'd like to bring in linting and formatting libraries. do you have a preference?
i'm thinking either https://standardjs.com/ or the one i use at work https://github.com/pdq/eslint-plugin-pdq with prettier. i don't care too much either way. i would just like some tool to catch those small things
Looks like this plugin is missing the gatsby-ssr.js file when pulling down via NPM / Yarn
Hi. Looking at the source for gatsby-brower.js
, where exactly does the 2nd paramter { trackPage }
come from?
exports.onRouteUpdate = ({}, { trackPage }) => {
https://github.com/benjaminhoffman/gatsby-plugin-segment-js/blob/master/src/gatsby-browser.js#L1
According to the Gatsby Browser API docs, onRouteUpdate
has only 1 parameter, de-structured as { location, prevLocation }
Out of curiosity, was there a particular reason scroll and route changes were chosen as triggers for script load? My usecase needs to delay the load of the script for performance reasons, but an idle pageview is still valuable to us to accurately assess bounce rates.
Is it worth creating an option to listen to load
instead of scroll
? If so, I'm happy to submit a PR if the community thinks it would be useful.
I am not seeing any identify
calls in the Segment debugger for anonymous users.
It's my understanding that anonymous users are tracked automatically (Note from Segment):
Note: You wonβt need to call identify for anonymous visitors to your site. Weβll automatically assign them an anonymousId, so just calling page and track will still work just fine without identify.
Is anyone else experiencing this issue? Is this an issue with Gatsby/SSR and Segment?
Additional info:
trackPage
set to true and it is workingidentify
calls on my site since I do not register/login users, so I rely on the automatic tracking of anonymous users.Analytics is not found when trying to trigger analytics.track from a page. Do you have example code of this working?
Hi, it seems that the latest commit Adding host option (#21) is not released in npm?
Will this package work on Gatsby 4?
Hi! At version 4.0.3, the delay load didn't work.
delayLoad: true,
delayLoadTime: 1000
Segment load without page scroll event or Link click.
Hi, I'm not receiving any tracking events.
I have no problem tracking with the deprecated package (gatsby-plugin-segment
) but after uninstalling it and installing this package no tracking events come through.
Any help would be much appreciated.
gatsby-config.js
below:
module.exports = {
siteMetadata: {
// ...
},
plugins: [
// ...
{
resolve: `gatsby-plugin-segment-js`,
options: {
prodKey: `<PROD_WRITE_KEY>`,
devKey: `<OTHER_WRITE_KEY>`,
},
},
],
}
Working correctly with deprecated library, for reference:
module.exports = {
siteMetadata: {
// ...
},
plugins: [
// ...
{
resolve: `gatsby-plugin-segment`,
options: {
writeKey: `<PROD_WRITE_KEY>`,
},
},
],
}
I need to add google analytics auto linker for a multi domain site
Enabling trackPage
option makes these lines to get run one after all, which ends in duplicate page tracking:
First this from gatsby-ssr.js:
gatsby-plugin-segment-js/src/gatsby-ssr.js
Lines 39 to 41 in 897db9b
or this if delayLoad
is enabled:
and, then, this other from gatsby-browser.js:
In addition, gatsby-ssr and gatsby-broswer calls to page
differ. SSR verison does not pass anything and browser passes the document.title
as param.
Hello,
I've followed the instructions on the Readme.
gatsby-config
{
resolve: 'gatsby-plugin-segment-js',
options: {
prodKey: 'KEY_HERE',
},
}
window.analytics.track('test');
On development mode, I get Cannot read property 'track' of undefined
.
Am I doing something wrong?
I know I can check if window.analytics
exists, but the docs imply that this plugin was handling that?
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?
deprecate the previous version of this repo and add warning to come here instead.
Hi maintainers,
I appreciate all you do. π
A concern came up about Segment deprecating v1 of their analytics.js
library this year? Will this plugin support analytics.js 2.0
?
Adding link for reference:
https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/upgrade-to-ajs2/
Segment JS snippet link (https://segment.com/docs/sources/website/analytics.js/quickstart/) returns 404.
my site uses a link rel="canonical"
tag to support various crawlers/social share/etc. I do this with react-helmet
.
calling analytics.page()
on onRouteUpdated
doesn't work in this case, because this fires before the react component that renders the meta tag is re-rendered.
so at the time when analytics.js tries to figure out what hte current page path is, it looks at the canonical
tag and sees <link data-react-helmet="true" rel="canonical" href="https://todayilearned.io/">
.
so page()
path is set to /
.
the fix could be to use the location.pathname
passed to the onRouteUpdate
hook, as it's the correct route at that point:
segment.js does allow passing in the path manually: https://segment.com/docs/sources/website/analytics.js/#default-properties
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.