google / openrtb-doubleclick

Utilities for DoubleClick Ad Exchange, including OpenRTB mapping, DoubleClick cryptography, metadata and validation
Apache License 2.0
198 stars 82 forks source link

How to send response back to Adx from OpenRtb.BidResponse.Builder #105

Closed vikas1981 closed 7 years ago

vikas1981 commented 7 years ago

We have a OpenRTB response JSON and converted it to OpenRtb.BidResponse.Builder

Now how will we send back response back to AdX for OpenRTB protobuf ?

OpenRtb.BidResponse.Builder has been constructed from openRTB JSON. I believe we need to send NetworkBid.BidResponse back to AdX. Am i correct ? if yes, what would the way to create NetworkBid.BidResponse from OpenRtb.BidResponse.Builder ?

And how to use DoubleClickValidator to validate the response before we send it back to AdX ?

opinali commented 7 years ago

The AdX native protocol is not supported anymore; if you're using this library with AdX, you must configure the bidder to receive the native OpenRTB protocol, check the updated AdX Buyer API where you can now choose the protocol. There are actually two variants of OpenRTB, the standard one with JSON encoding and the OpenRTB/Protobuf variant with binary encoding. The former requires using the JSON utilities in this library and in the companion lib https://github.com/google/openrtb. With Protobuf encoding it's simpler, just serialize/deserialize the messages using the proto APIs.

To use the validator: first, you can only use DoubleClickValidator with the native protocol, not with OpenRTB. With OpenRTB, use OpenRtbValidator from the associated openrtb library. You will find unit tests that show how to create and use the validators, but let me know if you have difficulty.

vikas1981 commented 7 years ago

Thanks for quick reply,

Currently we are are configured on AdX with OpenRTB Protopuf request format. I was able to parse the request buffer using below:

OpenRtb.BidRequest openRTBRequest = OpenRtb.BidRequest.parseFrom(byte []);

While we sending response back, we have raw OpenRTB JSON response. Then i used

OpenRtb.BidResponse.Builder bidResponseBuilder = OpenRtb.BidResponse.newBuilder();

To build the response from raw OpenRTB JSON response and return back response i call function like :

OpenRtb.BidResponse openRTBResponse = bidResponseBuilder.build();
openRTBResponse.writeTo(response.getOutputStream());

I hope this would have been working but since AdX dashboard UI runs behind by 8-10 hours. Today i see no valid in their dashboard instead it shows unsuccessful responses. But there is no way to know what was wrong with the response.

Let me know if you can help here to make sure the way we write response back to output stream is write or wrong ?

opinali commented 7 years ago

Your code is correct, so the problem has to be something in the AdX side it doesn't like your response for some reason, or maybe some problem with creative etc., hard to tell... at this point the ideal thing to do is contacting your AdX account manager, usually if you send a text dump of the response message they can tell if there's something wrong and see fro its ID what is the reason for rejection.

vikas1981 commented 7 years ago

My code was able to parse the request but then AdX showed us that we are configure in ADX Protocol instead of OpenRTB protobuf. So i asked them to switch to OpenRTB protobuf and since then code is not able to parse requests.

Below is one of the base 64 of buffer coming in: EhBYsFylAAPhtgo3RNJlD/tNIgNGwwYyiQFNb3ppbGxhLzUuMCAoTGludXg7IEFuZHJvaWQgNy4xLjE7IFBpeGVsIFhMIEJ1aWxkL05PRjI2VikgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzU2LjAuMjkyNC44NyBNb2JpbGUgU2FmYXJpLzUzNy4zNlpNaHR0cDovL3d3dy5teWZpdG5lc3NwYWwuY29tL2Zvb2QvY2Fsb3JpZXMvcG9wZXllcy1idXR0ZXJtaWxrLWJpc2N1aXQtMjk5ODA3NjhiAmVuaggIlgcVxVb4PmoICMgDFQAAgD9qCAjpCxU1s3g+agcIXhUAAEA/crQBCAEQrAIQ+gEY+gEY+gEiEUZfIiAeGzAZFBMSERAPDg0WMh4KXoIBkAGRAeEB6QHtAe4B8gH/AYQCrwLOAtYCvwQ6ChMEHgoDHwUIGBJKIhCBt4P6jwEokLz9AjoOCJiEIgj/5iUI351DKAE6BDDQpUxgAWoO5U7mTudO6E7pTutOwU9w9smf5AZ5FuuJBPvORHJ53TrsehZdBNKYAQCoAQrNAdztnjv1AQAAAAD6AQCiAgEAeACgAQGqARtDQUVTRUlNbGFOd01OLXJ0aURGemp3TklYNlnIAZj9/////////wHSAQEn4gE3GgdhbmRyb2lkOABAAWIGZ29vZ2xlaghwaXhlbCB4bHIGCAcQARgBeJwDgAHcBZABzKMEmAGsG/gBgIKXBrgC9d2mBMgC2QSYAwGyAzIIARIHYW5kcm9pZBoGZ29vZ2xlIghwaXhlbCB4bCoGCAcQARgBMMyjBDicA0DcBUisG7oDAlVT

