-
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
Do not load external js if renderer defined on adUnit #3284
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,5 +1,6 @@ | ||
import { loadScript } from './adloader'; | ||
import * as utils from './utils'; | ||
import find from 'core-js/library/fn/array/find'; | ||
|
||
/** | ||
* @typedef {object} Renderer | ||
|
@@ -10,7 +11,7 @@ import * as utils from './utils'; | |
*/ | ||
|
||
export function Renderer(options) { | ||
const { url, config, id, callback, loaded } = options; | ||
const { url, config, id, callback, loaded, adUnitCode } = options; | ||
this.url = url; | ||
this.config = config; | ||
this.handlers = {}; | ||
|
@@ -35,12 +36,16 @@ export function Renderer(options) { | |
this.process(); | ||
}); | ||
|
||
// we expect to load a renderer url once only so cache the request to load script | ||
loadScript(url, this.callback, true); | ||
if (!isRendererDefinedOnAdUnit(adUnitCode)) { | ||
// we expect to load a renderer url once only so cache the request to load script | ||
loadScript(url, this.callback, true); | ||
} else { | ||
utils.logWarn(`External Js not loaded by Renderer since renderer url and callback is already defined on adUnit ${adUnitCode}`); | ||
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. Does this need to be a warning? Given the nature of the setup (ie defining a renderer in the adunit), this seems like a 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. Here the user has set that renderer defined on adUnit will render the bid but the demand partners they are working with are using different js to render. |
||
} | ||
} | ||
|
||
Renderer.install = function({ url, config, id, callback, loaded }) { | ||
return new Renderer({ url, config, id, callback, loaded }); | ||
Renderer.install = function({ url, config, id, callback, loaded, adUnitCode }) { | ||
return new Renderer({ url, config, id, callback, loaded, adUnitCode }); | ||
}; | ||
|
||
Renderer.prototype.getConfig = function() { | ||
|
@@ -94,3 +99,11 @@ export function isRendererRequired(renderer) { | |
export function executeRenderer(renderer, bid) { | ||
renderer.render(bid); | ||
} | ||
|
||
function isRendererDefinedOnAdUnit(adUnitCode) { | ||
const adUnits = $$PREBID_GLOBAL$$.adUnits; | ||
const adUnit = find(adUnits, adUnit => { | ||
return adUnit.code === adUnitCode; | ||
}); | ||
return !!(adUnit && adUnit.renderer && adUnit.renderer.url && adUnit.renderer.render); | ||
} |
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 this needed on the bid?
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.
Code in master was pointing to
bid.adUnitCode
which was undefined until now. Hence i added it.Prebid.js/modules/appnexusBidAdapter.js
Line 276 in a98a349