electron-ga-uuid
v1.0.3
Published
Google Analytics client for Electron applications
Downloads
341
Readme
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
- Unique Client ID for every install
- Cache for offline usage
- Promise-based API
- It sends the following params by default:
- Protocol Version
- Client ID: stores a unique id to track the same client each time they use the app.
- Application Name
- Application Version
- User Language: determined by user agent
- User Agent: prepared to make interpretable for Analytics to parse the Platform info
- Screen Resolution
- Viewport Size
- Mechanism to reset the Client Id if the user requests
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();