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

ZetaGlobalSsp AnalyticsAdapter: provide zeta params through cache #10402

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
da0b4a5
Merge pull request #1 from prebid/master
asurovenko-zeta Mar 24, 2021
f4ec68e
Merge branch 'master' of git://github.com/prebid/Prebid.js
surovenko Apr 21, 2021
01990a9
Merge remote-tracking branch 'upstream/master'
surovenko May 18, 2021
62f969f
Merge remote-tracking branch 'upstream/master'
surovenko May 18, 2021
ec7c8f0
Merge remote-tracking branch 'upstream/master'
surovenko May 19, 2021
89fe5b1
Merge remote-tracking branch 'upstream/master'
surovenko May 24, 2021
6dc0255
Merge remote-tracking branch 'upstream/master'
surovenko Jun 1, 2021
8dc9ac2
Merge remote-tracking branch 'upstream/master'
surovenko Jun 3, 2021
35353f0
Merge remote-tracking branch 'upstream/master'
surovenko Jun 3, 2021
e6f982a
Merge remote-tracking branch 'upstream/master'
surovenko Jun 4, 2021
70e546c
Merge remote-tracking branch 'upstream/master'
surovenko Jun 7, 2021
cc56875
Merge remote-tracking branch 'upstream/master'
surovenko Jun 15, 2021
f4f2a1e
Merge remote-tracking branch 'upstream/master'
surovenko Jun 16, 2021
3f96c6a
Merge remote-tracking branch 'upstream/master'
surovenko Jul 8, 2021
8e503cd
Merge remote-tracking branch 'upstream/master'
surovenko Aug 3, 2021
1781bfd
Merge remote-tracking branch 'upstream/master'
surovenko Aug 12, 2021
459917b
Merge remote-tracking branch 'upstream/master'
surovenko Aug 17, 2021
9ce50bd
Merge remote-tracking branch 'upstream/master'
surovenko Aug 18, 2021
8f7f147
Merge remote-tracking branch 'upstream/master'
surovenko Aug 19, 2021
a280757
Merge remote-tracking branch 'upstream/master'
surovenko Sep 22, 2021
036d5f1
Merge remote-tracking branch 'upstream/master'
surovenko Nov 19, 2021
33e883f
Merge remote-tracking branch 'upstream/master'
surovenko Nov 26, 2021
e729eb9
Merge remote-tracking branch 'upstream/master'
surovenko Dec 28, 2021
c202e93
Merge remote-tracking branch 'origin/master'
surovenko Feb 17, 2022
95877a7
Merge remote-tracking branch 'upstream/master'
surovenko Feb 22, 2022
bf8f638
Merge remote-tracking branch 'upstream/master'
surovenko Feb 28, 2022
461374f
Merge remote-tracking branch 'upstream/master'
surovenko Mar 5, 2022
b6a2fdc
Merge remote-tracking branch 'upstream/master'
surovenko Mar 9, 2022
92b44e3
Merge remote-tracking branch 'upstream/master'
surovenko May 23, 2022
42381eb
Merge remote-tracking branch 'upstream/master'
surovenko May 25, 2022
f629f34
Merge remote-tracking branch 'upstream/master'
surovenko May 26, 2022
9627d5d
Merge remote-tracking branch 'upstream/master'
surovenko May 27, 2022
3d0c2b2
Merge remote-tracking branch 'upstream/master'
surovenko Aug 10, 2022
0dfdb1c
Merge remote-tracking branch 'upstream/master'
surovenko Nov 14, 2022
9438a2e
Merge remote-tracking branch 'upstream/master'
Feb 1, 2023
4198c51
Merge remote-tracking branch 'upstream/master'
asurovenko-zeta Feb 15, 2023
4064f1f
Merge remote-tracking branch 'upstream/master'
asurovenko-zeta Mar 16, 2023
6b380a1
Merge remote-tracking branch 'upstream/master'
asurovenko-zeta Apr 5, 2023
6cd4e3f
Merge remote-tracking branch 'upstream/master'
asurovenko-zeta Apr 25, 2023
1794ae1
Merge remote-tracking branch 'upstream/master'
asurovenko-zeta Jun 2, 2023
42d2317
Merge remote-tracking branch 'upstream/master'
asurovenko-zeta Jun 8, 2023
691c896
Merge remote-tracking branch 'upstream/master'
asurovenko-zeta Aug 28, 2023
da8e7d3
ZetaGlobalSsp Analytics Adapter: save ZetaParams to cache
asurovenko-zeta Aug 28, 2023
294aa6b
bugfix
asurovenko-zeta Aug 30, 2023
8c9b326
test
asurovenko-zeta Aug 30, 2023
5ef24f1
fixes by review
asurovenko-zeta Sep 9, 2023
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
62 changes: 59 additions & 3 deletions modules/zeta_global_sspAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logInfo, logError } from '../src/utils.js';
import {logInfo, logError, deepClone} from '../src/utils.js';
import { ajax } from '../src/ajax.js';
import adapterManager from '../src/adapterManager.js';
import CONSTANTS from '../src/constants.json';
Expand All @@ -10,6 +10,10 @@ const ADAPTER_CODE = 'zeta_global_ssp';
const BASE_URL = 'https://ssp.disqus.com/prebid/event';
const LOG_PREFIX = 'ZetaGlobalSsp-Analytics: ';

