Skip to content

Commit

Permalink
Forward extended parameters (prebid#11527)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn-lw committed May 22, 2024
1 parent 178ef64 commit 565825f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
10 changes: 2 additions & 8 deletions modules/livewrappedAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { timestamp, logInfo, getWindowTop } from '../src/utils.js';
import { timestamp, logInfo } from '../src/utils.js';
import {ajax} from '../src/ajax.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import { EVENTS, STATUS } from '../src/constants.js';
Expand Down Expand Up @@ -171,7 +171,7 @@ livewrappedAnalyticsAdapter.sendEvents = function() {
timeouts: getTimeouts(sentRequests.gdpr, sentRequests.auctionIds),
bidAdUnits: getbidAdUnits(),
rf: getAdRenderFailed(sentRequests.auctionIds),
rcv: getAdblockerRecovered()
ext: initOptions.ext
};

if (events.requests.length == 0 &&
Expand All @@ -185,12 +185,6 @@ livewrappedAnalyticsAdapter.sendEvents = function() {
ajax(initOptions.endpoint || URL, undefined, JSON.stringify(events), {method: 'POST'});
};

function getAdblockerRecovered() {
try {
return getWindowTop().I12C && getWindowTop().I12C.Morph === 1;
} catch (e) {}
}

function getSentRequests() {
var sentRequests = [];
var gdpr = [];
Expand Down
51 changes: 36 additions & 15 deletions test/spec/modules/livewrappedAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ describe('Livewrapped analytics adapter', function () {
});

it('should build a batched message from prebid events', function () {
sandbox.stub(utils, 'getWindowTop').returns({});
performStandardAuction();

clock.tick(BID_WON_TIMEOUT + 1000);
Expand Down Expand Up @@ -403,20 +402,6 @@ describe('Livewrapped analytics adapter', function () {
expect(message.timeouts[0].adUnit).to.equal('panorama_d_1');
});

it('should detect adblocker recovered request', function () {
sandbox.stub(utils, 'getWindowTop').returns({ I12C: { Morph: 1 } });
performStandardAuction();

clock.tick(BID_WON_TIMEOUT + 1000);

expect(server.requests.length).to.equal(1);
let request = server.requests[0];

let message = JSON.parse(request.requestBody);

expect(message.rcv).to.equal(true);
});

it('should forward GDPR data', function () {
events.emit(AUCTION_INIT, MOCK.AUCTION_INIT);
events.emit(BID_REQUESTED, {
Expand Down Expand Up @@ -623,4 +608,40 @@ describe('Livewrapped analytics adapter', function () {
expect(request.url).to.equal('https://whitelabeled.com/analytics/10');
});
});

describe('when given extended options', function () {
adapterManager.registerAnalyticsAdapter({
code: 'livewrapped',
adapter: livewrappedAnalyticsAdapter
});

beforeEach(function () {
adapterManager.enableAnalytics({
provider: 'livewrapped',
options: {
publisherId: 'CC411485-42BC-4F92-8389-42C503EE38D7',
ext: {
testparam: 123
}
}
});
});

afterEach(function () {
livewrappedAnalyticsAdapter.disableAnalytics();
});

it('should forward the extended options', function () {
performStandardAuction();

clock.tick(BID_WON_TIMEOUT + 1000);

expect(server.requests.length).to.equal(1);
let request = server.requests[0];
let message = JSON.parse(request.requestBody);

expect(message.ext).to.not.equal(null);
expect(message.ext.testparam).to.equal(123);
});
});
});

0 comments on commit 565825f

Please sign in to comment.