Can you please what is wrong with the code if i use:

OpenRtb.BidRequest openRTBRequest = OpenRtb.BidRequest.parseFrom(byte []);

I see below exception while executing above statement:


com.google.protobuf.InvalidProtocolBufferException$InvalidWireTypeException: Protocol message tag had invalid wire type.
        at com.google.protobuf.InvalidProtocolBufferException.invalidWireType(InvalidProtocolBufferException.java:111)
        at com.google.protobuf.UnknownFieldSet$Builder.mergeFieldFrom(UnknownFieldSet.java:551)
        at com.google.protobuf.MessageReflection.mergeFieldFrom(MessageReflection.java:795)
        at com.google.protobuf.GeneratedMessageV3$ExtendableMessage.parseUnknownField(GeneratedMessageV3.java:987)
        at com.google.openrtb.OpenRtb$BidRequest$Imp.<init>(OpenRtb.java:12502)
        at com.google.openrtb.OpenRtb$BidRequest$Imp.<init>(OpenRtb.java:12457)
        at com.google.openrtb.OpenRtb$BidRequest$Imp$1.parsePartialFrom(OpenRtb.java:35513)
        at com.google.openrtb.OpenRtb$BidRequest$Imp$1.parsePartialFrom(OpenRtb.java:35508)
        at com.google.protobuf.CodedInputStream$ArrayDecoder.readMessage(CodedInputStream.java:816)
        at com.google.openrtb.OpenRtb$BidRequest.<init>(OpenRtb.java:11793)
        at com.google.openrtb.OpenRtb$BidRequest.<init>(OpenRtb.java:11730)
        at com.google.openrtb.OpenRtb$BidRequest$1.parsePartialFrom(OpenRtb.java)
        at com.google.openrtb.OpenRtb$BidRequest$1.parsePartialFrom(OpenRtb.java)
        at com.google.protobuf.AbstractParser.parsePartialFrom(AbstractParser.java:139)
        at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:173)
        at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:185)
        at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:49)
        at com.google.openrtb.OpenRtb$BidRequest.parseFrom(OpenRtb.java)
opinali commented 7 years ago

The protocol is not correct, this is in the AdX/Protobuf format, not OpenRTB/Protobuf. I was able to decode this as an AdX BidRequest:

