Code Monkey home page Code Monkey logo

analytics-node's People

Contributors

alanjcharles avatar ankurchandraa avatar calvinfo avatar danieljackins avatar dependabot[bot] avatar dominicbarnes avatar f2prateek avatar fathyb avatar fauzyy avatar felipe-najson-ntf avatar greenkeeper[bot] avatar horacio-penya avatar ianstormtaylor avatar jesusprubio avatar juliangruber avatar michaelghseg avatar michaltk avatar nd4p90x avatar ngphi avatar nhi-nguyen avatar nijikokun avatar pbassut avatar pooyaj avatar reinpk avatar segmentbot avatar serhalp avatar silesky avatar stephenmathieson avatar travisjeffery avatar yujidude avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

analytics-node's Issues

Upgrade to superagent 2.x

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).

add missing methods for analytics.methods in setup page

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 ?

[Intercom] - Integration is missing app_id key

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?

replace TravisCI with CircleCI

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?

remove global state

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.

is there an optional callback to `identify()` calls?

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);

Documentation outdated

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)
})
  • It wasn’t obvious at first that I needed an id (either anonymous or user) at first

Provide a test mode or a mock class

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.

add callbacks

analytics.track(ctx, function(err){
  // ...
})

instead of

analytics.track(ctx)
.on('error', function(err){
  // ...
})
.on('flush', function(){
  // ...
});

set local timestamps for uploads

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

How to get an anonymousId ?

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

Dependency on "brfs" packaged for browserify transform breaks with missing devDependencies

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.

No error returned when using with bad write-key

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.

pin your dependency versions

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 :)

ClamXav identifies analytics-node.js as infected

I just updated atom-beautify which uses analytics-node and analytics-node.js gets flagged by ClamXav to have MCL Exploit CVE 2015-6127.
fzsoh0q

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.

Implement 'flush' and possibly 'error' events for analytics instance

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.

Rename (or alias) "err" event to "error"

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!

conflict with superagent depend

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!

How to handle errors when messages are automatically flushed?

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)?

Allow userId to be an ObjectId

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?

Callback is called for each tracked event with the entire batch data

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

Ongoing changes for API v2

https://github.com/segmentio/spec

  • Use HTTP Basic Auth with the project's Write Key.
  • Rename to anonymousId from sessionId for clarity.
  • Separate integrations object from context, for cleaner logs.
  • Add requestId for easily tracing calls through to the raw logs.
  • Change library to be a object with name and version for consistency.

Uncaught Error while using latest version with chrome extension

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

mime 1.2.2 suddenly missing

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.

Tests fail

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.

Cannot npm install analytics-node

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

Flush isn't behaving according to the docs

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:

  1. A message arrives in queue, and the timer is set for 10 seconds
  2. 9 seconds pass, and another message arrives in queue. The timer is reset for another 10 seconds in the future, now 19 seconds since the last flush.
  3. 9 seconds pass, another event arrives, and the flush timer is reset again, now triggering at 28 seconds since the last flush.

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.

reset method

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.