forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge tag '0.31.0' of https://github.com/prebid/Prebid.js into prebuilt
* tag '0.31.0' of https://github.com/prebid/Prebid.js: (54 commits) Fix for prebid#1628 (allowing standard bidCpmAdjustment) (prebid#1645) Prebid 0.31.0 Release Support native click tracking (prebid#1691) Initial commit for video support for pbs (prebid#1706) Fixes: Immediate adapter response may end auction (prebid#1690) Rubicon feature/s2s test module (prebid#1678) Renaming of "huddledmasses" adapter into colossusssp (prebid#1701) Don't set non-object configurations (prebid#1704) Update JSDoc for `pbjs.enableAnalytics` (prebid#1565) Add ad units event (prebid#1702) AppnexusAst adapter: logging error message from endpoint (prebid#1697) AppnexusAst bidadapter markdown file (prebid#1696) Change Default Content-Type for POST Requests to 'application/json' (prebid#1681) Code improvement for trustx adapter (prebid#1673) PulsePoint Lite adapter - Enabling Sync pixel (prebid#1686) Update spotx video adapter to set the spotx_ad_key used in DFP (prebid#1614) Fix broken AOL mobile endpoint secure bid requests (prebid#1684) Fix adapter tests that hardcoded pbjs. (prebid#1666) no longer attaching gpt slots to adUnits, which breaks utils.cloneJson(adUnit) (prebid#1676) remove bidmanager from rubicon tests (prebid#1671) ...
- Loading branch information
Showing
71 changed files
with
3,493 additions
and
1,810 deletions.
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
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
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
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
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
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,209 @@ | ||
import adapter from 'src/AnalyticsAdapter'; | ||
import CONSTANTS from 'src/constants.json'; | ||
import adaptermanager from 'src/adaptermanager'; | ||
// import utils from 'src/utils'; | ||
|
||
// Events used in adomik analytics adapter | ||
const auctionInit = CONSTANTS.EVENTS.AUCTION_INIT; | ||
const auctionEnd = CONSTANTS.EVENTS.AUCTION_END; | ||
const bidRequested = CONSTANTS.EVENTS.BID_REQUESTED; | ||
const bidResponse = CONSTANTS.EVENTS.BID_RESPONSE; | ||
const bidWon = CONSTANTS.EVENTS.BID_WON; | ||
const bidTimeout = CONSTANTS.EVENTS.BID_TIMEOUT; | ||
|
||
let bidwonTimeout = 1000; | ||
|
||
let adomikAdapter = Object.assign(adapter({}), | ||
{ | ||
// Track every event needed | ||
track({ eventType, args }) { | ||
switch (eventType) { | ||
case auctionInit: | ||
adomikAdapter.currentContext.id = args.requestId | ||
adomikAdapter.currentContext.timeout = args.timeout | ||
if (args.config.bidwonTimeout !== undefined && typeof args.config.bidwonTimeout === 'number') { | ||
bidwonTimeout = args.config.bidwonTimeout; | ||
} | ||
break; | ||
|
||
case bidTimeout: | ||
adomikAdapter.currentContext.timeouted = true; | ||
break; | ||
|
||
case bidResponse: | ||
adomikAdapter.bucketEvents.push({ | ||
type: 'response', | ||
event: adomikAdapter.buildBidResponse(args) | ||
}); | ||
break; | ||
|
||
case bidWon: | ||
adomikAdapter.bucketEvents.push({ | ||
type: 'winner', | ||
event: { | ||
id: args.adId, | ||
placementCode: args.adUnitCode | ||
} | ||
}); | ||
break; | ||
|
||
case bidRequested: | ||
args.bids.forEach(function(bid) { | ||
adomikAdapter.bucketEvents.push({ | ||
type: 'request', | ||
event: { | ||
bidder: bid.bidder.toUpperCase(), | ||
placementCode: bid.placementCode | ||
} | ||
}); | ||
}); | ||
break; | ||
|
||
case auctionEnd: | ||
setTimeout(() => { | ||
if (adomikAdapter.bucketEvents.length > 0) { | ||
adomikAdapter.sendTypedEvent(); | ||
} | ||
}, bidwonTimeout); | ||
break; | ||
} | ||
} | ||
} | ||
); | ||
|
||
adomikAdapter.sendTypedEvent = function() { | ||
const groupedTypedEvents = adomikAdapter.buildTypedEvents(); | ||
|
||
const bulkEvents = { | ||
uid: adomikAdapter.currentContext.uid, | ||
ahbaid: adomikAdapter.currentContext.id, | ||
timeout: adomikAdapter.currentContext.timeout, | ||
hostname: window.location.hostname, | ||
eventsByPlacementCode: groupedTypedEvents.map(function(typedEventsByType) { | ||
let sizes = []; | ||
const eventKeys = ['request', 'response', 'winner']; | ||
let events = {}; | ||
|
||
eventKeys.forEach((eventKey) => { | ||
events[`${eventKey}s`] = []; | ||
if (typedEventsByType[eventKey] !== undefined) { | ||
typedEventsByType[eventKey].forEach((typedEvent) => { | ||
if (typedEvent.event.size !== undefined) { | ||
const size = adomikAdapter.sizeUtils.handleSize(sizes, typedEvent.event.size); | ||
if (size !== null) { | ||
sizes = [...sizes, size]; | ||
} | ||
} | ||
events[`${eventKey}s`] = [...events[`${eventKey}s`], typedEvent.event]; | ||
}); | ||
} | ||
}); | ||
|
||
return { | ||
placementCode: typedEventsByType.placementCode, | ||
sizes, | ||
events | ||
}; | ||
}) | ||
}; | ||
|
||
// Encode object in base64 | ||
const encodedBuf = window.btoa(JSON.stringify(bulkEvents)); | ||
|
||
// Create final url and split it in 1600 characters max (+endpoint length) | ||
const encodedUri = encodeURIComponent(encodedBuf); | ||
const splittedUrl = encodedUri.match(/.{1,1600}/g); | ||
|
||
splittedUrl.forEach((split, i) => { | ||
const partUrl = `${split}&id=${adomikAdapter.currentContext.id}&part=${i}&on=${splittedUrl.length - 1}`; | ||
const img = new Image(1, 1); | ||
img.src = 'https://' + adomikAdapter.currentContext.url + '/?q=' + partUrl; | ||
}) | ||
}; | ||
|
||
adomikAdapter.buildBidResponse = function (bid) { | ||
return { | ||
bidder: bid.bidderCode.toUpperCase(), | ||
placementCode: bid.adUnitCode, | ||
id: bid.adId, | ||
status: (bid.statusMessage === 'Bid available') ? 'VALID' : 'EMPTY_OR_ERROR', | ||
cpm: parseFloat(bid.cpm), | ||
size: { | ||
width: Number(bid.width), | ||
height: Number(bid.height) | ||
}, | ||
timeToRespond: bid.timeToRespond, | ||
afterTimeout: adomikAdapter.currentContext.timeouted | ||
}; | ||
} | ||
|
||
adomikAdapter.sizeUtils = { | ||
sizeAlreadyExists: (sizes, typedEventSize) => { | ||
return sizes.find((size) => size.height === typedEventSize.height && size.width === typedEventSize.width); | ||
}, | ||
formatSize: (typedEventSize) => { | ||
return { | ||
width: Number(typedEventSize.width), | ||
height: Number(typedEventSize.height) | ||
}; | ||
}, | ||
handleSize: (sizes, typedEventSize) => { | ||
let formattedSize = null; | ||
if (adomikAdapter.sizeUtils.sizeAlreadyExists(sizes, typedEventSize) === undefined) { | ||
formattedSize = adomikAdapter.sizeUtils.formatSize(typedEventSize); | ||
} | ||
return formattedSize; | ||
} | ||
}; | ||
|
||
adomikAdapter.buildTypedEvents = function () { | ||
const groupedTypedEvents = []; | ||
adomikAdapter.bucketEvents.forEach(function(typedEvent, i) { | ||
const [placementCode, type] = [typedEvent.event.placementCode, typedEvent.type]; | ||
let existTypedEvent = groupedTypedEvents.findIndex((groupedTypedEvent) => groupedTypedEvent.placementCode === placementCode); | ||
|
||
if (existTypedEvent === -1) { | ||
groupedTypedEvents.push({ | ||
placementCode: placementCode, | ||
[type]: [typedEvent] | ||
}); | ||
existTypedEvent = groupedTypedEvents.length - 1; | ||
} | ||
|
||
if (groupedTypedEvents[existTypedEvent][type]) { | ||
groupedTypedEvents[existTypedEvent][type] = [...groupedTypedEvents[existTypedEvent][type], typedEvent]; | ||
} else { | ||
groupedTypedEvents[existTypedEvent][type] = [typedEvent]; | ||
} | ||
}); | ||
|
||
return groupedTypedEvents; | ||
} | ||
|
||
// Initialize adomik object | ||
adomikAdapter.currentContext = {}; | ||
adomikAdapter.bucketEvents = []; | ||
|
||
adomikAdapter.adapterEnableAnalytics = adomikAdapter.enableAnalytics; | ||
|
||
adomikAdapter.enableAnalytics = function (config) { | ||
const initOptions = config.options; | ||
if (initOptions) { | ||
adomikAdapter.currentContext = { | ||
uid: initOptions.id, | ||
url: initOptions.url, | ||
debug: initOptions.debug, | ||
id: '', | ||
timeouted: false, | ||
timeout: 0, | ||
} | ||
adomikAdapter.adapterEnableAnalytics(config); | ||
} | ||
}; | ||
|
||
adaptermanager.registerAnalyticsAdapter({ | ||
adapter: adomikAdapter, | ||
code: 'adomik' | ||
}); | ||
|
||
export default adomikAdapter; |
Oops, something went wrong.