Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/fix_insightkeenio' into rc
Browse files Browse the repository at this point in the history
  • Loading branch information
nuxlli committed Jun 16, 2015
2 parents 0907f35 + 596afaa commit c1b56a2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
11 changes: 9 additions & 2 deletions spec/utils/tracker_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import h from 'spec/spec_helper';
import { default as tracker } from 'azk/utils/tracker';

// azk nvm grunt --grep='Azk Tracker'
import { meta as azkMeta } from 'azk';

describe("Azk Tracker", function() {
this.timeout(2000);
Expand All @@ -22,4 +21,12 @@ describe("Azk Tracker", function() {
var expectedSessionId = tracker.loadAgentSessionId();
h.expect(sessionId).to.equal(expectedSessionId);
});

it("should override insight get/set for optout", function() {
return azkMeta.cleanAsync().then(() => {
tracker.insight.optOut = true;
var metaOptout = azkMeta.get(tracker.insight_opts.opt_out_key);
h.expect(metaOptout).to.equal(false);
});
});
});
13 changes: 8 additions & 5 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ var options = mergeConfig({
},
// jscs:disable maximumLineLength
tracker: {
permission_key: 'tracker_permission',
disable: envs('AZK_DISABLE_TRACKER', false),
projectId: envs('AZK_KEEN_PROJECT_ID', '552818c790e4bd7f7bd8baba'),
writeKey: envs('AZK_KEEN_WRITE_KEY', 'e2c70b3dd3ed3003a09a1bc7d8622ad9220fe33069d81164f0fafa13baf11458e48736f6cbcc995a8346183b290597504feb4bef06f71350f4859df5eb271a1d845f7cff5c9dfddf2f03de1e39760c6e51a06fb9e347c2e1fb98d3c6d370e6916e5db8810ddd9c0d5d83540386ccfe2e'),
Expand Down Expand Up @@ -136,11 +137,8 @@ var options = mergeConfig({
},
test: {
paths: {
// jscs:disable maximumLineLength
log : path.join(paths.logs, 'azk_test.log'),
projectId: envs('AZK_KEEN_PROJECT_ID', '5526968d672e6c5a0d0ebec6'),
writeKey: envs('AZK_KEEN_WRITE_KEY', '5dbce13e376070e36eec0c7dd1e7f42e49f39b4db041f208054617863832309c14a797409e12d976630c3a4b479004f26b362506e82a46dd54df0c977a7378da280c05ae733c97abb445f58abb56ae15f561ac9ad774cea12c3ad8628d896c39f6e702f6b035541fc1a562997cb05768'),
// jscs:enabled maximumLineLength
log : path.join(paths.logs, 'azk_test.log'),
azk_meta: path.join(data_path, azk_dir, "shared", "test-Azkfile.js"),
},
docker: {
namespace : 'azk.test',
Expand All @@ -150,6 +148,11 @@ var options = mergeConfig({
},
tracker: {
disable: true,
// jscs:disable maximumLineLength
permission_key: 'tracker_permission_test',
projectId : envs('AZK_KEEN_PROJECT_ID', '5526968d672e6c5a0d0ebec6'),
writeKey : envs('AZK_KEEN_WRITE_KEY', '5dbce13e376070e36eec0c7dd1e7f42e49f39b4db041f208054617863832309c14a797409e12d976630c3a4b479004f26b362506e82a46dd54df0c977a7378da280c05ae733c97abb445f58abb56ae15f561ac9ad774cea12c3ad8628d896c39f6e702f6b035541fc1a562997cb05768'),
// jscs:enabled maximumLineLength
},
logs_level: {
console: (envs('AZK_DEBUG') ? 'debug' : 'warn'),
Expand Down
31 changes: 25 additions & 6 deletions src/utils/tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,28 @@ import { meta as azkMeta } from 'azk';
import { promiseResolve } from 'azk/utils/promises';

var lazy = lazy_require({
InsightKeenIo: 'insight-keen-io',
os : 'os',
osName : 'os-name',
calculateHash: ['azk/utils'],
InsightKeenIo: 'insight-keen-io',
InsightKeenIoWithMeta: () => {
class InsightKeenIoWithMeta extends lazy.InsightKeenIo {
constructor(opts) {
super(opts);
this._opt_out_key = opts.opt_out_key;
}

get optOut() {
return !azkMeta.get(this._opt_out_key);
}

set optOut(val) {
azkMeta.set(this._opt_out_key, !val);
}
}

return InsightKeenIoWithMeta;
}
});

export class TrackerEvent {
Expand Down Expand Up @@ -88,9 +106,10 @@ export class Tracker {

constructor(opts, ids_keys) {
opts = _.merge({}, {
projectId: config('tracker:projectId'),
writeKey : config('tracker:writeKey'),
use_fork : true,
projectId : config('tracker:projectId'),
writeKey : config('tracker:writeKey'),
use_fork : true,
opt_out_key: ids_keys.permission,
}, opts);

this.ids_keys = ids_keys;
Expand All @@ -115,7 +134,7 @@ export class Tracker {

get insight() {
if (!this.__insight) {
this.__insight = new lazy.InsightKeenIo(this.insight_opts);
this.__insight = new lazy.InsightKeenIoWithMeta(this.insight_opts);
}
return this.__insight;
}
Expand Down Expand Up @@ -183,7 +202,7 @@ export class Tracker {

// Default tracker
var default_tracker = new Tracker({}, {
permission: 'tracker_permission',
permission: config('tracker:permission_key'),
user_id : 'tracker_user_id',
agent_id : 'agent_session_id',
});
Expand Down

0 comments on commit c1b56a2

Please sign in to comment.