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

Submitting Tercept Analytics Adapter #5099

Merged
merged 2 commits into from
Apr 16, 2020
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
145 changes: 145 additions & 0 deletions modules/terceptAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import { ajax } from '../src/ajax.js';
import adapter from '../src/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import CONSTANTS from '../src/constants.json';
import * as url from '../src/url.js';
import * as utils from '../src/utils.js';

const emptyUrl = '';
const analyticsType = 'endpoint';
const terceptAnalyticsVersion = 'v1.0.0';
const defaultHostName = 'us-central1-quikr-ebay.cloudfunctions.net';
const defaultPathName = '/prebid-analytics';

let initOptions;
let auctionTimestamp;
let events = {
bids: []
};

var terceptAnalyticsAdapter = Object.assign(adapter(
{
emptyUrl,
analyticsType
}), {
track({ eventType, args }) {
if (typeof args !== 'undefined') {
if (eventType === CONSTANTS.EVENTS.BID_TIMEOUT) {
args.forEach(item => { mapBidResponse(item, 'timeout'); });
} else if (eventType === CONSTANTS.EVENTS.AUCTION_INIT) {
events.auctionInit = args;
auctionTimestamp = args.timestamp;
} else if (eventType === CONSTANTS.EVENTS.BID_REQUESTED) {
mapBidRequests(args).forEach(item => { events.bids.push(item) });
} else if (eventType === CONSTANTS.EVENTS.BID_RESPONSE) {
mapBidResponse(args, 'response');
} else if (eventType === CONSTANTS.EVENTS.BID_WON) {
send({
bidWon: mapBidResponse(args, 'win')
}, 'won');
}
}

if (eventType === CONSTANTS.EVENTS.AUCTION_END) {
send(events, 'auctionEnd');
}
}
});

function mapBidRequests(params) {
let arr = [];
if (typeof params.bids !== 'undefined' && params.bids.length) {
params.bids.forEach(function (bid) {
arr.push({
bidderCode: bid.bidder,
bidId: bid.bidId,
adUnitCode: bid.adUnitCode,
requestId: bid.bidderRequestId,
auctionId: bid.auctionId,
transactionId: bid.transactionId,
sizes: utils.parseSizesInput(bid.mediaTypes.banner.sizes).toString(),
renderStatus: 1,
requestTimestamp: params.auctionStart
});
});
}
return arr;
}

function mapBidResponse(bidResponse, status) {
if (status !== 'win') {
let bid = events.bids.filter(o => o.bidId === bidResponse.bidId || o.bidId === bidResponse.requestId)[0];
Object.assign(bid, {
bidderCode: bidResponse.bidder,
bidId: status === 'timeout' ? bidResponse.bidId : bidResponse.requestId,
adUnitCode: bidResponse.adUnitCode,
auctionId: bidResponse.auctionId,
creativeId: bidResponse.creativeId,
transactionId: bidResponse.transactionId,
currency: bidResponse.currency,
cpm: bidResponse.cpm,
netRevenue: bidResponse.netRevenue,
mediaType: bidResponse.mediaType,
statusMessage: bidResponse.statusMessage,
status: bidResponse.status,
renderStatus: status === 'timeout' ? 3 : 2,
timeToRespond: bidResponse.timeToRespond,
requestTimestamp: bidResponse.requestTimestamp,
responseTimestamp: bidResponse.responseTimestamp
});
} else {
return {
bidderCode: bidResponse.bidder,
bidId: bidResponse.requestId,
adUnitCode: bidResponse.adUnitCode,
auctionId: bidResponse.auctionId,
creativeId: bidResponse.creativeId,
transactionId: bidResponse.transactionId,
currency: bidResponse.currency,
cpm: bidResponse.cpm,
netRevenue: bidResponse.netRevenue,
renderedSize: bidResponse.size,
mediaType: bidResponse.mediaType,
statusMessage: bidResponse.statusMessage,
status: bidResponse.status,
renderStatus: 4,
timeToRespond: bidResponse.timeToRespond,
requestTimestamp: bidResponse.requestTimestamp,
responseTimestamp: bidResponse.responseTimestamp
}
}
}

function send(data, status) {
let location = utils.getWindowLocation();
if (typeof data !== 'undefined' && typeof data.auctionInit !== 'undefined') {
Object.assign(data.auctionInit, { host: location.host, path: location.pathname, search: location.search });
}
data.initOptions = initOptions;

let terceptAnalyticsRequestUrl = url.format({
protocol: 'https',
hostname: (initOptions && initOptions.hostName) || defaultHostName,
pathname: (initOptions && initOptions.pathName) || defaultPathName,
search: {
auctionTimestamp: auctionTimestamp,
terceptAnalyticsVersion: terceptAnalyticsVersion,
prebidVersion: $$PREBID_GLOBAL$$.version
}
});

ajax(terceptAnalyticsRequestUrl, undefined, JSON.stringify(data), { method: 'POST', contentType: 'text/plain' });
}

terceptAnalyticsAdapter.originEnableAnalytics = terceptAnalyticsAdapter.enableAnalytics;
terceptAnalyticsAdapter.enableAnalytics = function (config) {
initOptions = config.options;
terceptAnalyticsAdapter.originEnableAnalytics(config);
};

adapterManager.registerAnalyticsAdapter({
adapter: terceptAnalyticsAdapter,
code: 'tercept'
});

export default terceptAnalyticsAdapter;
22 changes: 22 additions & 0 deletions modules/terceptAnalyticsAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Overview
Module Name: Tercept Analytics Adapter
Module Type: Analytics Adapter
Maintainer: gourav.chindlur@tercept.com

# Description

Analytics adapter for prebid provided by Tercept. Contact gourav.chindlur@tercept.com for information.

# Test Parameters

```
{
provider: 'Tercept',
options : {
pubId : 50357 //id provided by Tercept
pubKey: 'xxx' //key provided by Tercept
hostName: 'us-central1-quikr-ebay.cloudfunctions.net' //Tercept endpoint host
pathName: '/prebid-analytics' //Tercept endpoint path
}
}
```
Loading