Skip to content

Commit b01aa65

Browse files
authored
EOTY 2016 Refactoring for release 1.2 (#10)
1 parent 52a8a58 commit b01aa65

File tree

11 files changed

+293
-182
lines changed

11 files changed

+293
-182
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## 1.2 - December 2016
2+
3+
- Refactored code organisation in separated modules for simplicity.
4+
- Support for changing language during app navigation, useful in case of i18n apps.
5+
- Support for metrics
6+
- Support for exceptions
7+

README.md

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
</p>
1212
<br>
1313

14-
Dispatch events and track views from Vue components.
14+
This plugin will helps you in your common analytics tasks. Dispatching events, register some dimensions, metric and track views from Vue components.
1515

16-
<img src="http://occhiobiancogiuseppe.it/wp-content/uploads/2015/09/work_in_progress.png" height=130>
16+
# Requirements
1717

18-
This is a work in progress, this is stable for production but breaking changes may be introduced through minor revisions, but never in patch version.
18+
- **Vue.js.** >= 2.0.0
19+
- **Google Analytics account.** To send data to
1920

20-
# Requirements
21+
**Optionnals dependencies**
2122

22-
- **Vue.js.** > 2.0.0
23-
- **Google Analytics account.** To retrieve Data
23+
- **Vue Router** >= 2.x - In order to use auto-tracking of screens
2424

2525

2626
# Configuration
@@ -35,22 +35,26 @@ import VueRouter from 'vue-router'
3535
const router = new VueRouter({routes, mode, linkActiveClass})
3636

3737
Vue.use(VueAnalytics, {
38-
appName: '<app_name>',
39-
appVersion: '<app_version>',
40-
trackingId: '<your_tracking_id>',
41-
debug: true, // Whether or not display console logs (optional)
38+
appName: '<app_name>', // Mandatory
39+
appVersion: '<app_version>', // Mandatory
40+
trackingId: '<your_tracking_id>', // Mandatory
41+
debug: true, // Whether or not display console logs debugs (optional)
4242
vueRouter: router, // Pass the router instance to automatically sync with router (optional)
43-
ignoredViews: ['homepage'], // If router, you can exclude some routes name (case insensitive)
44-
globalDimensions: [
43+
ignoredViews: ['homepage'], // If router, you can exclude some routes name (case insensitive) (optional)
44+
globalDimensions: [ // Optional
4545
{dimension: 1, value: 'MyDimensionValue'},
4646
{dimension: 2, value: 'AnotherDimensionValue'}
47-
]
47+
],
48+
globalMetrics: [ // Optional
49+
{metric: 1, value: 'MyMetricValue'},
50+
{metric: 2, value: 'AnotherMetricValue'}
51+
]
4852
})
4953
```
5054

5155
# Documentation
5256

53-
Once registered you can access vue analytics in your components like this :
57+
Once the configuration is completed, you can access vue analytics instance in your components like that :
5458

5559
```javascript
5660
export default {
@@ -73,17 +77,35 @@ export default {
7377
}
7478
```
7579

76-
You can also access the instance everywhere using `Vue.analytics`, it's useful when you are in the store or somewhere else than components.
80+
You can also access the instance anywhere whenever you imported `Vue` by using `Vue.analytics`. It is especially useful when you are in a store module or
81+
somewhere else than a component's scope.
82+
83+
## Sync analytics with your router
84+
85+
Thanks to vue-router guards, you can automatically dispatch new screen views on router change !
86+
To use this feature, you just need to inject the router instance on plugin initialization.
7787

78-
## Using vue-router guards
88+
This feature will generate the view name according to a priority rule :
89+
- If you defined a meta field for you route named `analytics` this will take the value of this field for the view name.
90+
- Otherwise, if the plugin don't have a value for the `meta.analytics` it will fallback to the internal route name.
7991

80-
You can automatically dispatch new screen views on router change, to do this simply pass the router instance on plugin initialization.
81-
At the moment, this is using the `route name` to name the HIT, but this is going to be updated to allow you to specify whatever values you wants.
92+
Most of time the second case is enough, but sometimes you want to have more control on what is sent, this is where the first rule shine.
8293

94+
Example :
95+
```javascript
96+
const myRoute = {
97+
path: 'myRoute',
98+
name: 'MyRouteName',
99+
component: SomeComponent,
100+
meta: {analytics: 'MyCustomValue'}
101+
}
102+
```
103+
104+
> This will use `MyCustomValue` as the view name.
83105
84106
## API reference
85107

86-
### trackEvent (category, action = null, label = null, value = null, fieldsObject = {})
108+
### trackEvent (category, action = null, label = null, value = null)
87109
```javascript
88110
/**
89111
* Dispatch an analytics event.
@@ -93,7 +115,6 @@ At the moment, this is using the `route name` to name the HIT, but this is going
93115
* @param action
94116
* @param label
95117
* @param value
96-
* @param fieldsObject
97118
*/
98119
```
99120

@@ -115,6 +136,22 @@ At the moment, this is using the `route name` to name the HIT, but this is going
115136
*
116137
* @param {int} dimensionNumber
117138
* @param {string|int} value
139+
*
140+
* @throws Error - If already defined
141+
*/
142+
```
143+
144+
### injectGlobalMetric (metricNumber, value)
145+
```javascript
146+
/**
147+
* Inject a new GlobalMetric that will be sent every time.
148+
*
149+
* Prefer inject through plugin configuration.
150+
*
151+
* @param {int} metricNumber
152+
* @param {string|int} value
153+
*
154+
* @throws Error - If already defined
118155
*/
119156
```
120157

@@ -127,3 +164,12 @@ At the moment, this is using the `route name` to name the HIT, but this is going
127164
* @param {boolean} isFatal - Specifies whether the exception was fatal
128165
*/
129166
```
167+
168+
### changeSessionLanguage (code)
169+
```javascript
170+
/**
171+
* Set the current session language, use this if you change lang in the application after initialization.
172+
*
173+
* @param {string} code - Must be like in that : http://www.lingoes.net/en/translator/langcode.htm
174+
*/
175+
```

analytics.js

Lines changed: 0 additions & 156 deletions
This file was deleted.

dist/vue-analytics.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "vue-ua",
3-
"version": "1.1.2",
3+
"version": "1.2.0",
44
"description": "Help for Google Universal Analytics in Vue application",
5-
"main": "./vue-analytics.min.js",
5+
"main": "./dist/vue-analytics.min.js",
66
"author": "Andréas \"ScreamZ\" Hanss",
77
"license": "Apache-2.0",
88
"homepage": "https://github.com/ScreamZ/vue-analytics",

0 commit comments

Comments
 (0)