segmentio / analytics-node Goto Github PK
View Code? Open in Web Editor NEWThe hassle-free way to integrate analytics into any node application.
Home Page: https://segment.com/libraries/node
License: MIT License
The hassle-free way to integrate analytics into any node application.
Home Page: https://segment.com/libraries/node
License: MIT License
If analytics-node
is a dependency of a project that uses browserify in it's build process, it will trigger the need for the brfs
module which will not have been installed via npm due to being filed under the devDependencies for analytics-node
.
After an npm install brfs
in the root project, it's possible to require('analytics-node')
from within the project without issue.
When the brfs
module is unavailable the following error occurs during the browserify require step:
Error: Cannot find module 'brfs' from '/[...]/node_modules/analytics-node'
Warning: Error running grunt-browserify. Use --force to continue.
Aborted due to warnings.
var Analytics = require('analytics-node');
var analytics = Analytics(options);
instead of
var analytics = require('analytics-node');
analytics.init(options);
to remove side effects and make more composable.
Since superagent is not a fixed dependency https://github.com/segmentio/analytics-node/blob/master/package.json#L24, so users of analytics-node are impacted due to an incompatibility with express introduced in superagent 1.7.0.
Currently can't use analytics-node in an expressjs app due to this issue: ladjs/superagent#862
I just updated atom-beautify which uses analytics-node and analytics-node.js
gets flagged by ClamXav to have MCL Exploit CVE 2015-6127.
This is obviously bs but I thought you might be interested to know about this because if ClamXav flags it for me, it most likely flags it for many other people as well.
Is there a way app.use()
with this module?
In https://segment.com/YOUR_ORG_NAME/YOUR_PROJECT_NAME/setup/install
, there are bunch of codes that in inline javascript which would fetch latest analytics.js from cloud and inject some default methods for analytics
variable.
After doing some investigations, it seems that the default methods below do miss a lot of implementations from https://segment.com/docs/libraries/analytics.js/. like timeout
, reset
... etc.
analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","group","track","ready","alias","page","once","off","on"];
If we do call these methods before the request is back (or the request failed), these un-checked methods will cause javascript errors directly. Is there any reason for not adding them into analytics.methods
?
analytics.track(ctx, function(err){
// ...
})
instead of
analytics.track(ctx)
.on('error', function(err){
// ...
})
.on('flush', function(){
// ...
});
apparently we only set timestamps in the case that the user actually passes in the timestamp, otherwise we trust our server time. we should probably record the local server time if the user is intentionally batching a ton, so that all of their data doesn't come in with the same timestamp
since with version 1.1.1 npm install give error:
npm ERR! peerinvalid The package superagent does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants superagent@>= 0.15.4 && < 2
npm ERR! peerinvalid Peer [email protected] wants superagent@~0.19.0
Thanks for package!
When running npm install --save analytics-node and invoking in my RN Project I get the following error:
Unable to resolve module assert.
I'm seeing inconsistent event tracking in intercom. Sometimes track calls show up in intercom with a user and sometimes the user has no events. All the data appears to be going to segment.io, but possibly not in the correct order.
I am curious if its because we call identify()
and track()
asynchronously....I noticed track()
has a callback option but I could not find one documented for identify()
.
We need something like this:
analytics.identify(identifyData, function(err, resp){
analytics.track(trackingData);
}
In our specific use case its for a cli tool written in node. There is no user login or authentication....so we identify the user (uuid hardware id) every time we track a command.
We are currently doing the following which is yielding inconsistent results:
analytics.identify(identifyData);
analytics.track(trackingData);
Now everything that depends on analytics-node 0.5.0 fails npm install:
deshao (1)~/base> npm install
npm WARN unmet dependency /home/eshao/wsp/kites/src/kites-base/node_modules/kites-util/node_modules/analytics-node/node_modules/request/node_modules/form-data requires mime@'~1.2.2' but will load
npm WARN unmet dependency undefined,
npm WARN unmet dependency which is version undefined
As you can see, analytics-node depends on request which depends on form-data which depends on mime 1.2.2, which has gone missing.
If I deploy your package tomorrow it WILL break since I will get different versions of the packages. Please pin the exact version of the dependency as you tested and worked on it so that history can be properly preserved when we need to come back to older versions of the code :)
According to the documentation:
By default, our library will flush:
The very first time it gets a message.
Every 20 messages (controlled by options.flushAt).
If 10 seconds has passed since the last flush (controlled by options.flushAfter)
However the actual implementation resets the timeout every single time an event is enqueued:
https://github.com/segmentio/analytics-node/blob/master/analytics-node.js#L183-L185
What this means is that if you have flushAt
set to 20, and flushAfter
set to 10 seconds then each time a message arrives and is enqueued the timeout that controls flushAfter
is reset to 10 seconds again.
So:
So with the default settings the queue can be stored for up to 200 seconds before flushing rather than the desired 10 seconds.
The correct behavior would be to set the timer on the first enqueued item, and then leave it as is, so that the next flush happens exactly 10 seconds later. If I have time I'll open a PR to fix this.
to maintain symmetry with all of our other libraries (for example check python)
The project URL is set to https://segment.io/libraries/node
which originates:
I'm having the following error after adding the analytics-node
to my package.json
I'm guessing it may be the assert
dependency that might be broken. Can you please have a look at it?
I'm using [email protected]
.
Thanks.
This module has a side effect of leaking to window._
with it set to lodash.
I am trying to pass through a platform
value in the amplitude integration, which is pulling its value from context.library
This module is setting context.library
to analytics-node
even when I pass in a value. You should not override if it a value is provided. It would be better to call _.defaults
instead of _.extend
see: https://github.com/segmentio/analytics-node/blob/master/lib/index.js#L172
In Analytics.prototype.flush
on line 161, the entire batch data is passed to the callback:
fns.forEach(function(fn){ fn(err, data); });
When you implement node-analytics
you don't expect your callback to be called once for each tracked event with the entire batch data. Because that resulted in many hundreds of kb's of log statements for each flush, we now ignore the data passed back:
analytics.track(props, function (err) //removed function (err, data) {
if(err){
return log.error(err);
}
console.log('segment.io: tracked: %j', props); //log props instead of data
});
I would advice to change line 161 to:
fns.forEach(function(fn){ fn(err); }); //no data passed back
Right now, we can't browserify this library because request is incompatible. If you allow the library to take in a dependency, we can pass it request on the server side and https://github.com/iriscouch/browser-request on the client-side.
This would be helpful because analytics.js also doesn't work with browserify.
The superagent
dependency is currently stuck at 1.8.3
, while there have been significant fixes since. In particular, the double callback!
bug is supposed to have been resolved. I see this warning all over my logs but can't tell if it's an issue in superagent
2.3.0
(which my app uses) or just the old bug in 1.8.3
(brought in by analytics-node
).
Seems like the reset
method as detailed here is missing. Per Segment's Chrome extension source on-boarding, I am using this lib to identify
a user when they login but would like to call reset
when they logged out.
I noticed that #46 addresses this and then links to segmentio/analytics.js#485, which is analytics.js
. Should Chrome extension apps be using analytics.js
instead? If that's the case, the Segment documentation should be updated to reflect that.
Current docs outline flush
and error
events on analytics
but they're gone from v1.0.0
https://segment.io/docs/libraries/node/#how-do-i-know-when-_any_-messages-are-flushed-
How do I know when any messages are flushed?
You can also get notified of any flushes or errors by listening on the analytics module itself.analytics.on('flush', function () { console.log('I just got flushed. YAY!'); });
https://segment.io/docs/libraries/node/#error-handling
During integration, you should listen on the error event to make sure that all your data is being properly recorded.
Not sure if these events are still part of the spec, but if not then they should be removed from the documentation.
analytics-node depends on a thing who depends on a guy who deleted his git branch.
├─┬ [email protected]
│ │ The hassle-free way to integrate analytics into any node application.
│ │ git://github.com/segmentio/analytics-node.git
│ │ https://github.com/segmentio/analytics-node
│ └─┬ [email protected]
│ │ `Request#proxy(uri)` superagent extension
│ │ git://github.com/TooTallNate/superagent-proxy.git
│ │ https://github.com/TooTallNate/superagent-proxy#readme
│ └─┬ [email protected]
│ │ Maps proxy protocols to `http.Agent` implementations
│ │ git://github.com/TooTallNate/node-proxy-agent.git
│ │ https://github.com/TooTallNate/node-proxy-agent
│ └─┬ [email protected]
│ │ A PAC file proxy `http.Agent` implementation for HTTP
│ │ git://github.com/TooTallNate/node-pac-proxy-agent.git
│ │ https://github.com/TooTallNate/node-pac-proxy-agent
│ └─┬ [email protected]
│ │ Generates an asynchronous resolver function from a PAC file
│ │ git://github.com/TooTallNate/node-pac-resolver.git
│ │ https://github.com/TooTallNate/node-pac-resolver
│ └─┬ [email protected]
│ │ Turns sync functions into async generator functions
│ │ git://github.com/TooTallNate/node-degenerator.git
│ │ https://github.com/TooTallNate/node-degenerator
│ ├─┬ [email protected]
│ │ │ ECMAScript code generator
│ │ │ git+ssh://[email protected]/Constellation/escodegen.git
│ │ │ http://github.com/Constellation/escodegen
│ │ └── [email protected]
│ │ ECMAScript parsing infrastructure for multipurpose analysis
│ │ git+ssh://[email protected]/ariya/esprima.git
│ │ http://esprima.org
│ └── [email protected] (git+https://github.com/ariya/esprima.git#a41a40b49046747b3af57341cda048bbd3d9df79)
│ ECMAScript parsing infrastructure for multipurpose analysis
│ git+ssh://[email protected]/ariya/esprima.git
│ http://esprima.org
│ git+https://github.com/ariya/esprima.git#harmony
Downstream: TooTallNate/node-degenerator#7
Out-of-the-box, there is no supported way to test against Segment's analytics-node
module without a connection to a Segment server. In your own tests, you guys startup a server process that listens on localhost to test against. This isn't a practical solution for consumers, and it's a better practice to provide a mock shim to test against. Most other libraries support this, please add this functionality.
I think I can work around this by monkey-patching flush
:
analytics.flush = function(fn) {
process.nextTick(() => { fn(null, []); });
};
This is pretty lame though, a supported mock stub would be greatly appreciated. Thanks.
Hi guys, I'm trying to integrate intercom via segment into an universal app with React
After first setup I can see that scripts are injected correctly, but widget is not displayed at all.
NOTE that integration is working perfectly, I can see data into debugger, only widget button is missing
After some hours of troubleshooting I noticed that the only way to get it working is to set
window.intercomSettings = {
app_id: "12345", // change with a real ID
}
But if I set intercomSettings in this way, all the other value I set with analytics are not saved
For example
analytics.identify({
userId: '019mr8mf4r',
traits: {
name: 'Michael Bolton',
email: '[email protected]',
},
})
I already checked secure mode and guest mode
Any idea?
https://github.com/segmentio/analytics-node/blob/master/lib/index.js#L134-L140
https://cloudup.com/cuDAZW6jQUh
you can repro from the simulator :)
In version 0.6.0, analytics-node was also an EventEmitter and we could register callbacks for error
and flush
events. We used that to log any errors which occurred and also when the library flushed messages (for debugging). Obviously, the library is very different now that it is on v2.x, but what is the recommended method for error handling now? Do I have to register a callback with each and every call to a method which calls enqueue()
internally (identify()
, etc)?
uid
can't be resolved by the react-native packager because its package.json's main
property had a value of yes
. I have a PR open that resolves the issue: https://github.com/matthewmueller/uid/pull/9.
now that we changed its name
how to load load up the Drift chat widget on your website?
We use CircleCI everywhere else, so it'd be nice to not have to worry about the differences between Circle and Travis
Thoughts @segmentio/gateway?
Would be nice for internal metrics to see what versions of node our customers are actually using
the spec developed and deployed with the iOS SDK: https://gist.github.com/reinpk/7bd33d29694578b06cce (ignore the requestTimestamp on batch flushing since we don't want to correct timestamps coming from a server)
Hey guys,
Fantastic work on analytics.js, analytics-node, and segment.io in general! I'm finally getting a chance to check it out, and excited to integrate it into our app soon enough.
Just one piece of minor feedback: you might want to rename or alias your "err" event to the more standard Node "error" event (emitted by the native http, stream, net, ...). It'd also play nice then with Node domains, which look for "error" events.
https://segment.io/libraries/node#events
Keep up the great work!
should be defaulted so we don't lose context:
Line 168 in 49af7c9
Any plan to fix the tests? Looks like they have been failing for 14+ days: https://travis-ci.org/segmentio/analytics-node/jobs/21985633
I am considering using segment.io for a project and seeing a failing build for 14 days is a red flag. Given, I don't know your dev/merge process and it looks like you are getting ready to rev the entire API, so other things may be going on. However, the icon on the front page of the repo should always report all tests passing for the latest stable build IMO.
[Error: 404 Cannot POST /v1/batch
16:08:26 web.1 | ]
And I found that you use the following path to add event:
https://api.segment.io/v1/batch
But I didn't find any http api for 'batch' path in the doc:
https://segment.io/docs/tracking-api/reference/
What's wrong with this?
working on a chrome extension as found here: https://segment.com/docs/sources/website/guides/chrome-extension/
step one says to download latest analytics-node library
when I do and require it, I get the following error: Cannot set property length of [object Object] which has only a getter
when I revert back to the version found in this chrome extension: https://github.com/segmentio/daydream/blob/master/lib/background/analytics-node.js, everything seems to work fine.
my extension can be found here: https://github.com/benjaminhoffman/segment-demo-extension. simply swap out the analytics-node file to see the error.
cc @sperand-io
https://github.com/segmentio/spec
anonymousId
from sessionId
for clarity.integrations
object from context
, for cleaner logs.requestId
for easily tracing calls through to the raw logs.library
to be a object with name
and version
for consistency.If a Mongoose user id gets passed to analytics.identify
as userId
, an assertion error is thrown. It could make sense to allow analytics.identify to handle ObjectId
's, since it's a very common format for user ids in Node. Of course, one could always call userIdFromMongoose.toString()
and pass that, but throwing an assertion error and bringing down the server should that get left out seems overboard, especially since analytics
may not be available in testing. As a related question, what do you recommend for analytics
in test - should it be behind an if
(in which case one risks having the server come down due to an assertion error in production), or is it fine just to set up a test account and have it get whaled on during testing?
var Analytics = require('analytics-node')
var analytics = new Analytics('your-write-secret-api-key')
analytics.track({
anonymousId: new Date().getTime(),
event: 'download'
}, function(err) {
if (err) console.error(err)
})
Hi guys,
it seems that it is not possible to retrieve an anonymousId and moreover userId is required
How can I manage this problem?
I should send an identify event like this
return analytics.identify({ anonymousId: 'xxxxxx-xxxxxxxxx-xxxx', )}
But analytics.user().anonymousId()
seems it's not available and userId is required
new Analytics('badKey').identify({userId: "hello", traits: {}}, (err, batch) => {
if (err) {
console.log('err', err)
} else {
console.log('success')
}
})
The above script will log success instead of err. That's unexpected. analytics-node
should return error in callback for invalid write key.
looks like it got removed at some point
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.