Skip to content

Commit

Permalink
Adomik Analytics Adapter: update sampling (prebid#7846)
Browse files Browse the repository at this point in the history
* AdomikAnalyticsAdapter sampling

* kick off tests

Co-authored-by: Chris Huie <phoenixtechnerd@gmail.com>
  • Loading branch information
2 people authored and Chris Pabst committed Jan 10, 2022
1 parent 740e8d2 commit e12fdb3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
34 changes: 23 additions & 11 deletions modules/adomikAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const bidWon = CONSTANTS.EVENTS.BID_WON;
const bidTimeout = CONSTANTS.EVENTS.BID_TIMEOUT;
const ua = navigator.userAgent;

var _sampled = true;

let adomikAdapter = Object.assign(adapter({}),
{
// Track every event needed
Expand Down Expand Up @@ -81,6 +83,7 @@ adomikAdapter.sendTypedEvent = function() {
uid: adomikAdapter.currentContext.uid,
ahbaid: adomikAdapter.currentContext.id,
hostname: window.location.hostname,
sampling: adomikAdapter.currentContext.sampling,
eventsByPlacementCode: groupedTypedEvents.map(function(typedEventsByType) {
let sizes = [];
const eventKeys = ['request', 'response', 'winner'];
Expand Down Expand Up @@ -203,19 +206,28 @@ adomikAdapter.adapterEnableAnalytics = adomikAdapter.enableAnalytics;

adomikAdapter.enableAnalytics = function (config) {
adomikAdapter.currentContext = {};

const initOptions = config.options;
if (initOptions) {
adomikAdapter.currentContext = {
uid: initOptions.id,
url: initOptions.url,
testId: initOptions.testId,
testValue: initOptions.testValue,
id: '',
timeouted: false,

_sampled = typeof config === 'undefined' ||
typeof config.sampling === 'undefined' ||
Math.random() < parseFloat(config.sampling);

if (_sampled) {
if (initOptions) {
adomikAdapter.currentContext = {
uid: initOptions.id,
url: initOptions.url,
testId: initOptions.testId,
testValue: initOptions.testValue,
id: '',
timeouted: false,
sampling: config.sampling
}
logInfo('Adomik Analytics enabled with config', initOptions);
adomikAdapter.adapterEnableAnalytics(config);
}
logInfo('Adomik Analytics enabled with config', initOptions);
adomikAdapter.adapterEnableAnalytics(config);
} else {
logInfo('Adomik Analytics ignored for sampling', config.sampling);
}
};

Expand Down
4 changes: 3 additions & 1 deletion test/spec/modules/adomikAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import adomikAnalytics from 'modules/adomikAnalyticsAdapter.js';
import {expect} from 'chai';
import { expect } from 'chai';

let events = require('src/events');
let adapterManager = require('src/adapterManager').default;
Expand Down Expand Up @@ -73,6 +73,7 @@ describe('Adomik Prebid Analytic', function () {
expect(adomikAnalytics.currentContext).to.deep.equal({
uid: '123456',
url: 'testurl',
sampling: undefined,
testId: '12345',
testValue: '1000',
id: '',
Expand All @@ -85,6 +86,7 @@ describe('Adomik Prebid Analytic', function () {
expect(adomikAnalytics.currentContext).to.deep.equal({
uid: '123456',
url: 'testurl',
sampling: undefined,
testId: '12345',
testValue: '1000',
id: 'test-test-test',
Expand Down

0 comments on commit e12fdb3

Please sign in to comment.