-
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
Aardvark v1.0 #2507
Merged
Merged
Aardvark v1.0 #2507
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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,158 @@ | ||
import * as utils from 'src/utils'; | ||
import {registerBidder} from 'src/adapters/bidderFactory'; | ||
|
||
const BIDDER_CODE = 'aardvark'; | ||
const DEFAULT_ENDPOINT = 'bidder.rtk.io'; | ||
const SYNC_ENDPOINT = 'sync.rtk.io'; | ||
const AARDVARK_TTL = 300; | ||
const AARDVARK_CURRENCY = 'USD'; | ||
|
||
let hasSynced = false; | ||
|
||
export function resetUserSync() { | ||
hasSynced = false; | ||
} | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
|
||
isBidRequestValid: function(bid) { | ||
return ((typeof bid.params.ai === 'string') && !!bid.params.ai.length && | ||
(typeof bid.params.sc === 'string') && !!bid.params.sc.length); | ||
}, | ||
|
||
buildRequests: function(validBidRequests, bidderRequest) { | ||
var auctionCodes = []; | ||
var requests = []; | ||
var requestsMap = {}; | ||
var referer = utils.getTopWindowUrl(); | ||
var pageCategories = []; | ||
|
||
if (window.top.rtkcategories && Array.isArray(window.top.rtkcategories)) { | ||
pageCategories = window.top.rtkcategories; | ||
} | ||
|
||
utils._each(validBidRequests, function(b) { | ||
var rMap = requestsMap[b.params.ai]; | ||
if (!rMap) { | ||
rMap = { | ||
shortCodes: [], | ||
payload: { | ||
version: 1, | ||
jsonp: false, | ||
rtkreferer: referer | ||
}, | ||
endpoint: DEFAULT_ENDPOINT | ||
}; | ||
|
||
if (pageCategories && pageCategories.length) { | ||
rMap.payload.categories = pageCategories.slice(0); | ||
} | ||
|
||
if (b.params.categories && b.params.categories.length) { | ||
rMap.payload.categories = rMap.payload.categories || [] | ||
utils._each(b.params.categories, function(cat) { | ||
rMap.payload.categories.push(cat); | ||
}); | ||
} | ||
|
||
if (bidderRequest && bidderRequest.gdprConsent) { | ||
rMap.payload.gdpr = false; | ||
if (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') { | ||
rMap.payload.gdpr = bidderRequest.gdprConsent.gdprApplies; | ||
} | ||
if (rMap.payload.gdpr) { | ||
rMap.payload.consent = bidderRequest.gdprConsent.consentString; | ||
} | ||
} | ||
|
||
requestsMap[b.params.ai] = rMap; | ||
auctionCodes.push(b.params.ai); | ||
} | ||
|
||
rMap.shortCodes.push(b.params.sc); | ||
rMap.payload[b.params.sc] = b.bidId; | ||
|
||
if ((typeof b.params.host === 'string') && b.params.host.length && | ||
(b.params.host !== rMap.endpoint)) { | ||
rMap.endpoint = b.params.host; | ||
} | ||
}); | ||
|
||
utils._each(auctionCodes, function(auctionId) { | ||
var req = requestsMap[auctionId]; | ||
requests.push({ | ||
method: 'GET', | ||
url: `//${req.endpoint}/${auctionId}/${req.shortCodes.join('_')}/aardvark`, | ||
data: req.payload, | ||
bidderRequest | ||
}); | ||
}); | ||
|
||
return requests; | ||
}, | ||
|
||
interpretResponse: function(serverResponse, bidRequest) { | ||
var bidResponses = []; | ||
utils._each(serverResponse.body, function(rawBid) { | ||
if (!rawBid.cpm || !(+rawBid.cpm)) { | ||
return; | ||
} | ||
|
||
var bidResponse = { | ||
requestId: rawBid.cid, | ||
cpm: rawBid.cpm, | ||
width: rawBid.width || 0, | ||
height: rawBid.height || 0, | ||
currency: rawBid.currency ? rawBid.currency : AARDVARK_CURRENCY, | ||
netRevenue: rawBid.netRevenue ? rawBid.netRevenue : true, | ||
ttl: rawBid.ttl ? rawBid.ttl : AARDVARK_TTL, | ||
creativeId: rawBid.creativeId || 0 | ||
}; | ||
|
||
if (rawBid.hasOwnProperty('dealId')) { | ||
bidResponse.dealId = rawBid.dealId | ||
} | ||
|
||
switch (rawBid.media) { | ||
case 'banner': | ||
bidResponse.ad = rawBid.adm + utils.createTrackPixelHtml(decodeURIComponent(rawBid.nurl)); | ||
break; | ||
|
||
default: | ||
return utils.logError('bad Aardvark response (media)', rawBid); | ||
} | ||
|
||
bidResponses.push(bidResponse); | ||
}); | ||
|
||
return bidResponses; | ||
}, | ||
|
||
getUserSyncs: function(syncOptions, serverResponses, gdprConsent) { | ||
const syncs = []; | ||
var url = '//' + SYNC_ENDPOINT + '/cs'; | ||
var gdprApplies = false; | ||
if (gdprConsent && (typeof gdprConsent.gdprApplies === 'boolean')) { | ||
gdprApplies = gdprConsent.gdprApplies; | ||
} | ||
|
||
if (syncOptions.iframeEnabled) { | ||
if (!hasSynced) { | ||
hasSynced = true; | ||
if (gdprApplies) { | ||
url = url + '?g=1&c=' + encodeURIComponent(gdprConsent.consentString); | ||
} | ||
syncs.push({ | ||
type: 'iframe', | ||
url: url | ||
}); | ||
} | ||
} else { | ||
utils.logWarn('Aardvark: Please enable iframe based user sync.'); | ||
} | ||
return syncs; | ||
} | ||
}; | ||
|
||
registerBidder(spec); |
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,30 @@ | ||
# Overview | ||
|
||
**Module Name**: Aardvark Bidder Adapter | ||
**Module Type**: Bidder Adapter | ||
**Maintainer**: chris@rtk.io | ||
|
||
# Description | ||
|
||
Module that connects to a RTK.io Ad Units to fetch bids. | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [{ | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[300, 250]], | ||
} | ||
}, | ||
code: 'div-gpt-ad-1460505748561-0', | ||
|
||
bids: [{ | ||
bidder: 'aardvark', | ||
params: { | ||
ai: '0000', | ||
sc: '1234' | ||
} | ||
}] | ||
|
||
}]; | ||
``` |
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 you review the logic in using this
utils._each
function? It's currently iterating through each of the properties of the response object and evaluating them each as an entire bid object.This is a copy of the bid response object that I saw when I tested and it treated
rawBid
asdemo_exchange
(from theex
field) during the first pass of the function.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.
We've been updating the demo auction today, sorry about that. That is an array returned from our endpoint, so it gets iterated over as an array, not a map. It is now an array as it should be.