https://github.com/justinribeiro/ga-dnt-analytics
Basic Google Analytics web component with Do Not Track support.
https://github.com/justinribeiro/ga-dnt-analytics
donottrack google-analytics polymer-element polymer2 webcomponent
Last synced: 5 months ago
JSON representation
Basic Google Analytics web component with Do Not Track support.
- Host: GitHub
- URL: https://github.com/justinribeiro/ga-dnt-analytics
- Owner: justinribeiro
- License: mit
- Archived: true
- Created: 2017-01-16T23:00:01.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-07T22:37:26.000Z (almost 9 years ago)
- Last Synced: 2025-04-15T19:18:23.079Z (about 1 year ago)
- Topics: donottrack, google-analytics, polymer-element, polymer2, webcomponent
- Language: HTML
- Homepage: https://www.webcomponents.org/element/justinribeiro/ga-dnt-analytics
- Size: 2.48 MB
- Stars: 8
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# \
Basic Google Analytics web component with Do Not Track support. [](https://www.webcomponents.org/element/justinribeiro/ga-dnt-analytics)
```html
ga-dnt-analytics - Open DevTools and check console.
```

## Installation
Install the component using Bower:
```shell
bower i justinribeiro/ga-dnt-analytics --save
```
## Usage
1. Import Web Components' polyfill, if needed:
```html
```
2. Import ga-dnt-analytics:
```html
```
3. Start using it!
```html
```
## Attributes/Properties
Attribute | Options | Default | Description
--- | --- | --- | ---
`key` | *String* | "" | (_optional_) Sets UA for Google Analytics tracking
`debug` | *Boolean* | `false` | (_optional_) Enables Google Analytics debugging mode
`trace` | *Boolean* | `false` | (_optional_) Use with debug; enables full tracing for GA
`donottrack` | *Boolean* | `true` | (_optional_) Check and use Do Not Track browser flag
`pageview` | *Boolean* | `false` | (_optional_) Send `ga('send', 'pageview')` ping on element stamp
## Methods
If not using the `pageview` property to send a ping to GA, you can use the `send()` method to send a payload to GA.
```javascript
// via Polymer 2.x
this.shadowRoot.querySelector('ga-dnt-analytics').send({
hitType: 'pageview',
page: window.location.pathname,
location: window.location.href,
title: 'My Title'
});
// via Polymer 1.x
this.$$('ga-dnt-analytics').send({
hitType: 'pageview',
page: window.location.pathname,
location: window.location.href,
title: 'My Title'
});
// via JavaScript
document.querySelector('ga-dnt-analytics').send({
hitType: 'pageview',
page: window.location.pathname,
location: window.location.href,
title: 'My Title'
});
```
For list of payloads and string/objects to send, see [See https://developers.google.com/analytics/devguides/collection/analyticsjs/sending-hits](https://developers.google.com/analytics/devguides/collection/analyticsjs/sending-hits).
## Contributing
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D
## Credits
[Justin Ribeiro](https://github.com/justinribeiro)
[Schalk Neethling](https://github.com/schalkneethling)
[Google Analytics](https://developers.google.com/analytics/)
## License
MIT License (MIT)