https://github.com/startpolymer/start-google-analytics-tracker
https://github.com/startpolymer/start-google-analytics-tracker
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/startpolymer/start-google-analytics-tracker
- Owner: StartPolymer
- License: mit
- Created: 2015-08-27T12:46:49.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2016-06-15T05:09:22.000Z (about 10 years ago)
- Last Synced: 2025-03-16T23:07:04.260Z (over 1 year ago)
- Language: HTML
- Size: 125 KB
- Stars: 5
- Watchers: 1
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# start-google-analytics-tracker
`start-google-analytics-tracker` is a Polymer Element for [Google Analytics Web Tracking](https://developers.google.com/analytics/devguides/collection/analyticsjs/), supports page and event tracking.
Script analytics.js is served from local `scripts` dir, because https://www.google-analytics.com/analytics.js have only 2 hours cache.
You need download latest analytics.js file.
```sh
wget https://www.google-analytics.com/analytics.js -O scripts/analytics.js
```
Inspired by this repo https://github.com/matthewlawson/google-analytics-universal-tracker
## Getting Started
### Installation
```sh
bower install start-google-analytics-tracker --save
```
### Usage
#### Initialise
```html
```
If you are using regular anchor links and not push-state links you are ready to go!
If you have a Single Page Application that uses push-state, eg with `page.js` or `` you will need to signal to the `start-google-analytics-tracker` element that the page has changed.
The Page Change events are handled using iron-signals so you do not need to do any dom finding to trigger a page track.
#### Track a page Change
```javascript
this.fire('iron-signal', {name: 'track-page', data: { path: "/about.html" } });
```
#### Track an Event
```javascript
this.fire('iron-signal', {name: 'track-event',data: {category: "messages",action: "send_text_message",label: "group",value: 1}});
```
#### User id attribution
To use [Google Analytics user id attribution](https://developers.google.com/analytics/devguides/collection/analyticsjs/user-id) set the user id property on the element:
```javascript
document.querySelector("start-google-analytics-tracker").userId = loggedInUserId;
```