id: "X\260\\\245\000\003\341\266\n7D\322e\017\373M" ip: "F\303\006" user_agent: "Mozilla/5.0 (Linux; Android 7.1.1; Pixel XL Build/NOF26V) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Mobile Safari/537.36" url: "http://www.myfitnesspal.com/food/calories/popeyes-buttermilk-biscuit-29980768" detected_language: "en" detected_vertical { id: 918 weight: 0.485037 } detected_vertical { id: 456 weight: 1 } detected_vertical { id: 1513 weight: 0.24287112 } detected_vertical { id: 94 weight: 0.75 } adslot { id: 1 width: 300 width: 250 height: 250 height: 250 excluded_attribute: 70 excluded_attribute: 95 excluded_attribute: 34 excluded_attribute: 32 excluded_attribute: 30 excluded_attribute: 27 excluded_attribute: 48 excluded_attribute: 25 excluded_attribute: 20 excluded_attribute: 19 excluded_attribute: 18 excluded_attribute: 17 excluded_attribute: 16 excluded_attribute: 15 excluded_attribute: 14 excluded_attribute: 13 excluded_attribute: 22 allowed_vendor_type: 10 allowed_vendor_type: 94 allowed_vendor_type: 130 allowed_vendor_type: 144 allowed_vendor_type: 145 allowed_vendor_type: 225 allowed_vendor_type: 233 allowed_vendor_type: 237 allowed_vendor_type: 238 allowed_vendor_type: 242 allowed_vendor_type: 255 allowed_vendor_type: 260 allowed_vendor_type: 303 allowed_vendor_type: 334 allowed_vendor_type: 342 allowed_vendor_type: 575 excluded_sensitive_category: 19 excluded_sensitive_category: 4 excluded_sensitive_category: 30 excluded_sensitive_category: 10 excluded_sensitive_category: 3 excluded_sensitive_category: 31 excluded_sensitive_category: 5 excluded_sensitive_category: 8 excluded_sensitive_category: 24 excluded_sensitive_category: 18 matching_ad_data { billing_id: 38642178945 minimum_cpm_micros: 6250000 pricing_rule { included_advertisers: 557592 included_advertisers: 619391 included_advertisers: 1101535 blocked: true } pricing_rule { minimum_cpm_micros: 1250000 } } slot_visibility: ABOVE_THE_FOLD excluded_product_category: 10085 excluded_product_category: 10086 excluded_product_category: 10087 excluded_product_category: 10088 excluded_product_category: 10089 excluded_product_category: 10091 excluded_product_category: 10177 ad_block_key: 1820845302 publisher_settings_list_id: 8233933596248369942 publisher_settings_list_id: 15133322999004674781 iframing_state: UNKNOWN_IFRAME_STATE viewability: 10 click_through_rate: 0.0048501324 video_completion_rate: 0 sticky_settings { } allowed_ad_types: ALLOWED_AD_TYPE_BANNER } is_test: false cookie_version: 1 google_user_id: "CAESEIMlaNwMN-rtiDFzjwNIX6Y" timezone_offset: -360 detected_content_label: 39 mobile { is_app: false 3: "android" 8: 1 12: "google" 13: "pixel xl" 14 { 1: 7 2: 1 3: 1 } 15: 412 16: 732 18: 70092 19: 3500 } cookie_age_seconds: 12960000 geo_criteria_id: 9023221 seller_network_id: 601 publisher_type: ADX_PUBLISHER_OWNED_AND_OPERATED device { device_type: HIGHEND_PHONE platform: "android" brand: "google" model: "pixel xl" os_version { major: 7 minor: 1 micro: 1 } carrier_id: 70092 screen_width: 412 screen_height: 732 screen_pixel_ratio_millis: 3500 } publisher_country: "US"

Please ask them again, make sure it's "OPENRTB PROTOBUF 2.4".

vikas1981 commented 7 years ago

Thanks for the help. Finally AdX is able to fix on their end and request parsing is working for me now. Now we are stuck with response. AdX is asking us to send billing_id back in cid under RTB response. else they just keep rejecting the bids.

As per them they must be passing billing_id under Impression Extension object. How would we pass Extension object from BidRequest coming in OpenRTB protobuf ?

Currently I am using below code to parse request:

ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance(); OpenRtb.BidRequest openRTBRequest = OpenRtb.BidRequest.parseFrom(rr, extensionRegistry); if (openRTBRequest.getImpCount() > 0) { List imps = new ArrayList(openRTBRequest.getImpCount()); req.put("imp", imps);

        for (int i = 0; i < openRTBRequest.getImpCount(); i++) {
            OpenRtb.BidRequest.Imp im = openRTBRequest.getImp(i);

} . }

What is way to get Extension object from OpenRtb.BidRequest.Imp im object ?

opinali commented 7 years ago

To send the billing_id back you should use the Bid.cid field; please refer to the mapping docs in openrtb.proto: [AdX: BidResponse.Ad.AdSlot.billing_id]

vikas1981 commented 7 years ago

How will i retrieve billing_id from "OpenRtb.BidRequest openRTBRequest" so that i can pass the same back in response ?

vikas1981 commented 7 years ago

I used below code to parse incoming protobuf but extension are not being parsed. Do i need to register something in ExtensionRegistry to parse Imp.Ext ?

ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance(); OpenRtb.BidRequest openRTBRequest = OpenRtb.BidRequest.parseFrom(rr, extensionRegistry);

vikas1981 commented 7 years ago

I got it. Thanks for the support

ExtensionRegistry reg = ExtensionRegistry.newInstance(); AdxExt.registerAllExtensions(reg); OpenRtb.BidRequest openRTBRequest = OpenRtb.BidRequest.parseFrom(rr, reg);

