{"_id":"5b6c3c1650a5cb0003eb224b","project":"5429beef1163360800ed31fa","version":{"_id":"5429beef1163360800ed31fd","__v":22,"project":"5429beef1163360800ed31fa","createdAt":"2014-09-29T20:19:59.904Z","releaseDate":"2014-09-29T20:19:59.904Z","categories":["5429beef1163360800ed31fe","55e74e1f5d36b32b002563fa","55e7500a73169617001f2e86","55e76b8196131b2f00bf4b72","55e89569cdbb8a350096df9c","55f8935eb089b71700a8364e","55f8a67d3bb4bb0d0022d093","55f9dbefc7ef770d00d9bf6d","5601c21a22ecf60d002b27b3","5601c21ff12aee0d001bb06e","5601c2256c7b610d00280db5","5601c22c22ecf60d002b27b4","5603738d0c78b00d0039af47","5626f70bfcbbc621004ebf52","566f7a1ae144ab0d00e9732f","566f85ca7820960d00c3b93d","56708ce43a32d20d00c45cbf","56708d436995210d003aad8e","5736471abe10a9200030732c","57a82c7aff9bd30e00a6f1c1","591b8500e3992319007190f4","5a3718305c66a60012d960ba"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"category":{"_id":"5601c22c22ecf60d002b27b4","pages":["5601d37b70694e0d00e3c67e","5601d3a0d3ffde0d006abbd0","5601d3fd96e0f70d0044b110","5601d42096e0f70d0044b112","5601d45d7435de0d00fabc27","5601d48170694e0d00e3c680","561c925fac06982100493d19","56606f35bb77350d0073249b","567090d51dabd80d00b122ca","56abc1004e8ba20d006a23c9"],"version":"5429beef1163360800ed31fd","__v":10,"project":"5429beef1163360800ed31fa","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-09-22T21:03:40.067Z","from_sync":false,"order":7,"slug":"demand-manager","title":"Demand Manager"},"user":"592d2246b9d6342500d54f62","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2018-08-09T13:05:26.863Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":15,"body":"[block:api-header]\n{\n  \"title\": \"1. Add Google play services libraries\"\n}\n[/block]\nAdd the following Google play services libraries in your Gradle file\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"dependencies {\\n    compile 'com.google.android.gms:play-services-ads:15.0.1'\\n    compile 'com.google.android.gms:play-services-location:15.0.1'\\n }\",\n      \"language\": \"groovy\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"2. Create a header bidding request\"\n}\n[/block]\nCopy <code>PolymorphAdapter.java</code> and <code>PolymorphBidder.java</code> files from https://github.com/picatcha/adsnative-sdk-android/tree/master/header_bidding/DFP to your application code.\n\nInitialise DFP class as you would normally do while integrating with DFP SDK\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"AdLoader adLoader = new AdLoader.Builder(context, DFP_AD_UNTI_ID)\\n    .forAppInstallAd(new OnAppInstallAdLoadedListener() {\\n        :::at:::Override\\n        public void onAppInstallAdLoaded(NativeAppInstallAd appInstallAd) {\\n            // Show the app install ad.\\n        }\\n    })\\n    .forContentAd(new OnContentAdLoadedListener() {\\n        @Override\\n        public void onContentAdLoaded(NativeContentAd contentAd) {\\n            // Show the content ad.\\n        }\\n    })\\n    .forPublisherAdView(new OnPublisherAdViewLoadedListener() {\\n        @Override\\n        public void onPublisherAdViewLoaded(PublisherAdView adView) {\\n            // Show the banner ad.\\n        }\\n    }, AdSize.BANNER)\\n    .withAdListener(new AdListener() {\\n        @Override\\n        public void onAdFailedToLoad(int errorCode) {\\n            // Handle the failure by logging, altering the UI, etc.\\n        }\\n    })\\n    .withNativeAdOptions(new NativeAdOptions.Builder()\\n            // Methods in the NativeAdOptions.Builder class can be\\n            // used here to specify individual options settings.\\n            .build())\\n     .withPublisherAdViewOptions(new PublisherAdViewOptions.Builder()\\n            // Methods in the PublisherAdViewOptions.Builder class can be\\n            // used here to specify individual options settings.\\n            .build())\\n    .build();\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nImport and initialise Polymorph bidder preferably in your main or parent activity class <code>onCreateView()</code> method by passing Context, Polymorph placement ID, AdLoader instance and banner ad size using <code>AdHelper.AdSize</code> enum :\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PolymorphBidder polymorphBidder = new PolymorphBidder(this.getContext(), POLYMORPH_AD_UNIT_ID, adLoader, AdHelper.AdSize.BANNER_300x50);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"Make sure you pass the banner ad size using the<code>AdHelper.AdSize</code>Enum to indicate the size of the banner ad which you need from Polymorph. This has to be same as the size which you passed in DFP <code>forPublisherAdView()</code>call while creating the <code>AdLoader</code>instance\",\n  \"title\": \"Banner Ad Size\"\n}\n[/block]\nCall <code>loadDFPAd()</code> method via Polymorph bidder which will automatically handle header bidding while also pre-fetching ads from Polymorph to avoid network latency. DO NOT invoke <code>adLoader.loadAd()</code> as this is internally handled by PolymorphBidder.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"polymorphBidder.loadDFPAd();\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n**Setting Bidding Interval**\nSet the bidding interval based on the price range that you've chosen while creating various yield partners. The default bid interval is 0.05. You'll need to use the <code>setBiddingInterval()</code> method as shown below:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"polymorphBidder.setBiddingInterval(0.10);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n_Note: This value can also be set from server-side. Please contact us if you want to do this_\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"The bid thats obtained from Polymorph will be rounded off to the nearest multiple of bidding interval and then sent to DFP by key value targeting as the value of <code>ecpm</code> key. For instance, if the bidding interval is 0.05 and the bid obtained from Polymorph is 0.54, then 0.55 would be sent to DFP; if the bid obtained from Polymorph is 0.52, then 0.50 would be sent to DFP\"\n}\n[/block]\n**Set Targeting Details**\nThe PublisherAdRequest Builder holds custom targeting and other similar targeting https://developers.google.com/mobile-ads-sdk/docs/dfp/android/targeting. You can add this to the DFP request by making use of the  <code>setPubAdRequestBuilder()</code> method as shown below\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PublisherAdRequest.Builder pubBuilder = new PublisherAdRequest.Builder();\\npubBuilder.addCustomTargeting(\\\"key\\\", \\\"value\\\").\\n           setContentUrl(\\\"https://www.example.com\\\");\\npolymorphBidder.setPubAdRequestBuilder(pubBuilder)\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Sample App\",\n  \"body\": \"You can take a look at the sample implementation of the whole code setup in our sample app. Check <code>DFPNativeAd.java</code> file here https://github.com/picatcha/adsnative-sdk-android/blob/master/sampleads/src/main/java/com/adsnative/sampleads/DFPNativeBannerAd.java\"\n}\n[/block]","excerpt":"","slug":"developer-setup-android-in-app-header-bidding-into-dfp-native-banner","type":"basic","title":"Developer Setup - Android In-App Header Bidding into DFP - Native-Banner"}

Developer Setup - Android In-App Header Bidding into DFP - Native-Banner


[block:api-header] { "title": "1. Add Google play services libraries" } [/block] Add the following Google play services libraries in your Gradle file [block:code] { "codes": [ { "code": "dependencies {\n compile 'com.google.android.gms:play-services-ads:15.0.1'\n compile 'com.google.android.gms:play-services-location:15.0.1'\n }", "language": "groovy" } ] } [/block] [block:api-header] { "title": "2. Create a header bidding request" } [/block] Copy <code>PolymorphAdapter.java</code> and <code>PolymorphBidder.java</code> files from https://github.com/picatcha/adsnative-sdk-android/tree/master/header_bidding/DFP to your application code. Initialise DFP class as you would normally do while integrating with DFP SDK [block:code] { "codes": [ { "code": "AdLoader adLoader = new AdLoader.Builder(context, DFP_AD_UNTI_ID)\n .forAppInstallAd(new OnAppInstallAdLoadedListener() {\n @Override\n public void onAppInstallAdLoaded(NativeAppInstallAd appInstallAd) {\n // Show the app install ad.\n }\n })\n .forContentAd(new OnContentAdLoadedListener() {\n @Override\n public void onContentAdLoaded(NativeContentAd contentAd) {\n // Show the content ad.\n }\n })\n .forPublisherAdView(new OnPublisherAdViewLoadedListener() {\n @Override\n public void onPublisherAdViewLoaded(PublisherAdView adView) {\n // Show the banner ad.\n }\n }, AdSize.BANNER)\n .withAdListener(new AdListener() {\n @Override\n public void onAdFailedToLoad(int errorCode) {\n // Handle the failure by logging, altering the UI, etc.\n }\n })\n .withNativeAdOptions(new NativeAdOptions.Builder()\n // Methods in the NativeAdOptions.Builder class can be\n // used here to specify individual options settings.\n .build())\n .withPublisherAdViewOptions(new PublisherAdViewOptions.Builder()\n // Methods in the PublisherAdViewOptions.Builder class can be\n // used here to specify individual options settings.\n .build())\n .build();", "language": "java" } ] } [/block] Import and initialise Polymorph bidder preferably in your main or parent activity class <code>onCreateView()</code> method by passing Context, Polymorph placement ID, AdLoader instance and banner ad size using <code>AdHelper.AdSize</code> enum : [block:code] { "codes": [ { "code": "PolymorphBidder polymorphBidder = new PolymorphBidder(this.getContext(), POLYMORPH_AD_UNIT_ID, adLoader, AdHelper.AdSize.BANNER_300x50);", "language": "java" } ] } [/block] [block:callout] { "type": "info", "body": "Make sure you pass the banner ad size using the<code>AdHelper.AdSize</code>Enum to indicate the size of the banner ad which you need from Polymorph. This has to be same as the size which you passed in DFP <code>forPublisherAdView()</code>call while creating the <code>AdLoader</code>instance", "title": "Banner Ad Size" } [/block] Call <code>loadDFPAd()</code> method via Polymorph bidder which will automatically handle header bidding while also pre-fetching ads from Polymorph to avoid network latency. DO NOT invoke <code>adLoader.loadAd()</code> as this is internally handled by PolymorphBidder. [block:code] { "codes": [ { "code": "polymorphBidder.loadDFPAd();", "language": "java" } ] } [/block] **Setting Bidding Interval** Set the bidding interval based on the price range that you've chosen while creating various yield partners. The default bid interval is 0.05. You'll need to use the <code>setBiddingInterval()</code> method as shown below: [block:code] { "codes": [ { "code": "polymorphBidder.setBiddingInterval(0.10);", "language": "java" } ] } [/block] _Note: This value can also be set from server-side. Please contact us if you want to do this_ [block:callout] { "type": "info", "body": "The bid thats obtained from Polymorph will be rounded off to the nearest multiple of bidding interval and then sent to DFP by key value targeting as the value of <code>ecpm</code> key. For instance, if the bidding interval is 0.05 and the bid obtained from Polymorph is 0.54, then 0.55 would be sent to DFP; if the bid obtained from Polymorph is 0.52, then 0.50 would be sent to DFP" } [/block] **Set Targeting Details** The PublisherAdRequest Builder holds custom targeting and other similar targeting https://developers.google.com/mobile-ads-sdk/docs/dfp/android/targeting. You can add this to the DFP request by making use of the <code>setPubAdRequestBuilder()</code> method as shown below [block:code] { "codes": [ { "code": "PublisherAdRequest.Builder pubBuilder = new PublisherAdRequest.Builder();\npubBuilder.addCustomTargeting(\"key\", \"value\").\n setContentUrl(\"https://www.example.com\");\npolymorphBidder.setPubAdRequestBuilder(pubBuilder)", "language": "java" } ] } [/block] [block:callout] { "type": "info", "title": "Sample App", "body": "You can take a look at the sample implementation of the whole code setup in our sample app. Check <code>DFPNativeAd.java</code> file here https://github.com/picatcha/adsnative-sdk-android/blob/master/sampleads/src/main/java/com/adsnative/sampleads/DFPNativeBannerAd.java" } [/block]