-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
new bidder & analytics adapter: Concert #5338
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
101c22a
Add concert bid adapter, doc and tests.
walia e3f296c
Add analytics adapter
walia 2491f5e
Add email
walia 5c50b8d
Merge pull request #1 from voxmedia/concert-adapter
walia 668d500
fix alert from lgtm
walia 83d7993
try to fix test for ie 11
walia a166125
Handle USP string for PPID
andrew-a-dev 3012bc7
Merge pull request #2 from voxmedia/update-usprivacy-handling
andrew-a-dev b3b0138
Fix linking error
walia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import {ajax} from '../src/ajax.js'; | ||
import adapter from '../src/AnalyticsAdapter.js'; | ||
import CONSTANTS from '../src/constants.json'; | ||
import adapterManager from '../src/adapterManager.js'; | ||
import * as utils from '../src/utils.js'; | ||
|
||
const analyticsType = 'endpoint'; | ||
|
||
// We only want to send about 1% of events for sampling purposes | ||
const SAMPLE_RATE_PERCENTAGE = 1 / 100; | ||
const pageIncludedInSample = sampleAnalytics(); | ||
|
||
const url = 'https://bids.concert.io/analytics'; | ||
|
||
const { | ||
EVENTS: { | ||
BID_RESPONSE, | ||
BID_WON, | ||
AUCTION_END | ||
} | ||
} = CONSTANTS; | ||
|
||
let queue = []; | ||
|
||
let concertAnalytics = Object.assign(adapter({url, analyticsType}), { | ||
track({ eventType, args }) { | ||
switch (eventType) { | ||
case BID_RESPONSE: | ||
if (args.bidder !== 'concert') break; | ||
queue.push(mapBidEvent(eventType, args)); | ||
break; | ||
|
||
case BID_WON: | ||
if (args.bidder !== 'concert') break; | ||
queue.push(mapBidEvent(eventType, args)); | ||
break; | ||
|
||
case AUCTION_END: | ||
// Set a delay, as BID_WON events will come after AUCTION_END events | ||
setTimeout(() => sendEvents(), 3000); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
}); | ||
|
||
function mapBidEvent(eventType, args) { | ||
const { adId, auctionId, cpm, creativeId, width, height, timeToRespond } = args; | ||
const [gamCreativeId, concertRequestId] = getConcertRequestId(creativeId); | ||
|
||
return { | ||
event: eventType, | ||
concert_rid: concertRequestId, | ||
adId, | ||
auctionId, | ||
creativeId: gamCreativeId, | ||
position: args.adUnitCode, | ||
url: window.location.href, | ||
cpm, | ||
width, | ||
height, | ||
timeToRespond | ||
} | ||
} | ||
|
||
/** | ||
* In order to pass back the concert_rid from CBS, it is tucked into the `creativeId` | ||
* slot in the bid response and combined with a pipe `|`. This method splits the creative ID | ||
* and the concert_rid. | ||
* | ||
* @param {string} creativeId | ||
*/ | ||
function getConcertRequestId(creativeId) { | ||
if (!creativeId || !creativeId.includes('|')) return [null, null]; | ||
|
||
return creativeId.split('|'); | ||
} | ||
|
||
function sampleAnalytics() { | ||
return Math.random() <= SAMPLE_RATE_PERCENTAGE; | ||
} | ||
|
||
function sendEvents() { | ||
concertAnalytics.eventsStorage = queue; | ||
|
||
if (!queue.length) return; | ||
|
||
if (!pageIncludedInSample) { | ||
utils.logMessage('Page not included in sample for Concert Analytics'); | ||
return; | ||
} | ||
|
||
try { | ||
const body = JSON.stringify(queue); | ||
ajax(url, () => queue = [], body, { | ||
contentType: 'application/json', | ||
method: 'POST' | ||
}); | ||
} catch (err) { utils.logMessage('Concert Analytics error') } | ||
} | ||
|
||
// save the base class function | ||
concertAnalytics.originEnableAnalytics = concertAnalytics.enableAnalytics; | ||
concertAnalytics.eventsStorage = []; | ||
|
||
// override enableAnalytics so we can get access to the config passed in from the page | ||
concertAnalytics.enableAnalytics = function (config) { | ||
concertAnalytics.originEnableAnalytics(config); | ||
}; | ||
|
||
adapterManager.registerAnalyticsAdapter({ | ||
adapter: concertAnalytics, | ||
code: 'concert' | ||
}); | ||
|
||
export default concertAnalytics; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: Concert Analytics Adapter | ||
Module Type: Analytics Adapter | ||
Maintainer: [email protected] | ||
``` | ||
|
||
# Description | ||
|
||
Analytics adapter for concert. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
|
||
import * as utils from '../src/utils.js'; | ||
import { registerBidder } from '../src/adapters/bidderFactory.js'; | ||
import { getStorageManager } from '../src/storageManager.js' | ||
|
||
const BIDDER_CODE = 'concert'; | ||
const CONCERT_ENDPOINT = 'https://bids.concert.io'; | ||
const USER_SYNC_URL = 'https://cdn.concert.io/lib/bids/sync.html'; | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
/** | ||
* Determines whether or not the given bid request is valid. | ||
* | ||
* @param {BidRequest} bid The bid params to validate. | ||
* @return boolean True if this is a valid bid, and false otherwise. | ||
*/ | ||
isBidRequestValid: function(bid) { | ||
if (!bid.params.partnerId) { | ||
utils.logWarn('Missing partnerId bid parameter'); | ||
return false; | ||
} | ||
|
||
return true; | ||
}, | ||
|
||
/** | ||
* Make a server request from the list of BidRequests. | ||
* | ||
* @param {validBidRequests[]} - an array of bids | ||
* @param {bidderRequest} - | ||
* @return ServerRequest Info describing the request to the server. | ||
*/ | ||
buildRequests: function(validBidRequests, bidderRequest) { | ||
utils.logMessage(validBidRequests); | ||
utils.logMessage(bidderRequest); | ||
let payload = { | ||
meta: { | ||
prebidVersion: '$prebid.version$', | ||
pageUrl: bidderRequest.refererInfo.referer, | ||
screen: [window.screen.width, window.screen.height].join('x'), | ||
debug: utils.debugTurnedOn(), | ||
uid: getUid(bidderRequest), | ||
optedOut: hasOptedOutOfPersonalization(), | ||
adapterVersion: '1.1.0', | ||
uspConsent: bidderRequest.uspConsent, | ||
gdprConsent: bidderRequest.gdprConsent | ||
} | ||
} | ||
|
||
payload.slots = validBidRequests.map(bidRequest => { | ||
let slot = { | ||
name: bidRequest.adUnitCode, | ||
bidId: bidRequest.bidId, | ||
transactionId: bidRequest.transactionId, | ||
sizes: bidRequest.sizes, | ||
partnerId: bidRequest.params.partnerId, | ||
slotType: bidRequest.params.slotType | ||
} | ||
|
||
return slot; | ||
}); | ||
|
||
utils.logMessage(payload); | ||
|
||
return { | ||
method: 'POST', | ||
url: `${CONCERT_ENDPOINT}/bids/prebid`, | ||
data: JSON.stringify(payload) | ||
} | ||
}, | ||
/** | ||
* Unpack the response from the server into a list of bids. | ||
* | ||
* @param {ServerResponse} serverResponse A successful response from the server. | ||
* @return {Bid[]} An array of bids which were nested inside the server. | ||
*/ | ||
interpretResponse: function(serverResponse, bidRequest) { | ||
utils.logMessage(serverResponse); | ||
utils.logMessage(bidRequest); | ||
|
||
const serverBody = serverResponse.body; | ||
|
||
if (!serverBody || typeof serverBody !== 'object') { | ||
return []; | ||
} | ||
|
||
let bidResponses = []; | ||
|
||
bidResponses = serverBody.bids.map(bid => { | ||
return { | ||
requestId: bid.bidId, | ||
cpm: bid.cpm, | ||
width: bid.width, | ||
height: bid.height, | ||
ad: bid.ad, | ||
ttl: bid.ttl, | ||
creativeId: bid.creativeId, | ||
netRevenue: bid.netRevenue, | ||
currency: bid.currency | ||
} | ||
}); | ||
|
||
if (utils.debugTurnedOn() && serverBody.debug) { | ||
utils.logMessage(`CONCERT`, serverBody.debug); | ||
} | ||
|
||
utils.logMessage(bidResponses); | ||
return bidResponses; | ||
}, | ||
|
||
/** | ||
* Register the user sync pixels which should be dropped after the auction. | ||
* | ||
* @param {SyncOptions} syncOptions Which user syncs are allowed? | ||
* @param {ServerResponse[]} serverResponses List of server's responses. | ||
* @param {gdprConsent} object GDPR consent object. | ||
* @param {uspConsent} string US Privacy String. | ||
* @return {UserSync[]} The user syncs which should be dropped. | ||
*/ | ||
getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) { | ||
const syncs = [] | ||
if (syncOptions.iframeEnabled && !hasOptedOutOfPersonalization()) { | ||
let params = []; | ||
|
||
if (gdprConsent && (typeof gdprConsent.gdprApplies === 'boolean')) { | ||
params.push(`gdpr_applies=${gdprConsent.gdprApplies ? '1' : '0'}`); | ||
} | ||
if (gdprConsent && (typeof gdprConsent.consentString === 'string')) { | ||
params.push(`gdpr_consent=${gdprConsent.consentString}`); | ||
} | ||
if (uspConsent && (typeof uspConsent === 'string')) { | ||
params.push(`usp_consent=${uspConsent}`); | ||
} | ||
|
||
syncs.push({ | ||
type: 'iframe', | ||
url: USER_SYNC_URL + (params.length > 0 ? `?${params.join('&')}` : '') | ||
}); | ||
} | ||
return syncs; | ||
}, | ||
|
||
/** | ||
* Register bidder specific code, which will execute if bidder timed out after an auction | ||
* @param {data} Containing timeout specific data | ||
*/ | ||
onTimeout: function(data) { | ||
utils.logMessage('concert bidder timed out'); | ||
utils.logMessage(data); | ||
}, | ||
|
||
/** | ||
* Register bidder specific code, which will execute if a bid from this bidder won the auction | ||
* @param {Bid} The bid that won the auction | ||
*/ | ||
onBidWon: function(bid) { | ||
utils.logMessage('concert bidder won bid'); | ||
utils.logMessage(bid); | ||
} | ||
|
||
} | ||
|
||
registerBidder(spec); | ||
|
||
const storage = getStorageManager(); | ||
|
||
/** | ||
* Check or generate a UID for the current user. | ||
*/ | ||
function getUid(bidderRequest) { | ||
if (hasOptedOutOfPersonalization() || !consentAllowsPpid(bidderRequest)) { | ||
return false; | ||
} | ||
|
||
const CONCERT_UID_KEY = 'c_uid'; | ||
|
||
let uid = storage.getDataFromLocalStorage(CONCERT_UID_KEY); | ||
|
||
if (!uid) { | ||
uid = utils.generateUUID(); | ||
storage.setDataInLocalStorage(CONCERT_UID_KEY, uid); | ||
} | ||
|
||
return uid; | ||
} | ||
|
||
/** | ||
* Whether the user has opted out of personalization. | ||
*/ | ||
function hasOptedOutOfPersonalization() { | ||
const CONCERT_NO_PERSONALIZATION_KEY = 'c_nap'; | ||
|
||
return storage.getDataFromLocalStorage(CONCERT_NO_PERSONALIZATION_KEY) === 'true'; | ||
} | ||
|
||
/** | ||
* Whether the privacy consent strings allow personalization. | ||
* | ||
* @param {BidderRequest} bidderRequest Object which contains any data consent signals | ||
*/ | ||
function consentAllowsPpid(bidderRequest) { | ||
/* NOTE: We cannot easily test GDPR consent, without the | ||
* `consent-string` npm module; so will have to rely on that | ||
* happening on the bid-server. */ | ||
return !(bidderRequest.uspConsent === 'string' && | ||
bidderRequest.uspConsent.toUpperCase().substring(0, 2) === '1YY') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: Concert Bid Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: [email protected] | ||
``` | ||
|
||
# Description | ||
|
||
Module that connects to Concert demand sources | ||
|
||
# Test Paramters | ||
``` | ||
var adUnits = [ | ||
{ | ||
code: 'desktop_leaderboard_variable', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[1030, 590]] | ||
} | ||
} | ||
bids: [ | ||
{ | ||
bidder: "concert", | ||
params: { | ||
partnerId: 'test_partner' | ||
} | ||
} | ||
] | ||
} | ||
]; | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be a
partnerId
that will return data? When I used these params in a test page, I got this response:Also, all responses from your endpoint should be compressed (such as gzip, compress, deflate)