Skip to content
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

Replace all placeholders with the corresponding ortb assets #211

Merged
merged 3 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Universal creative for Prebid apps",
"main": "dist/creative.js",
"scripts": {
"test": "echo test",
"test": "gulp test",
"prepublish": "gulp build"
},
"repository": {
Expand Down
6 changes: 3 additions & 3 deletions src/nativeAssetManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,16 +426,16 @@ export function newNativeAssetManager(win, nativeTag) {
}

ortb.assets.forEach(asset => {
html = html.replace(`##hb_native_asset_id_${asset.id}##`, getAssetValue(asset));
html = html.replaceAll(`##hb_native_asset_id_${asset.id}##`, getAssetValue(asset));
if (asset.link && asset.link.url) {
html = html.replace(`##hb_native_asset_link_id_${asset.id}##`, asset.link.url);
html = html.replaceAll(`##hb_native_asset_link_id_${asset.id}##`, asset.link.url);
}
});

html = html.replaceAll(/##hb_native_asset_id_\d+##/gm, '');

if (ortb.privacy) {
html = html.replace("##hb_native_privacy##", ortb.privacy);
html = html.replaceAll("##hb_native_privacy##", ortb.privacy);
}

if (ortb.link) {
Expand Down
4 changes: 4 additions & 0 deletions test/spec/nativeAssetManager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ describe('nativeAssetManager', () => {
<div class="attribution">
<img class="pb-icon" src="##hb_native_asset_id_3##" alt="icon" height="150" width="50">
</div>
<h2>##hb_native_asset_id_1##</h2>
<p>##hb_native_asset_id_4##</p>
</div>
</div>
Expand Down Expand Up @@ -415,6 +416,9 @@ describe('nativeAssetManager', () => {
// ##hb_native_asset_id_4## was not returned in the response, it should
// be transformed into an empty string
expect(win.document.body.innerHTML).to.not.include(`##hb_native_asset_id_4##`);

// test that we are replacing ALL asset occurrences
expect(([...win.document.body.innerHTML.match(/new value/g)] || []).length, "expected 2 occurrences of \"new value\"").to.equal(2);
});

it('no placeholders found but requests all assets flag set - adTemplate', () => {
Expand Down