https://github.com/pirxpilot/google-ua
Google Universal Analytics snippet
https://github.com/pirxpilot/google-ua
Last synced: about 1 year ago
JSON representation
Google Universal Analytics snippet
- Host: GitHub
- URL: https://github.com/pirxpilot/google-ua
- Owner: pirxpilot
- License: mit
- Created: 2013-12-11T00:27:40.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2017-12-18T03:18:02.000Z (over 8 years ago)
- Last Synced: 2025-06-26T10:04:04.483Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
- License: License.txt
Awesome Lists containing this project
README
[](https://www.npmjs.com/package/google-ua)
[](https://www.npmjs.com/package/google-ua)
# google-ua
[Google Universal Analytics][gua] tracking snippet
## Installation
$ npm install -S google-ua
## API
Activate Google Analytics on the page and track page
```javascript
require('google-ua')("UA-XXXX-X");
```
Alternatively you can define ua property ID as a data attribute of document body
```html
```
Check [test/index.html](https://github.com/pirxpilot/google-ua/blob/master/test/index.html) for example.
Optional `fields` parameter lets you set [general tracker fields][fields] before the `pageview` event is sent.
```javascript
require('google-ua')("UA-XXXX-X", {
anonymizeIP: true,
forceSSL: true,
userId: 'as8eknlll'
});
// set fields, retrieve property ID from data attribute of document body
require('google-ua')({
anonymizeIP: true,
forceSSL: true,
userId: 'as8eknlll'
});
```
You can prevent snippet from sending `pageview` event automatically by setting the first parameter to false
```javascript
// initilize tracker, do not send `pageview` event
require('google-ua')(false, "UA-XXXX-X")
// initialize tracker, do not send `pageview` event, retrieve property ID from data attribute of document body
require('google-ua')(false);
```
## License
MIT
[gua]: https://support.google.com/analytics/answer/2790010?hl=en
[fields]: https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#general