Skip to content

Commit

Permalink
Make it work
Browse files Browse the repository at this point in the history
  • Loading branch information
cibernox committed Jan 2, 2017
1 parent 41af1f3 commit 85d969f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
52 changes: 52 additions & 0 deletions addon/metrics-adapters/chameleon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import BaseAdapter from 'ember-metrics/metrics-adapters/base';
import canUseDOM from 'ember-metrics/utils/can-use-dom';
import Ember from 'ember';

const { testing } = Ember;

export default BaseAdapter.extend({
toStringExtension() {
return 'chameleon';
},

init() {
let config = this.get('config');
var methods = ["setup", "identify", "alias", "track", "set", "show", "on", "off", "custom", "help", "_data"];
let chmln = {};
this.chmln = chmln;
chmln.accountToken = config.token;
chmln.location = window.location.href.toString();
methods.forEach(function(method) {
let ary = [];
chmln[method + "_a"] = ary;
chmln[method] = function() {
ary.push(arguments);
};
});
if (!canUseDOM) {
return;
}
window.chmln = this.chmln;
if (testing) {
return;
}
this._script = document.createElement("script");
this._script.src = "https://fast.trychameleon.com/messo/"+config.token+"/messo.min.js";
this._script.async = true;
document.head.appendChild(this._script);
},

identify(options) {
this.chmln.identify(options);
},

willDestroy() {
if (canUseDOM) {
if (this._script) {
document.removeChild(this._script);
this._script = null;
}
delete window.chmln;
}
}
});
1 change: 1 addition & 0 deletions app/metrics-adapters/chameleon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-metrics-chameleon-adapter/metrics-adapters/chameleon';
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
"version": "0.0.0",
"description": "The default blueprint for ember-cli addons.",
"keywords": [
"ember-addon"
"ember-addon",
"ember-metrics",
"chameleon",
"metrics"
],
"license": "MIT",
"author": "",
"author": "Miguel Camba",
"directories": {
"doc": "doc",
"test": "tests"
Expand Down Expand Up @@ -39,6 +42,7 @@
"ember-disable-prototype-extensions": "^1.1.0",
"ember-export-application-global": "^1.0.5",
"ember-load-initializers": "^0.5.1",
"ember-metrics": "0.7.0",
"ember-resolver": "^2.0.3",
"ember-welcome-page": "^1.0.3",
"loader.js": "^4.0.10"
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/metrics-adapters/chameleon-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { moduleFor, test } from 'ember-qunit';

moduleFor('metrics-adapter:chameleon', 'chameleon adapter');

test('#identify', function(assert) {
var adapter = this.subject({ config: { token: '123' } });
adapter.identify({ some: 'option' });
assert.deepEqual(window.chmln.identify_a[0][0], { some: 'option' });
});

0 comments on commit 85d969f

Please sign in to comment.