meteornpmsegment-io

Segment.io NPM Package not working with Meteor


I am using the npm package for segment server side with Meteor

In my packages.json folder I have

"segmentio": "0.1.4"


if Meteor.isServer
  Meteor.startup ->
    @analytics = Meteor.npmRequire('segmentio')
    analytics.init(Meteor.settings.segmentio)

    analytics.track
      event: 'hello'
      userId: '2'

That the code I am using to track an event with segment server side. But the event is not showing up in the debugger. Any advice? What am I doing wrong?

I know I am using the correct Meteor.settings.segmentio key because I am using the same key on the client and those events are tracked just fine. But on the server, the 'hello' event I posted above will not track. No errors are thrown when the code above runs.


Solution

  • I had the code setup slightly wrong.

    Scoping issue. Here is the working code:

    @analytics = null
    
    if Meteor.isServer
      Meteor.startup ->
        analytics = Meteor.npmRequire('segmentio')
        analytics.init(Meteor.settings.segmentio)
    
        analytics.track
          event: 'hello'
          userId: '2'