Skip to content

Commit e12fdb3

Browse files
liabas-bChrisHuie
authored and
Chris Pabst
committed
Adomik Analytics Adapter: update sampling (prebid#7846)
* AdomikAnalyticsAdapter sampling * kick off tests Co-authored-by: Chris Huie <[email protected]>
1 parent 740e8d2 commit e12fdb3

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

modules/adomikAnalyticsAdapter.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const bidWon = CONSTANTS.EVENTS.BID_WON;
1414
const bidTimeout = CONSTANTS.EVENTS.BID_TIMEOUT;
1515
const ua = navigator.userAgent;
1616

17+
var _sampled = true;
18+
1719
let adomikAdapter = Object.assign(adapter({}),
1820
{
1921
// Track every event needed
@@ -81,6 +83,7 @@ adomikAdapter.sendTypedEvent = function() {
8183
uid: adomikAdapter.currentContext.uid,
8284
ahbaid: adomikAdapter.currentContext.id,
8385
hostname: window.location.hostname,
86+
sampling: adomikAdapter.currentContext.sampling,
8487
eventsByPlacementCode: groupedTypedEvents.map(function(typedEventsByType) {
8588
let sizes = [];
8689
const eventKeys = ['request', 'response', 'winner'];
@@ -203,19 +206,28 @@ adomikAdapter.adapterEnableAnalytics = adomikAdapter.enableAnalytics;
203206

204207
adomikAdapter.enableAnalytics = function (config) {
205208
adomikAdapter.currentContext = {};
206-
207209
const initOptions = config.options;
208-
if (initOptions) {
209-
adomikAdapter.currentContext = {
210-
uid: initOptions.id,
211-
url: initOptions.url,
212-
testId: initOptions.testId,
213-
testValue: initOptions.testValue,
214-
id: '',
215-
timeouted: false,
210+
211+
_sampled = typeof config === 'undefined' ||
212+
typeof config.sampling === 'undefined' ||
213+
Math.random() < parseFloat(config.sampling);
214+
215+
if (_sampled) {
216+
if (initOptions) {
217+
adomikAdapter.currentContext = {
218+
uid: initOptions.id,
219+
url: initOptions.url,
220+
testId: initOptions.testId,
221+
testValue: initOptions.testValue,
222+
id: '',
223+
timeouted: false,
224+
sampling: config.sampling
225+
}
226+
logInfo('Adomik Analytics enabled with config', initOptions);
227+
adomikAdapter.adapterEnableAnalytics(config);
216228
}
217-
logInfo('Adomik Analytics enabled with config', initOptions);
218-
adomikAdapter.adapterEnableAnalytics(config);
229+
} else {
230+
logInfo('Adomik Analytics ignored for sampling', config.sampling);
219231
}
220232
};
221233

test/spec/modules/adomikAnalyticsAdapter_spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import adomikAnalytics from 'modules/adomikAnalyticsAdapter.js';
2-
import {expect} from 'chai';
2+
import { expect } from 'chai';
33

44
let events = require('src/events');
55
let adapterManager = require('src/adapterManager').default;
@@ -73,6 +73,7 @@ describe('Adomik Prebid Analytic', function () {
7373
expect(adomikAnalytics.currentContext).to.deep.equal({
7474
uid: '123456',
7575
url: 'testurl',
76+
sampling: undefined,
7677
testId: '12345',
7778
testValue: '1000',
7879
id: '',
@@ -85,6 +86,7 @@ describe('Adomik Prebid Analytic', function () {
8586
expect(adomikAnalytics.currentContext).to.deep.equal({
8687
uid: '123456',
8788
url: 'testurl',
89+
sampling: undefined,
8890
testId: '12345',
8991
testValue: '1000',
9092
id: 'test-test-test',

0 commit comments

Comments
 (0)