https://github.com/jaystack/electron-ga
Google Analytics client for Electron applications
https://github.com/jaystack/electron-ga
Last synced: 4 months ago
JSON representation
Google Analytics client for Electron applications
- Host: GitHub
- URL: https://github.com/jaystack/electron-ga
- Owner: jaystack
- License: mit
- Created: 2017-12-13T14:02:56.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-09-03T09:52:06.000Z (almost 5 years ago)
- Last Synced: 2025-02-01T14:13:42.934Z (4 months ago)
- Language: TypeScript
- Size: 114 KB
- Stars: 36
- Watchers: 10
- Forks: 17
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# electron-ga
[Google Analytics](https://developers.google.com/analytics/devguides/collection/protocol/v1/) client for [Electron](https://electronjs.org/) applications with some useful builtin features## Features
- **Unique [Client ID](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cid) for every machine**, where your app has been installed
- Cache for **offline usage**
- **Promise-based** API
- It sends the following **params by default**:
- [Protocol Version](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#v)
- [Client ID](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cid): unique for every machine
- [Application Name](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#an)
- [Application Version](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#av)
- [User Language](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ul): determined by user agent
- [User Agent](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ul): prepared to make interpretable for Analytics to parse the Platform info
- [Screen Resolution](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#sr)
- [Viewport Size](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#vp)## Easy to start using
First create a [Google Analytics Mobile Account](https://developers.google.com/analytics/solutions/mobile). It is needed, because webpage account does not track many parameters, like version. In many aspect an [Electron](https://electronjs.org/) application is more similar to a mobile application than a simple webpage.
[electron-ga]() works only in the [renderer process](https://electronjs.org/docs/tutorial/quick-start#renderer-process).
```js
import Analytics from 'electron-ga';const analytics = new Analytics('UA-XXXXXXXX-X');
```Then:
```js
await analytics.send('screenview', { cd: 'User List' });
await analytics.send('event', { ec: 'Scroll', ea: 'scrollto', el: 'row', ev: 123 });
```[electron-ga]() uses [Google Analytics Measurement Protocol](https://developers.google.com/analytics/devguides/collection/protocol/v1/). You can add custom [parameters](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters) or ovveride 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:
```js
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](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#t).
The `additionalParams` is an object with any properties, which are acceptable by the [Google Analytics Measurement Protocol](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters).
---
## License
[MIT](https://spdx.org/licenses/MIT)
## Developed by
[](http://jaystack.com/)