-
Notifications
You must be signed in to change notification settings - Fork 76
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
PUC update to include Native Phase 2 spec: #106
Conversation
1) Added renderNativeAd function to nativeTrackerManager.js 2) renderNativeAd checks for existence of adId and performs the following: - Checks for rendererUrl and preloads if exists - Uses prexisting loadAssets function with new callback - Fires Impression tracker and loads click tracker 3) LoadAssets update: - Checks for existence of assetsToReplace and adds each asset to placeholder - If no placeholders exist, checks for requestAllAssets flag to fire new requestAllAssets function 4) requestAllAssets will postmessage Prebid using the action allAssetRequest instead of assetRequest 5) Replace assets will now use added logic: - If rendererUrl existence. If exists in adServer (preloaded) then check for renderAd availability on the window. If none exists, set load event on the script tag using the id 'pb-native-renderer'. If url sent as asset from Prebid, append script to window and attach load event. When script loaded and renderAd available, fire function to retrieve HTML. This inserted into innerHtml - Else if adTemplate exists, replace assets and insert into innerHtml - Else run existing replace method 6) replace function updated to include check for new native to replace keys which are in the format of ##KEY## nativeAssetManager_spec and nativeTrackerManager_spec both updated to include additional tests nativeTracker.js updated to include renderNativeAd function definition on window object
src/nativeTrackerManager.js
Outdated
return { | ||
startTrackers | ||
startTrackers, | ||
renderNativeAd |
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.
Suggest move renderNativeAd
to a new class instead of add into newNativeTrackerManager
. In long run, newNativeTrackerManager.startTrackers
will get deprecated. If we separate code renderNativeAd
from newNativeTrackerManager
now, it will be much easier when that happens.
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.
renderAd code separated into new nativeRenderManager
src/nativeTrackerManager.js
Outdated
|
||
function fireNativeCallback(){ | ||
let parsedUrl = parseUrl(window.pbNativeData.pubUrl); | ||
publisherDomain = parsedUrl.protocol + '://' + parsedUrl.host; |
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.
We suppose set publisherDomain
value inside renderNativeAd
once, instead of set it before each tracker call.
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.
Corrected the above to one definition in renderNativeAd as opposed to the tracker definitions
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.
Good.
I don't see code inside |
We need logic to take care |
…nderManager. Removed repetitive publisherDomain definitions
src/nativeAssetManager.js
Outdated
}else if(flag && win.pbNativeData.hasOwnProperty('requestAllAssets') && win.pbNativeData.requestAllAssets) { | ||
callback = cb; | ||
requestAllAssets(adId); |
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 think we suppose check requestAllAssets
first. If it is true, then requestAllAssets
. Only when requestAllAssets
is not true, then requestAssets
for placeholders
.
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.
Can you describe the use case for this? I would think that if placeholders are detected/defined, then requesting all assets should not be a requirement as the needed assets would be known.
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.
2 reasons:
- for Use Case 1 - “Render Replacements”, and Use Case 2 - “Ad Template as String”, these 2 use cases both have placementholder token inside html. pbNativeTagData.requestAllAssets = true; will be useless if the code check placementholders exist first;
- for Use Case 1 - “Render Replacements”, for html
<img class="pb-icon" alt="icon" height="10" width="10">
, there suppose have some code which get asset of##hb_native_icon##
, and set src of the image be the value of##hb_native_icon##
. But inside html, there is no placeholder for##hb_native_icon##
, so the asset won't get pulled in existing logic.
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.
To make it easier, I will create a PR against your branch, so you will understand what I mean.
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.
unfortunately my account can't push commit into git@github.com:mmoschovas/prebid-universal-creative.git repo, even inside the my own branch.
Here is the code change I made, I change function fireNativeCallback() to:
function fireNativeCallback(){
const adElements = findAdElements(AD_ANCHOR_CLASS_NAME);
for (let i = 0; i < adElements.length; i++) {
adElements[i].addEventListener('click', function(event) {
loadClickTrackers(event, window.pbNativeData.adId);
}, true);
}
const imgElements = win.document.getElementsByTagName("img");
for (let i = 0; i < imgElements.length; i++) {
if (imgElements[i].dataset && imgElements[i].dataset.src) {
imgElements[i].src = imgElements[i].dataset.src;
}
}
}
with this change, then it will support tag with following format
<img data-src="##hb_native_image##" alt="" />
<img data-src="##hb_native_icon##" alt="logo" />
This will avoid 400 error if we directly set img.src inside html template.
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.
Notice, this is a different solution than using <img class="pb-icon">
, I think it is better and easier.
And with this solution, it doesn't need pbNativeTagData.requestAllAssets = true;
for Use Case 1 - “Render Replacements” anymore, since all asset placementholder exists in GAM template html.
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.
One more notice, you need to adjust renderingMocks
inside nativeRenderManager_spec.js to
const renderingMocks = {
getWindowObject: function() {
return {
document: {
getElementsByTagName: function() {
return [];
}
},
parent: {
postMessage: sinon.spy()
}
}
}
};
Hey all, I am setting up some GAM line items today to help make testing local PUC changes easier. I'll share example test pages once I am done today / tomorrow. I would like to finalize the native stuff and merge both these for next weeks release! Thanks again. |
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.
couple minor things.
Want to get the Xander team to do a more in depth review of the rendererUrl use case.
dist/load-cookie.html
Outdated
@@ -0,0 +1,16 @@ | |||
<!DOCTYPE html> |
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 think this should not be checked in correct?
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.
Same with the .DS_Store binary.
src/nativeAssetManager.js
Outdated
callback && callback(); | ||
win.removeEventListener('message', replaceAssets); | ||
if((data.hasOwnProperty('rendererUrl') && data.rendererUrl) || (flag && win.pbNativeData.hasOwnProperty('rendererUrl'))) { | ||
if(win.renderAd){ |
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.
some lint issues (we do not have automatic linter on puc code yet)
Maybe run the entire code on your local with your eslint plugin and do the fixes?
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.
Updated
src/nativeAssetManager.js
Outdated
callback && callback(); | ||
win.removeEventListener('message', replaceAssets); | ||
if((data.hasOwnProperty('rendererUrl') && data.rendererUrl) || (flag && win.pbNativeData.hasOwnProperty('rendererUrl'))) { | ||
if(win.renderAd){ |
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.
@jaiminpanchal27 When the rendererUrl is loaded, is the expected output that a renderAd function is placed on the win.
If you could review this use case a little more in depth I would appreciate it since it was spec'd by you.
src/nativeRenderManager.js
Outdated
nativeAssetManager.loadAssets(nativeTag.adId,fireNativeCallback); | ||
fireNativeCallback(); | ||
fireNativeImpTracker(nativeTag.adId); | ||
}else{ |
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.
some more lint issues
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.
Updated
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.
Should have a space after closing bracket befor else and after
} else {
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.
maybe just run enable eslint in your editor and see what else there is?
src/nativeTrackerManager.js
Outdated
@@ -10,6 +10,7 @@ const AD_DATA_ADID_ATTRIBUTE = 'pbAdId'; | |||
export function newNativeTrackerManager(win) { | |||
let publisherDomain; | |||
|
|||
|
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.
extra new line?
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.
Removing this. I believe I originally added logic that I later removed.
@@ -89,6 +95,58 @@ describe('nativeTrackerManager', function () { | |||
expect(trimPort(postMessageTargetDomain)).to.equal(tagData.pubUrl); | |||
}); | |||
|
|||
/*it('should verify the postMessage for impression trackers was executed', function() { |
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.
what is the reasoning behind this being commented out?
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 forgot to remove this test. Originally the new rendering code lived within trackerManager code but it was requested to live in a new class. This was mirrored in the nativeRenderManager_spec test.
Ok changes look good to me. Would like @jaiminpanchal27 to do a review before we merge this. Specifically making sure the Xander proposal of rendererUrl looks good. since they spec'd that part out. More than happy to set some time or keep an open dialogue if you want @jaiminpanchal27 Thanks all! |
The associated Prebid.js change has been approved and is ready for merge once this has been approved and merged as well: |
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.
Looks good to me
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.
@mmoschovas
I think the code here looks okay. Can you please remove the .DS_Store
file and the package-lock.json
updates from the PR though?
Removed both updates |
… file to avoid loading unused code lib
…/prebid-universal-creative into native-phase-2-update
…nderer exists then adId in message must match adId in creative window, before replacing assets
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.
couple minor things
src/nativeAssetManager.js
Outdated
@@ -227,12 +271,45 @@ export function newNativeAssetManager(win) { | |||
} | |||
|
|||
if (data.message === 'assetResponse') { | |||
const body = win.document.body.innerHTML; | |||
const newHtml = replace(body, data); | |||
const body = win.document.body.innerHTML,flag = (typeof win.pbNativeData !== 'undefined'); |
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.
Can you split this flag
out to a new declaration please.
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.
Done
src/nativeAssetManager.js
Outdated
win.document.body.innerHTML = newHtml; | ||
callback && callback(); | ||
win.removeEventListener('message', replaceAssets); | ||
if (flag && data.adId != win.pbNativeData.adId) return; |
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.
Any particular reason to use !=
vs !===
?
Do we expect adId to be the same data type in both? Or is is possible one is string and one is number?
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.
Nope good catch. Updated
src/nativeRenderManager.js
Outdated
nativeAssetManager.loadAssets(nativeTag.adId,fireNativeCallback); | ||
fireNativeCallback(); | ||
fireNativeImpTracker(nativeTag.adId); | ||
}else{ |
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.
Should have a space after closing bracket befor else and after
} else {
src/nativeAssetManager.js
Outdated
} | ||
|
||
return false; | ||
} |
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.
Could just do
return win.document.body.innerHTML.indexOf(str) !== -1
Not sure this function is even being used?
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 dont remember this function but cant find a use for it so removing
src/nativeAssetManager.js
Outdated
|
||
if (placeholders.length > 0) { | ||
callback = cb; | ||
requestAssets(adId, placeholders); | ||
}else if (flag && win.pbNativeData.hasOwnProperty('requestAllAssets') && win.pbNativeData.requestAllAssets) { |
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.
space after closing brackets
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.
Fixed these. Not sure how they didnt update last time around
src/nativeRenderManager.js
Outdated
nativeAssetManager.loadAssets(nativeTag.adId,fireNativeCallback); | ||
fireNativeCallback(); | ||
fireNativeImpTracker(nativeTag.adId); | ||
}else{ |
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.
maybe just run enable eslint in your editor and see what else there is?
Docs PR prebid/prebid.github.io#2479 |
@mmoschovas Can you please take a look at the code conflict in the Thanks. |
@jsnellbaker committed merge |
@mmoschovas Thanks for the updates and for the overall effort behind this PR. Based on side conversations, we are good to merge this PR (finally). |
nativeAssetManager_spec and nativeTrackerManager_spec both updated to include additional tests
nativeTracker.js updated to include renderNativeAd function definition on window object