Skip to content

Commit

Permalink
AdxPremium analytics adapter: do not generate network activity after …
Browse files Browse the repository at this point in the history
…tests have completed (#8514)

* AdxPremium analytics adapter: do not generate network activity after tests have completed

* Increase default test timeout to 3s
  • Loading branch information
dgirardi authored Jun 8, 2022
1 parent 3b4fce8 commit f5cf0eb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
6 changes: 6 additions & 0 deletions karma.conf.maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ module.exports = function(codeCoverage, browserstack, watchMode, file) {

reporters: ['mocha'],

client: {
mocha: {
timeout: 3000
}
},

mochaReporter: {
showDiff: true,
output: 'minimal'
Expand Down
1 change: 1 addition & 0 deletions modules/adxpremiumAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ function sendEventFallback() {
}

function sendEvent(completeObject) {
if (!adxpremiumAnalyticsAdapter.enabled) return;
requestDelivered = true;
try {
let responseEvents = btoa(JSON.stringify(completeObject));
Expand Down
19 changes: 13 additions & 6 deletions src/AnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ const BUNDLE = 'bundle';
var _sampled = true;

export default function AnalyticsAdapter({ url, analyticsType, global, handler }) {
var _queue = [];
var _eventCount = 0;
var _enableCheck = true;
var _handlers;
const _queue = [];
let _eventCount = 0;
let _enableCheck = true;
let _handlers;
let _enabled = false;

if (analyticsType === ENDPOINT || BUNDLE) {
_emptyQueue();
}

return {
return Object.defineProperties({
track: _track,
enqueue: _enqueue,
enableAnalytics: _enable,
Expand All @@ -52,7 +53,11 @@ export default function AnalyticsAdapter({ url, analyticsType, global, handler }
getGlobal: () => global,
getHandler: () => handler,
getUrl: () => url
};
}, {
enabled: {
get: () => _enabled
}
});

function _track({ eventType, args }) {
if (this.getAdapterType() === BUNDLE) {
Expand Down Expand Up @@ -140,13 +145,15 @@ export default function AnalyticsAdapter({ url, analyticsType, global, handler }
this.enableAnalytics = function _enable() {
return logMessage(`Analytics adapter for "${global}" already enabled, unnecessary call to \`enableAnalytics\`.`);
};
_enabled = true;
}

function _disable() {
_each(_handlers, (handler, event) => {
events.off(event, handler);
});
this.enableAnalytics = this._oldEnable ? this._oldEnable : _enable;
_enabled = false;
}

function _emptyQueue() {
Expand Down
8 changes: 8 additions & 0 deletions test/spec/AnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ FEATURE: Analytics Adapters API
adapter.disableAnalytics();
});

it('should track enable status in `enabled`', () => {
expect(adapter.enabled).to.equal(false);
adapter.enableAnalytics();
expect(adapter.enabled).to.equal(true);
adapter.disableAnalytics();
expect(adapter.enabled).to.equal(false);
})

it(`SHOULD call the endpoint WHEN an event occurs that is to be tracked`, function () {
const eventType = BID_REQUESTED;
const args = { some: 'data' };
Expand Down

0 comments on commit f5cf0eb

Please sign in to comment.