ember-metrics
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -7,2 +7,4 @@ import Ember from 'ember'; | ||
const { | ||
isPresent, | ||
copy, | ||
assert, | ||
@@ -22,3 +24,3 @@ merge, | ||
init() { | ||
const config = get(this, 'config'); | ||
const config = copy(get(this, 'config')); | ||
const { id } = config; | ||
@@ -28,2 +30,6 @@ | ||
delete config.id; | ||
const hasOptions = isPresent(Object.keys(config)); | ||
if (canUseDOM) { | ||
@@ -35,7 +41,19 @@ /* jshint ignore:start */ | ||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); | ||
window.ga('create', id, 'auto'); | ||
/* jshint ignore:end */ | ||
if (hasOptions) { | ||
window.ga('create', id, config); | ||
} else { | ||
window.ga('create', id, 'auto'); | ||
} | ||
} | ||
}, | ||
identify(options = {}) { | ||
const compactedOptions = compact(options); | ||
const { distinctId } = compactedOptions; | ||
window.ga('set', 'userId', distinctId); | ||
}, | ||
trackEvent(options = {}) { | ||
@@ -42,0 +60,0 @@ const compactedOptions = compact(options); |
import config from '../config/environment'; | ||
export function initialize(_container, application ) { | ||
const { metricsAdapters } = config; | ||
const { metricsAdapters = {} } = config; | ||
@@ -6,0 +6,0 @@ application.register('config:metrics', metricsAdapters, { instantiate: false }); |
{ | ||
"name": "ember-metrics", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Send data to multiple analytics integrations without re-implementing new API", | ||
@@ -5,0 +5,0 @@ "directories": { |
147
README.md
@@ -12,2 +12,21 @@ # ember-metrics | ||
#### Currently supported services and options | ||
1. `GoogleAnalytics` | ||
- `id`: [Property ID](https://support.google.com/analytics/answer/1032385?hl=en), e.g. `UA-XXXX-Y` | ||
2. `Mixpanel` | ||
- `token`: [Mixpanel token](https://mixpanel.com/help/questions/articles/where-can-i-find-my-project-token) | ||
3. `GoogleTagManager` | ||
- `id`: [Container ID](https://developers.google.com/tag-manager/quickstart), e.g. `GTM-XXXX` | ||
- `dataLayer`: An array containing a single POJO of information, e.g.: | ||
```js | ||
dataLayer = [{ | ||
'pageCategory': 'signup', | ||
'visitorType': 'high-value' | ||
}]; | ||
``` | ||
4. `KISSMetrics` (WIP) | ||
5. `CrazyEgg` (WIP) | ||
## Installing The Addon | ||
@@ -27,2 +46,61 @@ | ||
## Configuration | ||
To setup, you should first configure the service through `config/environment`: | ||
```javascript | ||
module.exports = function(environment) { | ||
var ENV = { | ||
metricsAdapters: [ | ||
{ | ||
name: 'GoogleAnalytics', | ||
config: { | ||
id: 'UA-XXXX-Y' | ||
} | ||
}, | ||
{ | ||
name: 'Mixpanel', | ||
config: { | ||
token: '0f76c037-4d76-4fce-8a0f-a9a8f89d1453' | ||
} | ||
}, | ||
{ | ||
name: 'LocalAdapter', | ||
config: { | ||
foo: 'bar' | ||
} | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
Adapter names are PascalCased. Refer to the [list of supported adapters](#currently-supported-services-and-options) above for more information. | ||
The `metricsAdapters` option in `ENV` accepts an array of objects containing settings for each analytics service you want to use in your app in the following format: | ||
```js | ||
/** | ||
* @param {String} name Adapter name | ||
* @param {Object} config Configuration options for the service | ||
*/ | ||
{ | ||
name: 'Analytics', | ||
config: {} | ||
} | ||
``` | ||
Values in the `config` portion of the object are dependent on the adapter. If you're writing your own adapter, you will be able to retrieve the options passed into it: | ||
```js | ||
// Example adapter | ||
export default BaseAdapter.extend({ | ||
init() { | ||
const { apiKey, options } = Ember.get(this, 'config'); | ||
this.setupService(apiKey); | ||
this.setOptions(options); | ||
} | ||
}); | ||
``` | ||
## Usage | ||
@@ -39,3 +117,3 @@ | ||
location: config.locationType, | ||
metrics: inject.service(), | ||
metrics: Ember.inject.service(), | ||
@@ -115,47 +193,2 @@ didTransition() { | ||
## Configuration | ||
To setup, you should first configure the service through `config/environment`: | ||
```javascript | ||
module.exports = function(environment) { | ||
var ENV = { | ||
metricsAdapters: [ | ||
{ | ||
name: 'GoogleAnalytics', | ||
config: { | ||
id: 'UA-XXXX-Y' | ||
} | ||
}, | ||
{ | ||
name: 'Mixpanel', | ||
config: { | ||
token: '0f76c037-4d76-4fce-8a0f-a9a8f89d1453' | ||
} | ||
}, | ||
{ | ||
name: 'LocalAdapter', | ||
config: { | ||
foo: 'bar' | ||
} | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
The `metricsAdapters` option in `ENV` accepts an array of objects containing settings for each analytics service you want to use in your app in the following format: | ||
```js | ||
{ | ||
name: 'Analytics', | ||
config: { | ||
anyKey: 'someValue', | ||
apiKey: 'eb4bb7f1' | ||
} | ||
} | ||
``` | ||
Values in the `config` portion of the object are dependent on the adapter. | ||
### Lazy Initialization | ||
@@ -210,2 +243,24 @@ | ||
### Usage | ||
Once you have implemented your adapter, you can add it to your [app's config](#configuration), like so: | ||
```js | ||
module.exports = function(environment) { | ||
var ENV = { | ||
metricsAdapters: [ | ||
{ | ||
name: 'MyAdapter', | ||
config: { | ||
secret: '29fJs90qnfEa', | ||
options: { | ||
foo: 'bar' | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
## Testing | ||
@@ -212,0 +267,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27674
523
296