nate-strauser/meteor-analyticsjs

Expose api to server use, so we can trigger events from server side

Closed this issue · 2 comments

Hi there,
I am having a use case scenario where I want to tell my analytics engines (mixpanel, GA) with a "Sign Up" event after a user has signed up.

I tried to do this via the Accounts.onCreateUser hook in meteor but that is only available on the server.

So that means I cannot send an event "Sign Up" since this package does not support server use.

analyticsjs is only for client side usage - to record server side metrics you need to use the 'analytics-node' npm package - i'm using the 'npm' package with a packages.json file like

{
  "analytics-node":"0.6.0"
}

then this code in server/lib/environment.js

analytics = Meteor.require('analytics-node');
analytics.init({secret: Meteor.settings.public.analytics_api_key});

the server side uses the same api key as the client side


so technically this isnt an issue/problem with this package, you just have to use 2 seperate components because of how segment.io splits up the access to their api

see:
https://segment.io/docs/tutorials/quickstart-analytics.js/ (client side)
https://segment.io/docs/tutorials/quickstart-node/ (server side)

alright it works thank you.

right now the node api is at v1.0.0

I initialize in this manner:

var Analytics  = Meteor.require('analytics-node');
var apiKey = Meteor.settings && Meteor.settings.public ? Meteor.settings.public.analytics_api_key : 'nokey';
analytics = new Analytics(apiKey);