Skip to content

Commit

Permalink
Merge pull request #1 from MatthewCallis/ES6
Browse files Browse the repository at this point in the history
v2.0: ES6
  • Loading branch information
MatthewCallis committed Dec 6, 2016
2 parents 6e79bda + b902bf7 commit bc9b8c4
Show file tree
Hide file tree
Showing 30 changed files with 1,563 additions and 2,251 deletions.
9 changes: 9 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"presets": [
["es2015"],
],
"plugins": [
"babel-plugin-espower",
"transform-object-rest-spread"
]
}
30 changes: 30 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"extends": "airbnb",
"plugins": [
"ava",
"no-inferred-method-name",
"xss",
],
"env": {
"es6": true,
"browser": true,
},
"globals": {
"sinon": false,
"expect": true,
},
# Custom Disabled Rules
rules: {
camelcase: 0,
max-len: 0,
no-param-reassign: 0,
no-unused-vars: ["error", { "varsIgnorePattern": "^(_|Apptentive)", "argsIgnorePattern": "^_", "caughtErrors": "none" }],
no-plusplus: 0, # Meaningless as other rules prevent the errors that could happens.
# Rules dependent on external APIs that would otherwise break rules or be needlessly complex:
no-underscore-dangle: 0,
no-restricted-syntax: 0,
no-empty: ["error", { "allowEmptyCatch": true }],
"import/no-extraneous-dependencies": 0,
"class-methods-use-this": 0 # Breaks Ava testing when using static method due to transpiled code.
}
}
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.DS_Store
node_modules/
.coveralls.yml
.DS_Store
.nyc_output/
build-coverage/
coverage/
lib-cov
build-coverage/
node_modules/
npm-debug.log
12 changes: 9 additions & 3 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
support
.coveralls.yml
.DS_Store
.nyc_output/
assets
assets_source
tmp
.DS_Store
build-coverage/
config.json
coverage/
lib-cov
node_modules/
npm-debug.log
support
tmp
21 changes: 9 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
language: node_js
node_js:
- "stable"
cache:
directories:
- node_modules
env:
- CODECLIMATE_REPO_TOKEN=9ffe8abc7638fd859bf081174225ff9846ee5a476c8793bd4e8cc3ec90dae358
before_install:
- npm conf set strict-ssl false
after_install:
- sudo npm install -g phantomjs
before_script:
- phantomjs --version
- npm install -g mocha-phantomjs
- npm install -g istanbul
- npm install -g codeclimate-test-reporter
script:
- npm run make
- npm run instrument
- npm run test-phantomjs
- npm run coverage-report
- npm run test
after_script:
- cat coverage/lcov.info | codeclimate
- cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/codeclimate-test-reporter'
branches:
only:
- master
addons:
code_climate:
repo_token: 9ffe8abc7638fd859bf081174225ff9846ee5a476c8793bd4e8cc3ec90dae358
3 changes: 1 addition & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 Matthew Callis
Copyright (c) 2016 Matthew Callis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

116 changes: 63 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,61 +14,64 @@ Wildberry Princess is a JavaScript library for abstracting out Google Analytics

## Usage

```coffeescript
# Google Analytics initialized somewhere...
# Kissmetrics initialized somewhere...

# Setup
analytics = new WildberryPrincess(
useGoogleAnalytics: true
useKissMetrics: true
)

# Set dimensions and users.
analytics.identify(current_user_id) if current_user_id?
analytics.set('dimension1', app_id) if app_id?

# Or more specifically:
analytics.setGA('dimension1', app_id) if app_id?
analytics.setKM('app_id', app_id) if app_id?

# Track user actions, specifically clicks, where the label is the text content (button, div, tab, etc.) or form input name (input, select, textarea).
# analytics.trackUserActions(selector, category, action, label, value)
analytics.trackUserActions('button', 'Button')
analytics.trackUserActions('input, select, textarea', 'Form Input')
analytics.trackUserActions('tab', 'Tab')

# Send events anywhere, like Backbone model actions.
# analytics.trackEvent(category, action, label, value)
# analytics.trackEventGA(category, action, label, value)
# analytics.trackEventKM(label, payload)
analytics.trackEvent('Model', 'Destroy', @constructorName)

# Track page views. Currently, KissMetrics is not included here to avoid event bloat.
Apptentive.analytics.trackPageView('/fake-page', 'A Cool Fake Title')

# Send eCommerce data.
transaction_id = "#{@model.id}_#{Date.now()}"
transaction =
id: transaction_id
affiliation: "Candy Kingdom"
revenue: price
shipping: '0'
tax: '0'

item =
id: transaction_id
name: name
category: category
price: price
quantity: 1

analytics.trackEcommerce('clear')
analytics.trackEcommerce('addTransaction', transaction)
analytics.trackEcommerce('addItem', item)
analytics.trackEcommerce('send')
```javascript
// Google Analytics initialized somewhere...
// Kissmetrics initialized somewhere...

// Setup
const analytics = new WildberryPrincess({
useGoogleAnalytics: true,
useKissMetrics: false,
});

// Set dimensions and users.
if (current_user_id != null) {
analytics.identify(current_user_id);
}

if (app_id != null) {
analytics.set('dimension1', app_id);
}

// Track user actions, specifically clicks, where the label is the text content (button, div, tab, etc.) or form input name (input, select, textarea).
// analytics.trackUserActions(selector, category, action, label, value)
analytics.trackUserActions('button', 'Button');
analytics.trackUserActions('input, select, textarea', 'Form Input');
analytics.trackUserActions('tab', 'Tab');

// Send events anywhere, like Backbone model actions.
// analytics.trackEvent(category, action, label, value)
analytics.trackEvent('Model', 'Destroy', this.constructorName);

// Track page views. Currently
// NOTE: KissMetrics is not included here to avoid event bloat 🤑
Apptentive.analytics.trackPageView('/fake-page', 'A Cool Fake Title');

// Send eCommerce data.
const transaction_id = `${this.model.id}_${Date.now()}`;
const transaction = {
id: transaction_id,
affiliation: 'Candy Kingdom',
revenue: price,
shipping: '0',
tax: '0',
};
const item = {
id: transaction_id,
name,
category,
price,
quantity: 1,
};

analytics.trackEcommerce('clear');
analytics.trackEcommerce('addTransaction', transaction);
analytics.trackEcommerce('addItem', item);
analytics.trackEcommerce('send');
```

For more advanced use, please refer to the source.

### Testing

```shell
Expand All @@ -82,6 +85,13 @@ npm run make-dist-min
npm run lint && npm run make && npm run instrument && npm run test-phantomjs && npm run coverage-report && npm run make-dist-min
```

## Useful Reading

- [Analytics.js Field Reference](https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference)
- [Cookies and User Identification](https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id)
- [Custom Dimensions and Metrics](https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets)
- [Event Tracking](https://developers.google.com/analytics/devguides/collection/analyticsjs/events)

## Contributing

1. Fork it
Expand Down

0 comments on commit bc9b8c4

Please sign in to comment.