Skip to content

Commit

Permalink
Add functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Andréas Hanss committed Nov 15, 2016
1 parent 2176b1b commit f36f4d8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
35 changes: 20 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 21,22 @@ Dispatch events and track views from Vue components.

# Configuration

`npm install vue-ua`
`npm install vue-ua -S` or `yarn add vua-ua` if you use [Yarn package manager](https://yarnpkg.com/)

And then just do the following, the configuration of dimensions is optional.
Here is an example of configuration, compose with it on your own :

```javascript
import VueAnalytics from 'vue-ua'
import VueRouter from 'vue-router'
const router = new VueRouter({routes, mode, linkActiveClass})

Vue.use(VueAnalytics, {
appName: '<app_name>',
appVersion: '<app_version>',
trackingId: '<your_tracking_id>',
debug: true, // Wheter or not display console logs
debug: true, // Whether or not display console logs (optional)
vueRouter: router, // Pass the router instance to automatically sync with router (optional)
ignoredViews: ['homepage'], // If router, you can exclude some routes name
globalDimensions: [
{dimension: 1, value: 'MyDimensionValue'},
{dimension: 2, value: 'AnotherDimensionValue'}
Expand Down Expand Up @@ -66,18 71,6 @@ You can also access the instance everywhere using `window.vueAnalytics`, it's us

## API reference

### injectGlobalDimension (dimensionNumber, value)
```javascript
/**
* Inject a new GlobalDimension that will be sent every time.
*
* Prefer inject through plugin configuration.
*
* @param {int} dimensionNumber
* @param {string|int} value
*/
```

### trackEvent (category, action = null, label = null, value = null, fieldsObject = {})
```javascript
/**
Expand All @@ -100,3 93,15 @@ You can also access the instance everywhere using `window.vueAnalytics`, it's us
* @param screenName
*/
```

### injectGlobalDimension (dimensionNumber, value)
```javascript
/**
* Inject a new GlobalDimension that will be sent every time.
*
* Prefer inject through plugin configuration.
*
* @param {int} dimensionNumber
* @param {string|int} value
*/
```
5 changes: 5 additions & 0 deletions analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 68,10 @@ AnalyticsPlugin.install = function (Vue, conf) {
throw new Error('VueAnalytics : Please provide a "appName" from the config')
}

if (!conf.appVersion) {
throw new Error('VueAnalytics : Please provide a "appVersion" from the config')
}

// Declare analytics snipper
(function (i, s, o, g, r, a, m) {
i[ 'GoogleAnalyticsObject' ] = r;
Expand All @@ -84,6 88,7 @@ AnalyticsPlugin.install = function (Vue, conf) {
// Register tracker
ga('create', conf.trackingId, 'auto')
ga('set', 'appName', conf.appName)
ga('set', 'appVersion', conf.appVersion)

// Create global dimensions
if (conf.globalDimensions) {
Expand Down
2 changes: 1 addition & 1 deletion vue-analytics.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f36f4d8

Please sign in to comment.