Skip to content

Prebid Core: Replace missing native asset placeholders #8773

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

Conversation

anitaschiller
Copy link

Type of change

  • Bugfix
  • Feature
  • New bidder adapter
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Does this change affect user-facing APIs or examples documented on http://prebid.org?
  • Other

Description of change

See the following issue: #8769
When setting requestAllAssets to false, missing assets are now replaced by an empty string instead of undefined.

  • test parameters for validating bids
{
  bidder: '<bidder name>',
  params: {
    // ...
  }
}

Be sure to test the integration with your adserver using the Hello World sample page.

  • contact email of the adapter’s maintainer
  • official adapter submission

For any changes that affect user-facing APIs or example code documented on http://prebid.org, please provide:

Other information

@ChrisHuie ChrisHuie linked an issue Aug 3, 2022 that may be closed by this pull request
@patmmccann patmmccann changed the title Replace missing asset placeholders Prebid Core: Replace missing asset placeholders Aug 3, 2022
@patmmccann patmmccann changed the title Prebid Core: Replace missing asset placeholders Prebid Core: Replace missing native asset placeholders Aug 3, 2022
@dgirardi
Copy link
Collaborator

dgirardi commented Aug 4, 2022

IMO this should be addressed from the PUC, but I have to admit that I have a hard time understanding native - so I'm not sure.

I know that it's possible to use custom renderers so I'm afraid that this might be a breaking change? because I can imagine some implementations for which it's useful to distinguish between an asset that is missing and one that is an empty string. It seems safer to me to put that fallback in the renderer (PUC in our case).

@muuki88
Copy link
Collaborator

muuki88 commented Aug 8, 2022

@dgirardi we decided to go for prebid.js, because this were the incoming bid data is processed and the simplest way to add defaults. However it's probably better to make this configurable to make it configurable like the requestAllAssets boolean.

E.g.

<script src="https://cdn.jsdelivr.net/npm/prebid-universal-creative@latest/dist/native-render.js"></script>
<script>
    var pbNativeTagData = {};
    pbNativeTagData.pubUrl = "%%PATTERN:url%%";     // GAM specific
    pbNativeTagData.adId = "%%PATTERN:hb_adid%%";   // GAM specific
    // if you're using 'Send All Bids' mode, you should use %%PATTERN:hb_adid_BIDDER%%
    pbNativeTagData.requestAllAssets = false;
    
    // configure a fallback that works for the publisher
    pbNativeTagData.fallbackAssetValue = '';
    window.pbNativeTag.renderNativeAd(pbNativeTagData);
</script>

From https://docs.prebid.org/prebid/native-implementation.html

So we would extend this in PUC

https://github.com/prebid/prebid-universal-creative/blob/259030726f486f161995908688f360a8befdecf1/src/nativeAssetManager.js#L190-L196

to send the fallbackValue along. The native.js would then be able to access the fallbackValue.

Prebid.js/src/native.js

Lines 386 to 391 in dd3267d

data.assets.forEach(asset => {
const key = getKeyByValue(CONSTANTS.NATIVE_KEYS, asset);
const value = getAssetValue(adObject.native[key]);
message.assets.push({ key, value });
});

but I have to admit that I have a hard time understanding native - so I'm not sure.

If you like, we can talk about this 😄

@dgirardi
Copy link
Collaborator

dgirardi commented Aug 8, 2022

If we involve the PUC, it can manage the fallbackValue all by itself - I don't think it needs to bounce it off Prebid. It would just need to say "replace macro with the asset value, or fallbackValue if the asset is missing or its value is undefined". I think it would also be perfectly sensible to always have have a fallback of '' in the PUC (without defining a new fallbackValue parameter), because I do not see how it is advantageous to show "undefined" in the rendered template. I am just unsure about doing it up here in Prebid because I do not know if any custom renderers would be affected.

@muuki88
Copy link
Collaborator

muuki88 commented Aug 8, 2022

True that custom renderers maybe check of undefined specifically instead of falsy value.

In PUC it would be this code here: https://github.com/prebid/prebid-universal-creative/blob/259030726f486f161995908688f360a8befdecf1/src/nativeAssetManager.js#L340-L345

We would essentially

  1. replace all placeholders with the incoming assets
  2. scanForPlaceholders and replace those with empty strings
    (assets || []).forEach(asset => {
      const flag = (typeof win.pbNativeData !== 'undefined');
      const searchString = (adId && !flag) ? `${NATIVE_KEYS[asset.key]}:${adId}` : ((flag) ? '##'+`${NATIVE_KEYS[asset.key]}`+'##' : `${NATIVE_KEYS[asset.key]}`);
      const searchStringRegex = new RegExp(searchString, 'g');
      html = html.replace(searchStringRegex, asset.value);
    });
    
    // roughly like this
    scanForPlaceholders().forEach(placeholder => {
      html = html.replace(placeholder, '');
    })

@anitaschiller
Copy link
Author

I now implemented the replacement of missing assets in the PUC like @muuki88 suggested --> PR.

Thanks for checking!

@anitaschiller
Copy link
Author

@dgirardi I opened a new PR in the PUC: prebid/prebid-universal-creative#171.
What do you think about this solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Native designs: Replacing placeholders for "missing" assets
4 participants