-
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
mgid bid adapters: refactoring for trimmer code #12057
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0ea3566
added consts for values
26c051f
added copy method
2b35da4
moved extractDomainFromHost
4bf6bc4
added method triggerNurlWithCpm
9354d05
added getUserSyncs
4a4e595
less formatting mgidBid
b05dd61
less formatting undertoneBid
3f8ef11
less formatting utils
60108e6
renamed adm to nativeAdm
df55f3d
back changes for other adaptes
dfc2a7e
back changes
1a4061a
moved getUserSyncs to lib pkg
6c4f36f
less changes
b4c9026
fixed errors
ef4020a
less changes
d762540
fixed errors
e39369c
fixed tests
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,73 @@ | ||
import { | ||
isPlainObject, | ||
isArray, | ||
isStr, | ||
isNumber, | ||
} from '../../src/utils.js'; | ||
import { config } from '../../src/config.js'; | ||
import { USERSYNC_DEFAULT_CONFIG } from '../../src/userSync.js'; | ||
|
||
const PIXEL_SYNC_URL = 'https://cm.mgid.com/i.gif'; | ||
const IFRAME_SYNC_URL = 'https://cm.mgid.com/i.html'; | ||
|
||
export function getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent, gppConsent) { | ||
const spb = isPlainObject(config.getConfig('userSync')) && | ||
isNumber(config.getConfig('userSync').syncsPerBidder) | ||
? config.getConfig('userSync').syncsPerBidder : USERSYNC_DEFAULT_CONFIG.syncsPerBidder; | ||
|
||
if (spb > 0 && isPlainObject(syncOptions) && (syncOptions.iframeEnabled || syncOptions.pixelEnabled)) { | ||
let pixels = []; | ||
if (serverResponses && | ||
isArray(serverResponses) && | ||
serverResponses.length > 0 && | ||
isPlainObject(serverResponses[0].body) && | ||
isPlainObject(serverResponses[0].body.ext) && | ||
isArray(serverResponses[0].body.ext.cm) && | ||
serverResponses[0].body.ext.cm.length > 0) { | ||
pixels = serverResponses[0].body.ext.cm; | ||
} | ||
|
||
const syncs = []; | ||
const query = []; | ||
query.push('cbuster={cbuster}'); | ||
query.push('gdpr_consent=' + encodeURIComponent(isPlainObject(gdprConsent) && isStr(gdprConsent?.consentString) ? gdprConsent.consentString : '')); | ||
if (isPlainObject(gdprConsent) && typeof gdprConsent?.gdprApplies === 'boolean' && gdprConsent.gdprApplies) { | ||
query.push('gdpr=1'); | ||
} else { | ||
query.push('gdpr=0'); | ||
} | ||
if (isPlainObject(uspConsent) && uspConsent?.consentString) { | ||
query.push(`us_privacy=${encodeURIComponent(uspConsent?.consentString)}`); | ||
} | ||
if (isPlainObject(gppConsent) && gppConsent?.gppString) { | ||
query.push(`gppString=${encodeURIComponent(gppConsent?.gppString)}`); | ||
} | ||
if (config.getConfig('coppa')) { | ||
query.push('coppa=1') | ||
} | ||
const q = query.join('&') | ||
if (syncOptions.iframeEnabled) { | ||
syncs.push({ | ||
type: 'iframe', | ||
url: IFRAME_SYNC_URL + '?' + q.replace('{cbuster}', Math.round(new Date().getTime())) | ||
}); | ||
} else if (syncOptions.pixelEnabled) { | ||
if (pixels.length === 0) { | ||
for (let i = 0; i < spb; i++) { | ||
syncs.push({ | ||
type: 'image', | ||
url: PIXEL_SYNC_URL + '?' + q.replace('{cbuster}', Math.round(new Date().getTime())) // randomly selects partner if sync required | ||
}); | ||
} | ||
} else { | ||
for (let i = 0; i < spb && i < pixels.length; i++) { | ||
syncs.push({ | ||
type: 'image', | ||
url: pixels[i] + (pixels[i].indexOf('?') > 0 ? '&' : '?') + q.replace('{cbuster}', Math.round(new Date().getTime())) | ||
}); | ||
} | ||
} | ||
} | ||
return syncs; | ||
} | ||
} |
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
Oops, something went wrong.
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.
Generally this is looking great! However, you can import from /libraries/..., not from another adapter, so please move this function to a file in that folder for both