Skip to content

Commit

Permalink
CRITEO RTUS Integration with Yieldmo Prebid (#5075)
Browse files Browse the repository at this point in the history
* update maintainer email

* add stringified schain

* Revert "add stringified schain"

This reverts commit 4fd8634.

* pass along gdpr consent string and gdpr applies through get

* use paramter gdprConsent

* add stringified schain

* don't change other files

* change parameter namves

* updates bidder module to be 3.0 compliant, and tests

* deletes openxoutstream adapter

* fix broken yieldmo test

* remove log

* remove utils functions that will be depricated in 3.0 and use new referer object in bidderRequest

* use prebids gettopwindow util functions. update markdown with 3.0 compliant ad units object

* Pass along us_privacy string

* remove blank.min

* Fix unit tests and remove unused variables and methods

* add stringified schain

* add stringified schain

* Revert "add stringified schain"

This reverts commit 4fd8634.

* pass along gdpr consent string and gdpr applies through get

* use paramter gdprConsent

* don't change other files

* change parameter namves

* updates bidder module to be 3.0 compliant, and tests

* deletes openxoutstream adapter

* fix broken yieldmo test

* remove log

* remove utils functions that will be depricated in 3.0 and use new referer object in bidderRequest

* use prebids gettopwindow util functions. update markdown with 3.0 compliant ad units object

* Pass along us_privacy string

* update maintainer email

* add stringified schain

* Revert "add stringified schain"

This reverts commit 4fd8634.

* add stringified schain

* don't change other files

* change parameter namves

* updates bidder module to be 3.0 compliant, and tests

* fix broken yieldmo test

* remove utils functions that will be depricated in 3.0 and use new referer object in bidderRequest

* use prebids gettopwindow util functions. update markdown with 3.0 compliant ad units object

* Pass along us_privacy string

* Clean up console

* Do not undo my featureeee

* CRITEO RTUS For prebid

* Tests for CRITEO RTUS For prebid

* Revert "Do not undo my featureeee"

This reverts commit 0185407.

* linting

* add test back in:

Co-authored-by: Melody Li <melodyli@ip-192-168-2-119.ec2.internal>
Co-authored-by: Elber Carneiro <elber@yieldmo.com>
Co-authored-by: Elber Carneiro <elberdev@gmail.com>
Co-authored-by: Melody Li <melody@yieldmo.com>
Co-authored-by: Melody Li <ml867@cornell.edu>
Co-authored-by: Andrew Holz <holz.andrew@gmail.com>
Co-authored-by: Michal <mike@lamiglo.com>
  • Loading branch information
8 people authored Apr 8, 2020
1 parent c61a2b9 commit 925ae0a
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 110 deletions.
114 changes: 71 additions & 43 deletions modules/yieldmoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: ['banner'],
/**
* Determines whether or not the given bid request is valid.
* @param {object} bid, bid to validate
* @return boolean, true if valid, otherwise false
*/
* Determines whether or not the given bid request is valid.
* @param {object} bid, bid to validate
* @return boolean, true if valid, otherwise false
*/
isBidRequestValid: function(bid) {
return !!(bid && bid.adUnitCode && bid.bidId);
},
Expand All @@ -41,13 +41,19 @@ export const spec = {
h: localWindow.innerHeight,
userConsent: JSON.stringify({
// case of undefined, stringify will remove param
gdprApplies: bidderRequest && bidderRequest.gdprConsent ? bidderRequest.gdprConsent.gdprApplies : undefined,
cmp: bidderRequest && bidderRequest.gdprConsent ? bidderRequest.gdprConsent.consentString : undefined
gdprApplies:
bidderRequest && bidderRequest.gdprConsent
? bidderRequest.gdprConsent.gdprApplies
: undefined,
cmp:
bidderRequest && bidderRequest.gdprConsent
? bidderRequest.gdprConsent.consentString
: undefined
}),
us_privacy: bidderRequest && bidderRequest.us_privacy,
us_privacy: bidderRequest && bidderRequest.us_privacy
};

bidRequests.forEach((request) => {
bidRequests.forEach(request => {
serverRequest.p.push(addPlacement(request));
const pubcid = getId(request, 'pubcid');
if (pubcid) {
Expand All @@ -61,6 +67,10 @@ export const spec = {
if (tdid) {
serverRequest.tdid = tdid;
}
const criteoId = getId(request, 'criteoId');
if (criteoId) {
serverRequest.cri_prebid = criteoId;
}
if (request.schain) {
serverRequest.schain = JSON.stringify(request.schain);
}
Expand All @@ -70,7 +80,7 @@ export const spec = {
method: 'GET',
url: SERVER_ENDPOINT,
data: serverRequest
}
};
},
/**
* Makes Yieldmo Ad Server response compatible to Prebid specs
Expand All @@ -81,7 +91,7 @@ export const spec = {
let bids = [];
let data = serverResponse.body;
if (data.length > 0) {
data.forEach((response) => {
data.forEach(response => {
if (response.cpm && response.cpm > 0) {
bids.push(createNewBid(response));
}
Expand All @@ -91,15 +101,17 @@ export const spec = {
},
getUserSync: function(syncOptions) {
if (trackingEnabled(syncOptions)) {
return [{
type: 'iframe',
url: SYNC_ENDPOINT + utils.getOrigin()
}];
return [
{
type: 'iframe',
url: SYNC_ENDPOINT + utils.getOrigin()
}
];
} else {
return [];
}
}
}
};
registerBidder(spec);

/***************************************
Expand All @@ -115,7 +127,7 @@ function addPlacement(request) {
placement_id: request.adUnitCode,
callback_id: request.bidId,
sizes: request.mediaTypes.banner.sizes
}
};
if (request.params) {
if (request.params.placementId) {
placementInfo.ym_placement_id = request.params.placementId;
Expand All @@ -128,9 +140,9 @@ function addPlacement(request) {
}

/**
* creates a new bid with response information
* @param response server response
*/
* creates a new bid with response information
* @param response server response
*/
function createNewBid(response) {
return {
requestId: response['callback_id'],
Expand All @@ -150,31 +162,35 @@ function createNewBid(response) {
* @returns false if dnt or if not iframe/pixel enabled
*/
function trackingEnabled(options) {
return (isIOS() && !getDNT() && options.iframeEnabled);
return isIOS() && !getDNT() && options.iframeEnabled;
}

/**
* Detects whether we're in iOS
* @returns true if in iOS
*/
* Detects whether we're in iOS
* @returns true if in iOS
*/
function isIOS() {
return /iPhone|iPad|iPod/i.test(window.navigator.userAgent);
}

/**
* Detects whether dnt is true
* @returns true if user enabled dnt
*/
* Detects whether dnt is true
* @returns true if user enabled dnt
*/
function getDNT() {
return window.doNotTrack === '1' || window.navigator.doNotTrack === '1' || false;
return (
window.doNotTrack === '1' || window.navigator.doNotTrack === '1' || false
);
}

/**
* get page description
*/
function getPageDescription() {
if (document.querySelector('meta[name="description"]')) {
return document.querySelector('meta[name="description"]').getAttribute('content'); // Value of the description metadata from the publisher's page.
return document
.querySelector('meta[name="description"]')
.getAttribute('content'); // Value of the description metadata from the publisher's page.
} else {
return '';
}
Expand All @@ -200,9 +216,9 @@ function getPageDescription() {
*/

/**
* Detects what environment we're in
* @returns Environment kind
*/
* Detects what environment we're in
* @returns Environment kind
*/
function getEnvironment() {
if (isSuperSandboxedIframe()) {
return 89;
Expand All @@ -228,28 +244,31 @@ function getEnvironment() {
}

/**
* @returns true if we are running on the top window at dispatch time
*/
* @returns true if we are running on the top window at dispatch time
*/
function isCodeOnPage() {
return window === window.parent;
}

/**
* @returns true if the environment is both DFP and AMP
*/
* @returns true if the environment is both DFP and AMP
*/
function isDfpInAmp() {
return isDfp() && isAmp();
}

/**
* @returns true if the window is in an iframe whose id and parent element id match DFP
*/
* @returns true if the window is in an iframe whose id and parent element id match DFP
*/
function isDfp() {
try {
const frameElement = window.frameElement;
const parentElement = window.frameElement.parentNode;
if (frameElement && parentElement) {
return frameElement.id.indexOf('google_ads_iframe') > -1 && parentElement.id.indexOf('google_ads_iframe') > -1;
return (
frameElement.id.indexOf('google_ads_iframe') > -1 &&
parentElement.id.indexOf('google_ads_iframe') > -1
);
}
return false;
} catch (e) {
Expand All @@ -258,8 +277,8 @@ function isDfp() {
}

/**
* @returns true if there is an AMP context object
*/
* @returns true if there is an AMP context object
*/
function isAmp() {
try {
const ampContext = window.context || window.parent.context;
Expand All @@ -285,7 +304,11 @@ function isSafeFrame() {
function isDFPSafeFrame() {
if (window.location && window.location.href) {
const href = window.location.href;
return isSafeFrame() && href.indexOf('google') !== -1 && href.indexOf('safeframe') !== -1;
return (
isSafeFrame() &&
href.indexOf('google') !== -1 &&
href.indexOf('safeframe') !== -1
);
}
return false;
}
Expand Down Expand Up @@ -318,7 +341,7 @@ function isSuperSandboxedIframe() {
* @returns true if the window has the attribute identifying MRAID
*/
function isMraid() {
return !!(window.mraid);
return !!window.mraid;
}

/**
Expand All @@ -329,7 +352,12 @@ function isMraid() {
*/
function getId(request, idType) {
let id;
if (request && request.userId && request.userId[idType] && typeof request.userId === 'object') {
if (
request &&
request.userId &&
request.userId[idType] &&
typeof request.userId === 'object'
) {
id = request.userId[idType];
}
return id;
Expand Down
1 change: 1 addition & 0 deletions modules/yieldmoBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Module Name: Yieldmo Bid Adapter
Module Type: Bidder Adapter
Maintainer: opensource@yieldmo.com
Note: Our ads will only render in mobile
```

# Description
Expand Down
Loading

0 comments on commit 925ae0a

Please sign in to comment.