This repository has been archived by the owner on Feb 13, 2021. It is now read-only.
forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request prebid#128 in AOLP_ADS_JS/prebid.js from release/1…
….30.0 to aolgithub-master * commit '5a8d2bf93ee15071a78e24ac976103cacf3c6021': (35 commits) Added changelog entry. Prebid 0.30.1 Release Remove undefined variable usage (prebid#1662) fixes bug for IE when invalid value passed to parse (prebid#1657) Aliasbidder fix (prebid#1652) prebidAdapter secure support (prebid#1655) Increment pre version Prebid 0.30.0 Release Add native param support to mediaTypes (prebid#1625) PulsePoint Lite adpater changes (prebid#1630) Appnexus ast unittest updates (prebid#1654) Support aspect ratio specification for native images (prebid#1634) Revert changes for switch between client side and server side. (prebid#1653) rubicon converted to bidderFactory (prebid#1624) Add JSDoc for `pbjs.getAllWinningBids` (prebid#1566) Add ignore-loader to handle .md files (prebid#1646) fixed PBS cookie syncs (prebid#1637) Add placementId request param to Yieldmo bid adapter (prebid#1632) Adxcg analytics adapter (prebid#1599) Add publisher sub-id support to the Criteo adapter (prebid#1629) ...
- Loading branch information
Showing
54 changed files
with
2,157 additions
and
1,327 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
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; |
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,94 @@ | ||
import {ajax} from 'src/ajax'; | ||
import adapter from 'src/AnalyticsAdapter'; | ||
import adaptermanager from 'src/adaptermanager'; | ||
import * as url from 'src/url'; | ||
import * as utils from 'src/utils'; | ||
|
||
const emptyUrl = ''; | ||
const analyticsType = 'endpoint'; | ||
const adxcgAnalyticsVersion = 'v1.04'; | ||
|
||
let initOptions; | ||
let auctionTimestamp; | ||
let events = { | ||
bidRequests: [], | ||
bidResponses: [] | ||
}; | ||
|
||
var adxcgAnalyticsAdapter = Object.assign(adapter( | ||
{ | ||
emptyUrl, | ||
analyticsType | ||
}), { | ||
track({eventType, args}) { | ||
if (typeof args !== 'undefined') { | ||
if (eventType === 'bidTimeout') { | ||
events.bidTimeout = args; | ||
} else if (eventType === 'auctionInit') { | ||
events.auctionInit = args; | ||
auctionTimestamp = args.timestamp; | ||
} else if (eventType === 'bidRequested') { | ||
events.bidRequests.push(args); | ||
} else if (eventType === 'bidResponse') { | ||
events.bidResponses.push(mapBidResponse(args)); | ||
} else if (eventType === 'bidWon') { | ||
send({ | ||
bidWon: mapBidResponse(args) | ||
}); | ||
} | ||
} | ||
|
||
if (eventType === 'auctionEnd') { | ||
send(events); | ||
} | ||
} | ||
}); | ||
|
||
function mapBidResponse(bidResponse) { | ||
return { | ||
adUnitCode: bidResponse.adUnitCode, | ||
statusMessage: bidResponse.statusMessage, | ||
bidderCode: bidResponse.bidderCode, | ||
adId: bidResponse.adId, | ||
mediaType: bidResponse.mediaType, | ||
creative_id: bidResponse.creative_id, | ||
width: bidResponse.width, | ||
height: bidResponse.height, | ||
cpm: bidResponse.cpm, | ||
timeToRespond: bidResponse.timeToRespond | ||
}; | ||
} | ||
|
||
function send(data) { | ||
data.initOptions = initOptions; | ||
data.auctionTimestamp = auctionTimestamp; | ||
|
||
let location = utils.getTopWindowLocation(); | ||
let secure = location.protocol == 'https:'; | ||
|
||
let adxcgAnalyticsRequestUrl = url.format({ | ||
protocol: secure ? 'https' : 'http', | ||
hostname: secure ? 'hbarxs.adxcg.net' : 'hbarx.adxcg.net', | ||
pathname: '/pbrx', | ||
search: { | ||
auctionTimestamp: auctionTimestamp, | ||
adxcgAnalyticsVersion: adxcgAnalyticsVersion, | ||
prebidVersion: $$PREBID_GLOBAL$$.version | ||
} | ||
}); | ||
|
||
ajax(adxcgAnalyticsRequestUrl, undefined, JSON.stringify(data), {method: 'POST'}); | ||
} | ||
|
||
adxcgAnalyticsAdapter.originEnableAnalytics = adxcgAnalyticsAdapter.enableAnalytics; | ||
adxcgAnalyticsAdapter.enableAnalytics = function (config) { | ||
initOptions = config.options; | ||
adxcgAnalyticsAdapter.originEnableAnalytics(config); | ||
}; | ||
|
||
adaptermanager.registerAnalyticsAdapter({ | ||
adapter: adxcgAnalyticsAdapter, | ||
code: 'adxcg' | ||
}); | ||
|
||
export default adxcgAnalyticsAdapter; |
Oops, something went wrong.