How to use the universal-analytics function in universal-analytics

To help you get started, we’ve selected a few universal-analytics 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 hymm / squid-tracks / src / analytics.js View on Github external
import ua from 'universal-analytics';
import uuid from 'uuid/v4';
const { ipcRenderer, remote } = require('electron');
const { app } = remote;
const appVersion = app.getVersion();
const appName = app.getName();
const log = require('electron-log');

const ua_ID = 'UA-104941988-1';
// get this from saved data or create if it doesn't exist and save it.
let userUuid = ipcRenderer.sendSync('getFromStore', 'uuid');
if (userUuid.length < 10) {
  userUuid = uuid();
  ipcRenderer.sendSync('setToStore', 'uuid', userUuid);
}
const visitor = ua(ua_ID, userUuid);

function errorHandler(err) {
  if (err) {
    log.error(`Error with google analytics: ${err}`);
  }
}

// support disabling analytics
export const screenview = screenName => {
  if (ipcRenderer.sendSync('getFromStore', 'gaEnabled')) {
    visitor.screenview(screenName, appName, appVersion, errorHandler).send();
  }
};

export const event = (...args) => {
  if (ipcRenderer.sendSync('getFromStore', 'gaEnabled')) {
github cgrossde / Pullover / src / app / services / Analytics.js View on Github external
import os from 'os'
import ua from 'universal-analytics'
import uuidv4 from 'uuid/v4'

import Settings from './Settings'
import packageInfo from '../../package.json'

// Init
let visitor
try {
  visitor = ua('UA-114351855-1', getClientId())
  visitor.set('anonymizeIp', 1)
  visitor.set('clientId', getClientId())
  visitor.set('dataSource', 'app')
  visitor.set('applicationName', 'Pullover')
  visitor.set('applicationVersion', packageInfo.version)
  visitor.set('applicationInstallerId', getPlatform())
  visitor.set('userAgentOverride', window.navigator.userAgent)

  if (window.firstRun) {
    visitor.event('App', 'Install')

  }
  if (window.updateRun) {
    event('App', 'Updated', packageInfo.version)
  }
} catch (e) {
github KELiON / cerebro / app / lib / trackEvent.js View on Github external
const visitor = () => {
  if (visitorCache) {
    return visitorCache
  }
  if (isTrackingEnabled()) {
    try {
      visitorCache = ua('UA-87361302-1', machineIdSync(), { strictCidFormat: false })
    } catch (err) {
      console.log('[machine-id error]', err)
      visitorCache = ua('UA-87361302-1')
    }
  }
  return visitorCache
}
github zeit / now / packages / now-cli / src / util / metrics.ts View on Github external
export const metrics = () => {
  const token = typeof config.token === 'string' ? config.token : platform() + release();
  const salt = userInfo().username;
  const hash = crypto.pbkdf2Sync(token, salt, 1000, 64, 'sha512').toString('hex').substring(0, 24);

  return ua(GA_TRACKING_ID, {
    cid: hash,
    strictCidFormat: false,
    uid: hash,
    headers: {
      'User-Agent': userAgent
    }
  });
}
github AlexRex / wokup / src / containers / App / App.js View on Github external
constructor() {
    super();
    this.state = {
      loading: true
    };

    const visitor = ua('UA-80488337-3');
    visitor.pageview('/').send();
  }
github Superjo149 / auryo / src / shared / utils / universalAnalytics.js View on Github external
export default getUA => {
    if (!a) {
        a = ua(CONFIG.GOOGLE_GA);
    }

    return a

}
github shoutem / cli / src / services / analytics.js View on Github external
async function getAnalyticsVisitor() {
  const clientId = await getClientId();

  const visitor = analytics(analyticsTrackingId, clientId);
  reportData.clientId = clientId;

  const { email } = await getValue('developer') || {};
  if (email) {
    visitor.set('userId', email);
    reportData.userId = email;
  }
  visitor.set('isDeveloper', true);
  reportData.isDeveloper = true;

  return visitor;
}
github rafaell-lycan / sabesp-mananciais-api / src / common / middleware / analytics.ts View on Github external
public use(req: Request, res: Response, next: NextFunction) {
    const { headers, path } = req;
    logger.info(`Analytics pageview on ${path}`);
    if (env.ANALYTICS) {
      const visitor: Visitor = ua(env.ANALYTICS);
      const options: PageviewParams = {
        dp: path,
        dh: headers.host,
        uip: headers['x-forwarded-for'] || headers['x-real-ip'],
        ua: headers['user-agent'],
      };

      logger.info(`Analytics pageview on ${path}`);
      visitor.pageview(options).send(() => next());
    }

    next();
  }
}
github iopipe / serverless-plugin-iopipe / src / util / track.js View on Github external
try {
      pkg = fs.readJsonSync(join(pluginInstance.prefix, 'package.json'));
    } catch (err) {
      _.noop();
    }
  }
  const str =
    pkg.author ||
    _.get(pkg, 'repository.url') ||
    pkg.name ||
    pkg.homepage ||
    uuid.v4();
  const userId = createHash('md5')
    .update(str)
    .digest('hex');
  const visitor = ua('UA-73165042-2', userId, {
    strictCidFormat: false,
    https: true
  });
  return visitor;
}

universal-analytics

A node module for Google's Universal Analytics tracking

MIT
Latest version published 2 years ago

Package Health Score

68 / 100
Full package analysis