Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Greenbids Analytics Adapter: define split between exploratory and non exploratory sides of the sampling #11104

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions modules/greenbidsAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,24 @@ export const BIDDER_STATUS = {

const analyticsOptions = {};

export const isSampled = function(greenbidsId, samplingRate) {
export const isSampled = function(greenbidsId, samplingRate, exploratorySamplingSplit) {
if (samplingRate < 0 || samplingRate > 1) {
logWarn('Sampling rate must be between 0 and 1');
return true;
}
const exploratorySamplingRate = samplingRate * exploratorySamplingSplit;
const throttledSamplingRate = samplingRate * (1.0 - exploratorySamplingSplit);
const hashInt = parseInt(greenbidsId.slice(-4), 16);
return hashInt < samplingRate * (0xFFFF + 1);
const isPrimarySampled = hashInt < exploratorySamplingRate * (0xFFFF + 1);
if (isPrimarySampled) return true;
const isExtraSampled = hashInt >= (1 - throttledSamplingRate) * (0xFFFF + 1);
return isExtraSampled;
}

export const greenbidsAnalyticsAdapter = Object.assign(adapter({ANALYTICS_SERVER, analyticsType}), {

cachedAuctions: {},
exploratorySamplingSplit: 0.9,

initConfig(config) {
analyticsOptions.options = deepClone(config.options);
Expand Down Expand Up @@ -68,6 +74,14 @@ export const greenbidsAnalyticsAdapter = Object.assign(adapter({ANALYTICS_SERVER
analyticsOptions.options.greenbidsSampling = 1;
}

/**
* Add optional debug parameter to override exploratorySamplingSplit
*/
if (typeof analyticsOptions.options.exploratorySamplingSplit === 'number') {
logInfo('Greenbids Analytics: Overriding "exploratorySamplingSplit".');
this.exploratorySamplingSplit = analyticsOptions.options.exploratorySamplingSplit;
}

analyticsOptions.pbuid = config.options.pbuid
analyticsOptions.server = ANALYTICS_SERVER;

Expand Down Expand Up @@ -172,7 +186,7 @@ export const greenbidsAnalyticsAdapter = Object.assign(adapter({ANALYTICS_SERVER
logInfo("Couldn't find Greenbids RTD info, assuming analytics only");
cachedAuction.greenbidsId = generateUUID();
}
cachedAuction.isSampled = isSampled(cachedAuction.greenbidsId, analyticsOptions.options.greenbidsSampling);
cachedAuction.isSampled = isSampled(cachedAuction.greenbidsId, analyticsOptions.options.greenbidsSampling, this.exploratorySamplingSplit);
},
handleAuctionEnd(auctionEndArgs) {
const cachedAuction = this.getCachedAuction(auctionEndArgs.auctionId);
Expand Down
16 changes: 12 additions & 4 deletions test/spec/modules/greenbidsAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,16 +404,24 @@ describe('Greenbids Prebid AnalyticsAdapter Testing', function () {

describe('isSampled', function() {
it('should return true for invalid sampling rates', function() {
expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', -1)).to.be.true;
expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', 1.2)).to.be.true;
expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', -1, 0.0)).to.be.true;
expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', 1.2, 0.0)).to.be.true;
});

it('should return determinist falsevalue for valid sampling rate given the predifined id and rate', function() {
expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', 0.0001)).to.be.false;
expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', 0.0001, 0.0)).to.be.false;
});

it('should return determinist true value for valid sampling rate given the predifined id and rate', function() {
expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', 0.9999)).to.be.true;
expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', 0.9999, 0.0)).to.be.true;
});

it('should return determinist true value for valid sampling rate given the predifined id and rate when we split to non exploration first', function() {
expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', 0.9999, 0.0, 1.0)).to.be.true;
});

it('should return determinist false value for valid sampling rate given the predifined id and rate when we split to non exploration first', function() {
expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', 0.0001, 0.0, 1.0)).to.be.false;
});
});
});