Google DFP - Android Studio¶
Pulse can also perform real-time geo-targeting and dynamic creative personalisation for display ads.
This capability currently works with Google DFP, when an app is in the foreground (i.e.open)
Google DFP SDK
Set up DFP SDK as per Google’s instructions and verify you can display ads without using Pulse: https://developers.google.com/mobile-ads-sdk/docs/dfp/android/quick-start
Enable Pulse capability
Enable Pulse capability on the Activities where ads are being shown:
-
Use the enablePulseDFP method to enable Pulse
-
Use Pulse’s getDFPCustomParameters method to execute showPulseDFP E.g.:
@Override protected void onResume() { super.onResume(); // Enable Pulse DFP feature String result = mApplication.getPulseSDKInstance().enablePulseDFP(this); // Verify instantiation if(success.equalsIgnoreCase(result)) { @SuppressWarnings("static-access") HashMap<String,String> mDFPCustomParameters = mApplication.getPulseSDKInstance().getDFPCustomParameters(); if((null != mDFPCustomParameters)&&(mDFPCustomParameters.size()==8)) { showPulseDFP(mDFPCustomParameters); }else { showDefaultDFP(); } }else { //Pulse DFP is not available showDefaultDFP(); } }
- Use disablePulseDFP to disable Pulse ads when app is not open E.g.:
@Override protected void onPause() { String result = mApplication.getPulseSDKInstance().disablePulseDFP(); super.onPause(); }
- Use addCustomTargeting in showPulseDFP to pass a user’s real time location needs to Google DFP E.g.:
private void showPulseDFP(HashMap<String, String> mDFPCustomParameters) { if(true != mPulseDFP) { mPulseDFP = true; if((null != mDFPCustomParameters)&&(mDFPCustomParameters.size()==8)) { // Add customer parameters to DFP Iterator<String> keySetIterator = mDFPCustomParameters.keySet().iterator(); String[] pulseDfpKey = new String[mDFPCustomParameters.size()]; String[] pulseDfpKeyValue = new String[mDFPCustomParameters.size()]; int index = 0; while(keySetIterator.hasNext()){ String key = keySetIterator.next(); pulseDfpKey[index] = key; pulseDfpKeyValue[index] = mDFPCustomParameters.get(key); index++; } PublisherAdRequest newRequest = new PublisherAdRequest.Builder() // Remove in Production .addTestDevice("951599B6898217134B31EEB6E9145F9") // Pulse DFP Targeting .addCustomTargeting(pulseDfpKey[0],pulseDfpKeyValue[0]) .addCustomTargeting(pulseDfpKey[1],pulseDfpKeyValue[1]) .addCustomTargeting(pulseDfpKey[2],pulseDfpKeyValue[2]) .addCustomTargeting(pulseDfpKey[3],pulseDfpKeyValue[3]) .addCustomTargeting(pulseDfpKey[4],pulseDfpKeyValue[4]) .addCustomTargeting(pulseDfpKey[5],pulseDfpKeyValue[5]) .addCustomTargeting(pulseDfpKey[6],pulseDfpKeyValue[6]) .addCustomTargeting(pulseDfpKey[7],pulseDfpKeyValue[7]) // Media DFP Targeting .addCustomTargeting("keyword","mobile_banner") .build(); mPublisherAdView.loadAd(newRequest); }else { Log.i(TAG,"mDFPCustomParameters==Null , mDFPCustomParameters.size()!=8"); } }else { Log.i(TAG, " mPulseDFP ==true"); } } private void showDefaultDFP() { PublisherAdRequest newRequest = new PublisherAdRequest.Builder() // Remove in Production .addTestDevice("951599B6898217134B31EEB6E9145F9") // DFP Targeting .addCustomTargeting("keyword","mobile_banner") .build(); mPublisherAdView.loadAd(newRequest); }