-
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
Fledge Module: Initial Commit #7189
Closed
Closed
Changes from all commits
Commits
Show all changes
3 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
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,75 @@ | ||
import { Fledge } from '@magnite/fledge.polyfill/dist/api/cjs/index.js'; | ||
import { auctionManager } from '../src/auctionManager.js'; | ||
import { config } from '../src/config.js'; | ||
import CONSTANTS from '../src/constants.json'; | ||
import { getGlobal } from '../src/prebidGlobal.js'; | ||
import * as utils from '../src/utils.js'; | ||
|
||
/** | ||
* @summary This Module is intended to provide users with the ability to run a Fledge-based auction against a PreBid winning bid | ||
*/ | ||
const MODULE_NAME = 'Fledge'; | ||
|
||
/** | ||
* @summary The config to be used. Can be updated via: setConfig | ||
*/ | ||
let _fledgeConfig = {}; | ||
|
||
/** | ||
* | ||
* @param {Object} reqBidsConfigObj required; This is the same param that's used in pbjs.requestBids. | ||
* @param {function} fn required; The next function in the chain, used by hook.js | ||
*/ | ||
export function renderAdHook(fn, doc, id, options) { | ||
const bid = auctionManager.findBidByAdId(id); | ||
|
||
if (_fledgeConfig.auctionConfig) { | ||
const fledge = new Fledge('https://magniteengineering.github.io/fledge.polyfill/iframe.html'); | ||
const auctionConfig = _fledgeConfig.auctionConfig; | ||
auctionConfig.auctionSignals.winningContextualBid = bid; | ||
fledge | ||
.runAdAuction(auctionConfig) | ||
.then(results => { | ||
if (results) { | ||
// create an iframe within the Fledge auction iframe, render the winning ad | ||
const ad = document.createElement('iframe'); | ||
ad.src = results; | ||
document.getElementById(bid.adUnitCode).appendChild(ad); | ||
} else { | ||
return fn.call(this, doc, id, options); | ||
} | ||
}); | ||
} else { | ||
return fn.call(this, doc, id, options); | ||
} | ||
} | ||
|
||
/** | ||
* @summary This is the function which controls what happens during a pbjs.setConfig({...floors: {}}) is called | ||
*/ | ||
export function handleSetFledgeConfig(config) { | ||
_fledgeConfig = utils.pick(config, [ | ||
'enabled', enabled => enabled !== false, // defaults to true | ||
'auctionConfig', | ||
]); | ||
|
||
// if enabled then do some stuff | ||
if (_fledgeConfig.enabled) { | ||
getGlobal() | ||
.renderAd | ||
.before(renderAdHook, CONSTANTS.HOOK_PRIORITY.RENDER_AD); | ||
} else { | ||
utils.logInfo(`${MODULE_NAME}: Turning off module`); | ||
|
||
_fledgeConfig = {}; | ||
|
||
getGlobal() | ||
.renderAd | ||
.getHooks({ | ||
hook: renderAdHook | ||
}) | ||
.remove(); | ||
} | ||
} | ||
|
||
config.getConfig('fledge', config => handleSetFledgeConfig(config.fledge)); |
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.
Why is external code needed here? Also, please lock https://magniteengineering.github.io/fledge.polyfill/scripts/frame/esm/index.js to a version if external code is actually required. Also, since it requires promises / async await, please make sure the browser can handle these features before adding these requests.
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.
The external code is a polyfill that is required to work with Google's new Fledge proposal.
This is locked down in the
package.json
to a version (https://github.com/prebid/Prebid.js/pull/7189/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R105)Do you have any suggestions for how to handle this? Do you guys have/use some sort of agent/browser sniffing that I could work with in order to prevent the code from running in older browsers? Technically this piece of code will only work with Chrome at version 91 or 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.
I am confused, if you don't need the runtime code bc you included it at build time, why are you invoking it.
I would suggest not sniffing for user agents or browser versions but just checking for the existence of the required api or functionality
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.
I'm also confused by the concern and questions here.
I included the
@magnite/fledge.polyfill
library because it's a polyfill that is required to work with Fledge.okay, thanks.
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.
@iamnewton I was looking at the polyfill and looks like it only supports chrome versions 91 and greater? Not sure if it's a problem but that is a pretty recent version.
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.
yeah, this is new stuff that doesn't exist yet
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.
That is intentional @ChrisHuie Chrome 91 will be the version of Chrome that supports Fledge. We have to match this "module" with requests from the right Chrome browser version.
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.
well Chrome 94 is out now, so it will be much later at this point
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.
right I guess the pt is that this module is intended to only work on a very specific version of Chrome, TBD on which version.