How to use analytics-node - 10 common examples

To help you get started, we’ve selected a few analytics-node examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Syncano / syncano-node / packages / cli / src / utils / analytics.js View on Github external
/* eslint no-underscore-dangle: "warn" */
import _ from 'lodash'
import Analytics from 'analytics-node'
import Command from 'commander'

import pjson from '../../package.json'
import logger from './debug'
import session from './session'

const { debug } = logger('utils-analytics')

const STG_KEY = 'CCupheBjgV6WI0emy3oRUnDyjQ8ngmgB'
const PROD_KEY = 'fLDtpYXRjFYnHlp1gvzl4I3Gv8gDoQ8m'

const ANALYTICS_WRITE_KEY = process.env.SYNCANO_ENV === 'test' ? STG_KEY : PROD_KEY
const analytics = new Analytics(ANALYTICS_WRITE_KEY, {
  flushAt: 5,
  flushAfter: 300
})

const identify = (details) => {
  debug('identify')
  analytics.identify({
    userId: details.id,
    traits: {
      'First name': details.first_name,
      'Last name': details.last_name,
      source: 'Sign up',
      email: details.email,
      is_active: details.is_active
    }
  })
github segmentio / typewriter / src / cli / index.tsx View on Github external
.version(false).argv

interface DebugContextProps {
	/** Whether or not debug mode is enabled. */
	debug: boolean
}
export const DebugContext = createContext({ debug: false })

// Initialize analytics-node
const writeKey =
	process.env.NODE_ENV === 'production'
		? // Production: https://app.segment.com/segment_prod/sources/typewriter/overview
		  'ahPefUgNCh3w1BdkWX68vOpVgR2Blm5e'
		: // Development: https://app.segment.com/segment_prod/sources/typewriter_dev/overview
		  'NwUMoJltCrmiW5gQZyiyvKpESDcwsj1r'
const analyticsNode = new Analytics(writeKey, {
	flushAt: 1,
	flushInterval: -1,
})

// Initialize the typewriter client that this CLI uses.
typewriter.setTypewriterOptions({
	analytics: analyticsNode,
})

function toYargsHandler<p>(
	Command: React.FC,
	props: P,
	cliOptions?: { validateDefault?: boolean }
) {
	// Return a closure which yargs will execute if this command is run.
	return async (args: CLIArguments) =&gt; {</p>
github expo / expo-cli / packages / xdl / src / Analytics.ts View on Github external
export function setSegmentNodeKey(key: string) {
  // Do not wait before flushing, we want node to close immediately if the programs ends
  _segmentNodeInstance = new Segment(key, { flushInterval: 300 });
}
github cockroachdb / cockroach-gen / pkg / ui / src / redux / analytics.ts View on Github external
path = path.replace(r.match, r.replace as string);
        }
        return false;
      }
    });
    return path;
  }
}

// Create a global instance of AnalyticsSync which can be used from various
// packages. If enabled, this instance will push to segment using the following
// analytics key.
const analyticsOpts = {
  host: COCKROACHLABS_ADDR + "/api/segment",
};
const analyticsInstance = new Analytics(
  "5Vbp8WMYDmZTfCwE0uiUqEdAcTiZWFDb",
  analyticsOpts,
);
export const analytics = new AnalyticsSync(
  analyticsInstance,
  store,
  defaultRedactions,
);

// Attach a listener to the history object which will track a 'page' event
// whenever the user navigates to a new path.
let lastPageLocation: Location;
history.listen((location: Location) => {
  // Do not log if the pathname is the same as the previous.
  // Needed because history.listen() fires twice when using hash history, this
  // bug is "won't fix" in the version of history we are using, and upgrading
github cockroachdb / cockroach-gen / pkg / ui / src / redux / customAnalytics / customAnalyticsSagas.spec.ts View on Github external
it("calls analytics#identify with user email in args ", () => {
      const analyticsIdentifyFn = sandbox.stub(Analytics.prototype, "identify");
      const clusterId = "cluster-1";
      const email = "foo@bar.com";
      const action = signUpForEmailSubscription(clusterId, email);

      return expectSaga(signUpEmailSubscription, action)
        .dispatch(action)
        .run()
        .then(() => {
          const expectedAnalyticsMessage = {
            userId: clusterId,
            traits: {
              email,
            },
          };
          analyticsIdentifyFn.calledOnceWith(expectedAnalyticsMessage);
        });
github nars-dev / nars / packages / nars / src / NarsServer.ts View on Github external
export const startListening = (
  server: Server,
  render: (component: Schema.IRender) => JSX.Element
) => {
  /**
   * Feel free to remove analytics. nars doesn't depend
   * on analytic information at all. They are only collected
   * to understand how/if developers use it.
   */
  const analytics = new Analytics("RsD4jSdhauL5xheR1WDxcXApnCGh8Kts");
  let id;
  try {
    id = { anonymousId: getMachineUDID.machineIdSync() };
    analytics.identify({
      ...id,
      traits: {
        idStable: "true"
      }
    });
  } catch (e) {
    id = { anonymousId: uuid() };
    analytics.identify({
      ...id,
      traits: {
        idStable: "false"
      }
github Blockrazor / blockrazor / imports / api / analytics.js View on Github external
import { Mongo } from 'meteor/mongo';
import Analytics from 'analytics-node'
var analytics = new Analytics('auAfRv1y0adOiVyz1TZB9nl18LI9UT98');

//function to send user events to segment, a payload is required to send to segment per the below analytics.track function
export var segmentEvent = function(payload) {
    if (payload) {
        analytics.track({
            userId: Meteor.userId(),
            event: payload.event,
            properties: payload.properties
        });
    } else {
        throw new Meteor.Error('No event payload has been provided')
    }
};
github replicatedhq / kots / kotsadm / api / src / util / analytics.ts View on Github external
export function getAnalytics(params: Params){
  return new Analytics(params.segmentioAnalyticsKey);
};
github cockroachdb / cockroach-gen / pkg / ui / src / redux / customAnalytics / customAnalyticsSagas.ts View on Github external
export function getAnalyticsClientFor(
  target: AnalyticsClientTarget,
): Analytics {
  switch (target) {
    case "email_sign_up":
      return new Analytics(EMAIL_SIGN_UP_CLIENT_KEY, analyticsOpts);
    default:
      throw new Error("Unrecognized Analytics Client target.");
  }
}
github smspillaz / intuitive-math / server / serverAnalytics.js View on Github external
constructor() {
    this.analytics = new Analytics(SEGMENT_CLIENT_ID);
  }
  pageView(category, name, props, options) {

analytics-node

The hassle-free way to integrate analytics into any Node.js application

MIT
Latest version published 2 years ago

Package Health Score

50 / 100
Full package analysis

Popular analytics-node functions