opinali commented 7 years ago

Great you found it, closing this as I suppose everything's working now :)

kartik11 commented 7 years ago

Hi Opinali, I am new to Google RTB protocol, i am working with PHP platform and needs to develop bidder in openRTB standard. Can i get any documentation or technical assist on this?

opinali commented 7 years ago

Hi,

I suppose you want to bid on AdX, in that case you'll find docs here: https://developers.google.com/ad-exchange/rtb/openrtb-guide

I don't know much about PHP, but you should be able to get the OpenRTB proto files from this project and from google/openrtb, or from https://developers.google.com/ad-exchange/rtb/data (it's the same protos), and compile them for PHP with the latest protoc release at https://github.com/google/protobuf/tree/master/php.

On Fri, May 19, 2017 at 4:48 AM, kartik11 notifications@github.com wrote:

Hi Opinali, I am new to Google RTB protocol, i am working with PHP platform and needs to develop bidder in openRTB standard. Can i get any documentation or technical assist on this?0

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/google/openrtb-doubleclick/issues/105#issuecomment-302646269, or mute the thread https://github.com/notifications/unsubscribe-auth/AC4MMEFgpdpc-i464ANMFIeMxLHYVBoJks5r7VdLgaJpZM4MDdKm .

-- Osvaldo Doederlein | Software Engineer, DoubleClick Ad Exchange | opinali@google.com

kartik11 commented 7 years ago

Hi Opinali, I can able to understand the base process, is there any other way to find out some code with PHP for google openRTB process, i am eager to receive from your side.

mifefr commented 7 years ago

Hi kartik11, I'm actualy working on the google openRTB process since 2 weeks, if you have any question in your project, I think I can help you. Because the doc is so poor for the process in php.

Do not hesitate!

mifefr.

kartik11 commented 7 years ago

Hi Opinali,

Thanks for you interest, if you can kindly send any doc for openRTB protobuf install and simple usage code in PHP with single request / response. Thanks in Advance.

On Tue, May 23, 2017 at 3:30 PM, mifefr notifications@github.com wrote:

Hi kartik11, I'm actualy working on the google openRTB process since 2 weeks, if you have any question in your project, I think I can help you. Because the doc is so poor for the process in php.

Do not hesitate!

mifefr.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/google/openrtb-doubleclick/issues/105#issuecomment-303351452, or mute the thread https://github.com/notifications/unsubscribe-auth/AGqtIC95aLqJ5uIM7KGDt98V6lsC3-oTks5r8q5YgaJpZM4MDdKm .

pkthakkar26 commented 7 years ago

Hi Opinali,

I was trying to integrate Adx OpenRTB/ProtoBuf format. Where can i get sample request for it? As https://developers.google.com/ad-exchange/rtb/openrtb-guide contains sample request/response only for OpenRTB/JSON format. Also Do i need to use OpenRtb BidRequest Builder to parse openrtb/protobuf request?

opinali commented 7 years ago

Hi Pratik,

To the best of my knowledge, we don't have any full, real-world samples of AdX requests in our documentation... this is hard to share because requests will have fields that contain user-agent information and also IDs from the adx buyer. But this shouldn't be hard to get, if you have and AdX account you can enable bidding and have a minimal bidder that just dumps the requests. Or you can ask a TAM to provide samples.

On Mon, Jul 10, 2017 at 2:41 AM, Pratik Thakkar notifications@github.com wrote:

Hi Opinali,

I was trying to integrate Adx OpenRTB/ProtoBuf format. Where can i get sample request for it? As https://developers.google.com/ad-exchange/rtb/openrtb-guide http://url contains sample request/response only for OpenRTB/JSON format. Also Do i need to use OpenRtb BidRequest Builder to parse openrtb/protobuf request?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/google/openrtb-doubleclick/issues/105#issuecomment-314018841, or mute the thread https://github.com/notifications/unsubscribe-auth/AC4MMBzswvryi3i4wQvFj8bJiLkg42dwks5sMceYgaJpZM4MDdKm .

-- Osvaldo Doederlein | Software Engineer, DoubleClick Ad Exchange | opinali@google.com

pkthakkar26 commented 7 years ago

Thanks Opinali for the reply. I was able to generate sample request of my choice from OpenRtb.BidRequest Builder.