From 9c3c44228836fa7c14c471fa7cccf1f7af6809d4 Mon Sep 17 00:00:00 2001 From: Rich Loveland Date: Tue, 9 Jan 2018 16:34:43 -0500 Subject: [PATCH 1/2] Add docs for native image-type asset dimensions Related to https://github.com/prebid/Prebid.js/pull/1919 --- dev-docs/bidder-adaptor.md | 48 ++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/dev-docs/bidder-adaptor.md b/dev-docs/bidder-adaptor.md index 2ea57cf040..4e45675da8 100644 --- a/dev-docs/bidder-adaptor.md +++ b/dev-docs/bidder-adaptor.md @@ -408,7 +408,7 @@ In order for your bidder to support the native media type: 2. Your (client-side) bidder adapter needs to unpack the server's response into a Prebid-compatible bid response populated with the required native assets. 3. Your bidder adapter must be capable of ingesting the required and optional native assets specified on the `adUnit.mediaTypes.native` object, as described in [Show Native Ads]({{site.baseurl}}/dev-docs/show-native-ads.html). -The adapter code sample below fulfills requirement #2, unpacking the server's reponse and: +The adapter code samples below fulfills requirement #2, unpacking the server's reponse and: 1. Checking for native assets on the response. 2. If present, filling in the `native` object with those assets. @@ -420,22 +420,50 @@ else if (rtbBid.rtb.native) { /* If yes, let's populate our response with native assets */ - const native = rtbBid.rtb.native; + const nativeResponse = rtbBid.rtb.native; bid.native = { - title: native.title, - body: native.desc, - cta: native.ctatext, - sponsoredBy: native.sponsored, - image: native.main_img && native.main_img.url, - icon: native.icon && native.icon.url, - clickUrl: native.link.url, - impressionTrackers: native.impression_trackers, + title: nativeResponse.title, + body: nativeResponse.desc, + cta: nativeResponse.ctatext, + sponsoredBy: nativeResponse.sponsored, + image: nativeResponse.main_img && nativeResponse.main_img.url, + icon: nativeResponse.icon && nativeResponse.icon.url, + clickUrl: nativeResponse.link.url, + impressionTrackers: nativeResponse.impression_trackers, }; } {% endhighlight %} +As of the [0.34.1 release](https://github.com/prebid/Prebid.js/releases/tag/0.34.1), a bidder may optionally return the height and width of a native image asset. + +If your bidder does return the image size, you can expose the image dimensions on the bid response object as shown below. + +```javascript + /* Does the bidder respond with native assets? */ + else if (rtbBid.rtb.native) { + + const nativeResponse = rtbBid.rtb.native; + + /* */ + + bid.native = { + title: nativeResponse.title, + image: { + url: nativeResponse.img.url, + height: nativeResponse.img.height, + width: nativeResponse.img.width, + }, + icon: nativeResponse.icon.url, + }; + } +``` + +The targeting key `hb_native_image` (about which more [here]({{site.baseurl}}/adops/setting-up-prebid-native-in-dfp.html) (ad ops setup) and [here]({{site.baseurl}}/dev-docs/show-native-ads.html) (engineering setup)) will be set with the value of `image.url` if `image` is an object. + +If `image` is a string, `hb_native_image` will be populated with that string (a URL). + ## Adding Unit Tests Every adapter submission must include unit tests. For details about adapter testing requirements, see the **Writing Tests** section of [CONTRIBUTING.md](https://github.com/prebid/Prebid.js/blob/master/CONTRIBUTING.md). From ab97da384b70798cb5b170f74c890f4c2ff6c60e Mon Sep 17 00:00:00 2001 From: Rich Loveland Date: Wed, 10 Jan 2018 13:39:38 -0500 Subject: [PATCH 2/2] Per feedback, this applies to `icon` assets, too --- dev-docs/bidder-adaptor.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-docs/bidder-adaptor.md b/dev-docs/bidder-adaptor.md index 4e45675da8..bf64936fcb 100644 --- a/dev-docs/bidder-adaptor.md +++ b/dev-docs/bidder-adaptor.md @@ -436,7 +436,7 @@ else if (rtbBid.rtb.native) { {% endhighlight %} -As of the [0.34.1 release](https://github.com/prebid/Prebid.js/releases/tag/0.34.1), a bidder may optionally return the height and width of a native image asset. +As of the [0.34.1 release](https://github.com/prebid/Prebid.js/releases/tag/0.34.1), a bidder may optionally return the height and width of a native `image` or `icon` asset. If your bidder does return the image size, you can expose the image dimensions on the bid response object as shown below.