-
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
bidWatch Analytics Adapter : add creative endpoint #8710
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
93dec77
New Analytics Adapter bidwatch
matthieularere-msq aa6107b
test for bidwatch Analytics Adapter
matthieularere-msq 5e6e3d1
change maintainer address
matthieularere-msq 706d98b
Update bidwatchAnalyticsAdapter.js
matthieularere-msq 54348a1
Update bidwatchAnalyticsAdapter.js
matthieularere-msq 6cfbb13
Update bidwatchAnalyticsAdapter.md
matthieularere-msq 4e4eeb6
Update bidwatchAnalyticsAdapter.md
matthieularere-msq 5ce4407
Merge branch 'prebid:master' into master
matthieularere-msq 3389271
add features to bidwatchAnalyticsAdapter
matthieularere-msq 8df3521
update tests
matthieularere-msq 3eb1a6d
add test and made improvements
matthieularere-msq 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 |
---|---|---|
|
@@ -10,10 +10,14 @@ const { | |
EVENTS: { | ||
AUCTION_END, | ||
BID_WON, | ||
BID_RESPONSE, | ||
BID_REQUESTED, | ||
} | ||
} = CONSTANTS; | ||
|
||
let saveEvents = {} | ||
let allEvents = {} | ||
let auctionEnd = {} | ||
let initOptions = {} | ||
let endpoint = 'https://default' | ||
let objectToSearchForBidderCode = ['bidderRequests', 'bidsReceived', 'noBids'] | ||
|
@@ -22,53 +26,108 @@ function getAdapterNameForAlias(aliasName) { | |
return adapterManager.aliasRegistry[aliasName] || aliasName; | ||
} | ||
|
||
function setOriginalBidder(arg) { | ||
function cleanArgObject(arg, removead) { | ||
if (typeof arg['bidderCode'] == 'string') { arg['originalBidder'] = getAdapterNameForAlias(arg['bidderCode']); } | ||
if (typeof arg['creativeId'] == 'number') { | ||
arg['creativeId'] = arg['creativeId'].toString(); | ||
} | ||
if (removead && typeof arg['ad'] != 'undefined') { | ||
arg['ad'] = 'emptied'; | ||
} | ||
if (typeof arg['gdprConsent'] != 'undefined' && typeof arg['gdprConsent']['vendorData'] != 'undefined') { | ||
arg['gdprConsent']['vendorData'] = 'emptied'; | ||
} | ||
return arg; | ||
} | ||
|
||
function cleanArgs(arg, removead) { | ||
Object.keys(arg).forEach(key => { | ||
arg[key]['originalBidder'] = getAdapterNameForAlias(arg[key]['bidderCode']); | ||
if (typeof arg[key]['creativeId'] == 'number') { arg[key]['creativeId'] = arg[key]['creativeId'].toString(); } | ||
arg[key] = cleanArgObject(arg[key], removead); | ||
}); | ||
return arg | ||
} | ||
|
||
function checkBidderCode(args) { | ||
function checkBidderCode(args, removead) { | ||
if (typeof args == 'object') { | ||
for (let i = 0; i < objectToSearchForBidderCode.length; i++) { | ||
if (typeof args[objectToSearchForBidderCode[i]] == 'object') { args[objectToSearchForBidderCode[i]] = setOriginalBidder(args[objectToSearchForBidderCode[i]]) } | ||
if (typeof args[objectToSearchForBidderCode[i]] == 'object') { args[objectToSearchForBidderCode[i]] = cleanArgs(args[objectToSearchForBidderCode[i]], removead) } | ||
} | ||
} | ||
if (typeof args['bidderCode'] == 'string') { args['originalBidder'] = getAdapterNameForAlias(args['bidderCode']); } else if (typeof args['bidder'] == 'string') { args['originalBidder'] = getAdapterNameForAlias(args['bidder']); } | ||
if (typeof args['creativeId'] == 'number') { args['creativeId'] = args['creativeId'].toString(); } | ||
|
||
return args | ||
} | ||
|
||
function addEvent(eventType, args) { | ||
if (allEvents[eventType] == undefined) { allEvents[eventType] = [] } | ||
if (eventType && args) { args = checkBidderCode(args); } | ||
allEvents[eventType].push(args); | ||
let argsCleaned; | ||
if (eventType && args) { | ||
if (allEvents[eventType] == undefined) { allEvents[eventType] = [] } | ||
if (saveEvents[eventType] == undefined) { saveEvents[eventType] = [] } | ||
argsCleaned = checkBidderCode(JSON.parse(JSON.stringify(args)), false); | ||
allEvents[eventType].push(argsCleaned); | ||
saveEvents[eventType].push(argsCleaned); | ||
argsCleaned = checkBidderCode(JSON.parse(JSON.stringify(args)), true); | ||
if (['auctionend', 'bidtimeout'].includes(eventType.toLowerCase())) { | ||
if (auctionEnd[eventType] == undefined) { auctionEnd[eventType] = [] } | ||
auctionEnd[eventType].push(argsCleaned); | ||
} | ||
} | ||
} | ||
|
||
function handleBidWon(args) { | ||
if (typeof allEvents.bidRequested == 'object' && allEvents.bidRequested.length > 0 && allEvents.bidRequested[0].gdprConsent) { args.gdpr = allEvents.bidRequested[0].gdprConsent; } | ||
args = cleanArgObject(JSON.parse(JSON.stringify(args)), true); | ||
let increment = args['cpm']; | ||
if (typeof saveEvents['auctionEnd'] == 'object') { | ||
for (let i = 0; i < saveEvents['auctionEnd'].length; i++) { | ||
let tmpAuction = saveEvents['auctionEnd'][i]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these types of loops would look a bit cleaner as
or
Although I think |
||
if (tmpAuction['auctionId'] == args['auctionId'] && typeof tmpAuction['bidsReceived'] == 'object') { | ||
for (let j = 0; j < tmpAuction['bidsReceived'].length; j++) { | ||
let tmpBid = tmpAuction['bidsReceived'][j]; | ||
if (tmpBid['transactionId'] == args['transactionId'] && tmpBid['adId'] != args['adId']) { | ||
if (args['cpm'] < tmpBid['cpm']) { | ||
increment = 0; | ||
} else if (increment > args['cpm'] - tmpBid['cpm']) { | ||
increment = args['cpm'] - tmpBid['cpm']; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
args['cpmIncrement'] = increment; | ||
if (typeof saveEvents.bidRequested == 'object' && saveEvents.bidRequested.length > 0 && saveEvents.bidRequested[0].gdprConsent) { args.gdpr = saveEvents.bidRequested[0].gdprConsent; } | ||
ajax(endpoint + '.bidwatch.io/analytics/bid_won', null, JSON.stringify(args), {method: 'POST', withCredentials: true}); | ||
} | ||
|
||
function handleAuctionEnd() { | ||
ajax(endpoint + '.bidwatch.io/analytics/auctions', null, JSON.stringify(allEvents), {method: 'POST', withCredentials: true}); | ||
ajax(endpoint + '.bidwatch.io/analytics/auctions', null, JSON.stringify(auctionEnd), {method: 'POST', withCredentials: true}); | ||
auctionEnd = {} | ||
if (typeof allEvents['bidResponse'] != 'undefined') { | ||
for (let i = 0; i < allEvents['bidResponse'].length; i++) { ajax(endpoint + '.bidwatch.io/analytics/creatives', null, JSON.stringify(allEvents['bidResponse'][i]), {method: 'POST', withCredentials: true}); } | ||
} | ||
allEvents = {} | ||
} | ||
|
||
let bidwatchAnalytics = Object.assign(adapter({url, analyticsType}), { | ||
track({ | ||
eventType, | ||
args | ||
}) { | ||
addEvent(eventType, args); | ||
switch (eventType) { | ||
case AUCTION_END: | ||
addEvent(eventType, args); | ||
handleAuctionEnd(); | ||
break; | ||
case BID_WON: | ||
handleBidWon(args); | ||
break; | ||
case BID_RESPONSE: | ||
addEvent(eventType, args); | ||
break; | ||
case BID_REQUESTED: | ||
addEvent(eventType, args); | ||
break; | ||
} | ||
}}); | ||
|
||
|
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
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.
IMO it'd be better to explicitly list what to keep rather than what to remove. As more features are added your payload will probably continue to grow, and I can't imagine new, unrecognized fields being too useful on your end. It would also make it less likely that we'd accidentally rename or remove some field that is important to you, because a simple code search will show us what you are depending on.
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.
Thanks for the suggestion @dgirardi
I am no javascript specialist so I often go to the easiest way I know without searching for subtilities. As I have another PR to send very shortly I'll make the suggested changes with this next one.