electron-ga-uuid
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

electron-ga-uuid

Google Analytics client for Electron applications with some useful built in features.

Forked from electron-ga. Changed to use a locally stored unique id, which can be reset if requested to comply with Google Analytics requirements. Also despite the inherited name, no longer depends on electron.

Features

Easy to start using

First create a Web Property in Google Analytics and add a Mobile App View. The Mobile App View is better suited to display analytics from Electron, including application version.

electron-ga-uuid works in the renderer process.

import Analytics from 'electron-ga-uuid';

const analytics = new Analytics('UA-XXXXXXXX-X');

In electron, for app name and app version, either use dotenv with a .env file to set them or pass them in at the constructor:

const analytics = new Analytics('UA-XXXXXXXX-X', { appName: packageJson.name, appVersion: packageJson.version });

Then:

await analytics.send('screenview', { cd: 'User List' });
await analytics.send('event', { ec: 'Scroll', ea: 'scrollto', el: 'row', ev: 123 });

electron-ga-uuid uses Google Analytics Measurement Protocol. You can add custom parameters or override any of them.

API Reference

constructor(trackId[, initParams])

The trackId is a string and its format is: UA-XXXXXXXX-X.

The initParams is an object and its optional properties are:

  • protocolVersion
  • trackId
  • clientId
  • userId - undefined by default
  • appName
  • appVersion
  • language
  • userAgent
  • viewport
  • screenResolution

You can set any of them with a constant string value or a getter function, that returns a string value:

const analytics = new Analytics('UA-XXXXXXXX-X', {
  userId: '123456',
  language: () => store.getState().language
});

send(hitType[, additionalParams]) -> Promise

The hitType is a string. You can find here the available values.

The additionalParams is an object with any properties, which are acceptable by the Google Analytics Measurement Protocol.

resetClientId()

Reset the Client ID if the user requests

import { resetClientId } from 'electron-ga-uuid';
resetClientId();

License

MIT

Developed by

JayStack

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.3
    283
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.3
    283
  • 1.0.2
    6
  • 1.0.1
    1
  • 1.0.0
    0

Package Sidebar

Install

npm i electron-ga-uuid

Weekly Downloads

290

Version

1.0.3

License

MIT

Unpacked Size

17.5 kB

Total Files

13

Last publish

Collaborators

  • d7259