const cache = {
auctions: {}
};

/// /////////// VARIABLES ////////////////////////////////////

let publisherId; // int
Expand All @@ -24,19 +28,71 @@ function sendEvent(eventType, event) {
);
}

function getZetaParams(event) {
if (event.adUnits) {
for (const i in event.adUnits) {
const unit = event.adUnits[i];
if (unit.bids) {
for (const j in unit.bids) {
const bid = unit.bids[j];
if (bid.bidder === ADAPTER_CODE && bid.params) {
return bid.params;
}
}
}
}
}
return null;
}

/// /////////// ADAPTER EVENT HANDLER FUNCTIONS //////////////

function adRenderSucceededHandler(args) {
function adRenderSucceededHandler(originalArgs) {
const args = deepClone(originalArgs);
let eventType = CONSTANTS.EVENTS.AD_RENDER_SUCCEEDED
logInfo(LOG_PREFIX + 'handle ' + eventType + ' event');

if (args.bid) {
// cleanup object
delete args.bid.metrics;
delete args.bid.ad;

// set zetaParams from cache
if (args.bid.auctionId) {
const zetaParams = cache.auctions[args.bid.auctionId];
if (zetaParams) {
args.bid.params = [ zetaParams ];
}
}
}

sendEvent(eventType, args);
}

function auctionEndHandler(args) {
function auctionEndHandler(originalArgs) {
const args = deepClone(originalArgs);
let eventType = CONSTANTS.EVENTS.AUCTION_END;
logInfo(LOG_PREFIX + 'handle ' + eventType + ' event');

// cleanup object
delete args.metrics;
if (args.bidderRequests) {
args.bidderRequests.forEach(requests => {
delete requests.metrics;
if (requests.bids) {
requests.bids.forEach(bid => {
delete bid.metrics;
})
}
})
}

// save zetaParams to cache
const zetaParams = getZetaParams(args);
if (zetaParams && args.auctionId) {
cache.auctions[args.auctionId] = zetaParams;
}

sendEvent(eventType, args);
}

Expand Down
65 changes: 24 additions & 41 deletions test/spec/modules/zeta_global_sspAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ import zetaAnalyticsAdapter from 'modules/zeta_global_sspAnalyticsAdapter.js';
import {config} from 'src/config';
import CONSTANTS from 'src/constants.json';
import {server} from '../../mocks/xhr.js';
import {logError} from '../../../src/utils';

let utils = require('src/utils');
let events = require('src/events');

const MOCK = {
STUB: {
'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa'
},
const EVENTS = {
AUCTION_END: {
'auctionId': '75e394d9-ccce-4978-9238-91e6a1ac88a1',
'timestamp': 1638441234544,
'auctionEnd': 1638441234784,
'auctionStatus': 'completed',
'metrics': {
'someMetric': 1
},
'adUnits': [
{
'code': '/19968336/header-bid-tag-0',
Expand Down Expand Up @@ -74,13 +75,6 @@ const MOCK = {
'bids': [
{
'bidder': 'zeta_global_ssp',
'params': {
'sid': 111,
'tags': {
'shortname': 'prebid_analytics_event_test_shortname',
'position': 'test_position'
}
},
'mediaTypes': {
'banner': {
'sizes': [
Expand Down Expand Up @@ -309,6 +303,9 @@ const MOCK = {
'cpm': 2.258302852806723,
'currency': 'USD',
'ad': 'test_ad',
'metrics': {
'someMetric': 0
},
'ttl': 200,
'creativeId': '456456456',
'netRevenue': true,
Expand Down Expand Up @@ -344,11 +341,7 @@ const MOCK = {
'status': 'rendered',
'params': [
{
'sid': 111,
'tags': {
'shortname': 'prebid_analytics_event_test_shortname',
'position': 'test_position'
}
'nonZetaParam': 'nonZetaValue'
}
]
},
Expand Down Expand Up @@ -392,33 +385,23 @@ describe('Zeta Global SSP Analytics Adapter', function() {
zetaAnalyticsAdapter.disableAnalytics();
});

it('events are sent', function() {
this.timeout(5000);
events.emit(CONSTANTS.EVENTS.AUCTION_INIT, MOCK.STUB);
events.emit(CONSTANTS.EVENTS.AUCTION_END, MOCK.AUCTION_END);
events.emit(CONSTANTS.EVENTS.BID_ADJUSTMENT, MOCK.STUB);
events.emit(CONSTANTS.EVENTS.BID_TIMEOUT, MOCK.STUB);
events.emit(CONSTANTS.EVENTS.BID_REQUESTED, MOCK.STUB);
events.emit(CONSTANTS.EVENTS.BID_RESPONSE, MOCK.STUB);
events.emit(CONSTANTS.EVENTS.NO_BID, MOCK.STUB);
events.emit(CONSTANTS.EVENTS.BID_WON, MOCK.STUB);
events.emit(CONSTANTS.EVENTS.BIDDER_DONE, MOCK.STUB);
events.emit(CONSTANTS.EVENTS.BIDDER_ERROR, MOCK.STUB);
events.emit(CONSTANTS.EVENTS.SET_TARGETING, MOCK.STUB);
events.emit(CONSTANTS.EVENTS.BEFORE_REQUEST_BIDS, MOCK.STUB);
events.emit(CONSTANTS.EVENTS.BEFORE_BIDDER_HTTP, MOCK.STUB);
events.emit(CONSTANTS.EVENTS.REQUEST_BIDS, MOCK.STUB);
events.emit(CONSTANTS.EVENTS.ADD_AD_UNITS, MOCK.STUB);
events.emit(CONSTANTS.EVENTS.AD_RENDER_FAILED, MOCK.STUB);
events.emit(CONSTANTS.EVENTS.AD_RENDER_SUCCEEDED, MOCK.AD_RENDER_SUCCEEDED);
events.emit(CONSTANTS.EVENTS.TCF2_ENFORCEMENT, MOCK.STUB);
events.emit(CONSTANTS.EVENTS.AUCTION_DEBUG, MOCK.STUB);
events.emit(CONSTANTS.EVENTS.BID_VIEWABLE, MOCK.STUB);
events.emit(CONSTANTS.EVENTS.STALE_RENDER, MOCK.STUB);
it('Move ZetaParams through analytics events', function() {
this.timeout(3000);

events.emit(CONSTANTS.EVENTS.AUCTION_END, EVENTS.AUCTION_END);
events.emit(CONSTANTS.EVENTS.AD_RENDER_SUCCEEDED, EVENTS.AD_RENDER_SUCCEEDED);

expect(requests.length).to.equal(2);
expect(JSON.parse(requests[0].requestBody)).to.deep.equal(MOCK.AUCTION_END);
expect(JSON.parse(requests[1].requestBody)).to.deep.equal(MOCK.AD_RENDER_SUCCEEDED);
const auctionEnd = JSON.parse(requests[0].requestBody);
const auctionSucceeded = JSON.parse(requests[1].requestBody);

expect(auctionEnd.metrics).to.be.undefined;

expect(auctionSucceeded.bid.ad).to.be.undefined;
expect(auctionSucceeded.bid.metrics).to.be.undefined;

expect(auctionSucceeded.bid.params[0]).to.be.deep.equal(EVENTS.AUCTION_END.adUnits[0].bids[0].params);
expect(EVENTS.AUCTION_END.adUnits[0].bids[0].bidder).to.be.equal('zeta_global_ssp');
});
});
});