-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
OFF-465 Add getUserKey logic to prebid.js adapter #3
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import {isEmpty, parseUrl} from '../src/utils.js'; | ||
import {isEmpty, parseUrl, triggerPixel} from '../src/utils.js'; | ||
import { registerBidder } from '../src/adapters/bidderFactory.js'; | ||
import { BANNER } from '../src/mediaTypes.js'; | ||
import {getStorageManager} from '../src/storageManager.js'; | ||
|
||
const NETWORK_ID = 11090; | ||
const AD_TYPES = [4309, 641]; | ||
const DTX_TYPES = [5061]; | ||
|
@@ -12,6 +14,61 @@ const DEFAULT_CURRENCY = 'USD'; | |
const DEFAULT_CREATIVE_TYPE = 'NativeX'; | ||
const VALID_CREATIVE_TYPES = ['DTX', 'NativeX']; | ||
|
||
let userKey = null; | ||
let cookieSynced = false; | ||
export const storage = getStorageManager({bidderCode: BIDDER_CODE}); | ||
|
||
const syncUserKey = (userKey) => { | ||
if (!cookieSynced) { | ||
triggerPixel(`https://idsync.rlcdn.com/712559.gif?partner_uid=${userKey}`); | ||
cookieSynced = true; | ||
} | ||
}; | ||
|
||
export function getUserKey(options = {}) { | ||
if (userKey) { | ||
syncUserKey(userKey); | ||
return userKey; | ||
} | ||
|
||
// If the partner provides the user key use it, otherwise fallback to cookies | ||
if ('userKey' in options && options.userKey) { | ||
if (isValidUserKey(options.userKey)) { | ||
userKey = options.userKey; | ||
syncUserKey(userKey); | ||
return options.userKey; | ||
} | ||
} | ||
|
||
const FLIPP_USER_KEY = 'flipp-uid'; | ||
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. I think we should put all constants on the top |
||
|
||
// Grab from Cookie | ||
const foundUserKey = storage.cookiesAreEnabled() && storage.getCookie(FLIPP_USER_KEY); | ||
if (foundUserKey) { | ||
syncUserKey(foundUserKey); | ||
return foundUserKey; | ||
} | ||
|
||
// Generate if none found | ||
userKey = generateUUID(); | ||
|
||
if (!userKey) { | ||
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. Is it possible that it will be some empty value? 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. I think it's ok to have empty user key if everything fails, kevel request would still work without a key 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. Perhaps I haven't described well, I meant in general, do we need this check rather then what's the default value of this condition. 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. You're right, just removed the check |
||
return null; | ||
} | ||
|
||
// Set cookie | ||
if (storage.cookiesAreEnabled()) { | ||
storage.setCookie(FLIPP_USER_KEY, userKey); | ||
} | ||
|
||
syncUserKey(userKey); | ||
return userKey; | ||
} | ||
|
||
function isValidUserKey(userKey) { | ||
return !userKey.startsWith('#'); | ||
} | ||
|
||
const generateUUID = () => { | ||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => { | ||
const r = (Math.random() * 16) | 0; | ||
|
@@ -63,7 +120,7 @@ export const spec = { | |
buildRequests: function(validBidRequests, bidderRequest) { | ||
const urlParams = parseUrl(bidderRequest.refererInfo.page).search; | ||
const contentCode = urlParams['flipp-content-code']; | ||
const userKey = isEmpty(validBidRequests[0]?.params.userKey) ? generateUUID() : validBidRequests[0]?.params.userKey; | ||
const userKey = getUserKey(validBidRequests[0]?.params); | ||
const placements = validBidRequests.map((bid, index) => { | ||
return { | ||
divName: TARGET_NAME, | ||
|
@@ -76,11 +133,11 @@ export const spec = { | |
...(!isEmpty(contentCode) && {contentCode: contentCode.slice(0, 32)}), | ||
}, | ||
prebid: { | ||
creativeType: validateCreativeType(bid.params.creativeType), | ||
requestId: bid.bidId, | ||
publisherNameIdentifier: bid.params.publisherNameIdentifier, | ||
height: bid.mediaTypes.banner.sizes[index][0], | ||
width: bid.mediaTypes.banner.sizes[index][1], | ||
creativeType: validateCreativeType(bid.params.creativeType), | ||
} | ||
} | ||
}); | ||
|
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.