Skip to content

Commit

Permalink
AdomikAnalyticsAdapter sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
liabas-b committed Dec 16, 2021
1 parent df54d4b commit 049962f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 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
2 changes: 2 additions & 0 deletions test/spec/modules/adomikAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
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 049962f

Please sign in to comment.