Tag Archives: Developer

From a DFP Line Item to Mobile Ads SDK Code

Imagine you’ve just finished creating a line item targeting mobile devices in DFP, and your manager comes to you and says, “Bad news! Our Android developer was just eaten by a bear, so now it’s your job to get that line item into our new app.” Don’t worry! Displaying DFP ads in Android applications is surprisingly easy.

First, check your configuration

If you’re already using the Mobile Ads SDK in your project, you’re ready to go. If not, check our quick starts for Android Studio and Eclipse to learn the best way to include the SDK.

Retrieve your ad unit ID and size

To display your new line item, you’ll need to retrieve its ad unit ID from DFP. Log into your account, locate the ad unit that targets the new line item, and look for a “Generate tags” button to the right of its name. Clicking that button will display a dialog with some options for the type of tag to generate:

Select “Mobile applications” in the Tag Type dropdown, and you’ll see the correct ad unit ID and ad unit size for your line item. Armed with those two pieces of info, you’re ready to start coding.

Place a PublisherAdView

DFP banner ads are displayed with the PublisherAdView class. It’s possible to create instances on the fly and add them to a layout programmatically, but the better practice is to define them in your XML layout files. Here’s an example element:


<com.google.android.gms.ads.doubleclick.PublisherAdView
android:id="@+id/banner_ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="320x50"
ads:adUnitId="/1234567890/DemoAccount/BearRepellent"/>

Note the adSize and adUnitId attributes. These should be set to match the ad unit ID and size shown in the Generate Tags dialog. See our banner guide for more information about setting custom or multiple sizes.

Request an ad

With the PublisherAdView defined in your layout file, you just need to add a few lines of code to its corresponding Java class:


PublisherAdView adView = (PublisherAdView)findViewById(R.id.banner_ad);
PublisherAdRequest request = new PublisherAdRequest.Builder().build();
adView.loadAd(request);

PublisherAdRequest.Builder is a factory class that builds PublisherAdRequest objects. This example uses a simple, unmodified request, but there are a number of ways to add custom targeting, network extras, and test device information when building your own. See the targeting section of our banner guide for details.

Enjoy your line item

With the layout updated and request code in place, your app is ready to show an ad!

Feel free to use the code from this example in your own applications, and if you have any questions, come and see us on our forum.

LineItemService, or Line_Item PQL Table?

One of the most used services in the DFP API is the LineItemService. Many of you are already utilizing the Line_Item table in the PublisherQueryLanguageService to create match tables on fields like Status or ExternalId, but with newer API versions, more and more fields are available as columns. Did you know that as of v201411 the Line_Item table includes a column for Targeting? With so many line item fields now accessible through PQL, the Line_Item table might be a viable replacement for your read operations.

What's the advantage? Faster response times. As an example, I pulled 5,000 line items from a network using both the LineItemService and the Line_Item PQL Table, printing page offsets as the results arrived. Take a look at the results:

* Actual response times may vary. Line item fields only available in participating PQL Tables.

Using the PublisherQueryLanguageService shaved off 17 seconds for a respectable speed increase of 15%.

However, if your application doesn't need some of the heavier fields, you'll see a much bigger gain. Check out what happens when we leave out Targeting:

The sparse selection offered by the PublisherQueryLangugeService means our data size is smaller, cutting the total time by a whopping 45%!

If you're looking for a performance boost in your LineItem read operations, give the Line_Item table a try. We've got example code in each of our client libraries to get you started. If you have any questions, don't hesitate to reach out to us on our API forums.

We’re fixing an issue impacting Quality Score reporting in AdWords

If you read Quality Score metrics programmatically from the AdWords API, please be aware that the values reported by the API, starting from around 11am PT on March 26, 2015, may have been artificially low. Correct values are currently being restored, and should be fully stabilized within 24 hours.

This issue is limited to Quality Score reporting only. Auction time signals of quality, which are the signals actually used within the auction for computing Ad Rank and serving ads, are unaffected.

- Adam Ohren, AdWords API Team

IMA Android SDK Beta 10 released

Today we're releasing Beta 10 of the IMA Android SDK. This is primarily a service release to address performance and bug fixes, but the release also includes some API changes to be aware of.

Changes in Beta 10

  • Added ImaSdkSettings.getMaxRedirects and ImaSdkSettings.setMaxRedirects.
  • IMA API classes are now final.
  • The following AdError.AdErrorCode values have been removed:
    • API_ERROR - instead use UNKNOWN_AD_RESPONSE.
    • PLAYLIST_MALFORMED_RESPONSE - instead use UNKNOWN_AD_RESPONSE.
    • REQUIRED_LISTENERS_NOT_ADDED - was not being raised by the SDK.
    • VAST_INVALID_URL - instead use VAST_LOAD_TIMEOUT.
  • Bug fixes.

Download IMA Android SDK Beta 10

You can get this latest release of the IMA Android SDK from our IMA SDK downloads page.

Check out the release notes page to stay up to date on IMA Android SDK releases.

Other questions?

As always, feel free to drop us a line on the IMA SDK forum and follow our Google+ page for other announcements and updates.

New features in AdWords Scripts

We are excited to announce two new features for AdWords scripts:

AdWords API v201502 reports

AdWords scripts now support AdWords API v201502 reports. The new version introduces two new reports: USER_AD_DISTANCE_PERFORMANCE_REPORT and LABEL_REPORT. We also introduced several new columns, renamed some columns to make them consistent with the AdWords UI, and removed some duplicate columns. See the AdWords API release notes for more details.

If you use API versioning in your reports, you’ll need to modify your code to use v201502 as shown:

var report = AdWordsApp.report(query, {
apiVersion: 'v201502'
});
If you don’t use API versioning, your scripts will now default to v201502 reports. If your scripts access one of the removed or renamed columns, you may need to fix that column name in your scripts.

JDBC

JDBC allows your scripts to connect to external databases through the JDBC service, a wrapper around the standard Java Database Connectivity technology. In Apps Script, the JDBC service supports Google Cloud SQL, MySQL, Microsoft SQL Server, and Oracle databases. See our guide for more details.

If you have any questions about these features or AdWords scripts in general, you can post them on our developer forum.

Shopping utility available in the AdWords API Java client library

We've got good news for Java developers using the AdWords API to manage Shopping campaigns: the Java client library now has a set of utilities that greatly simplifies the process of setting up your product partition trees.

The utilities let you focus on your use case, avoid boilerplate code, make your code more readable, and reduce the amount of code needed for common actions.

For example, the updated AddProductPartitionTree code sample that uses the utility is 65% shorter than the previous version.

Intrigued? Check out the product partition utility guide on github, and let us know what you think!

If you would like to have a similar utility in a different client library, register your interest by opening a github issue on that library's issues page.

Learn more

If you haven't started using Shopping campaigns, the following resources are a great place to start: Still have questions? Feel free to visit us on the AdWords API Forum or our Google+ page.

Announcing v7.0 of the Google Mobile Ads SDK for Android

Today we’re announcing the release of v7.0 of the Google Mobile Ads SDK! It’s listed as Google Play services (Rev. 23) in the Android SDK manager, and is available for download right now. Those of you using Android Studio can download Google Repository (Rev. 16) to get the latest Gradle artifacts. This release contains a number of stability and performance improvements, as well as some new features.

DFP developers can take advantage of two other new methods in PublisherAdRequest.Builder: addCustomTargeting and addCategoryExclusion.

Previously, developers had to add custom targeting information to a request by creating a Bundle and passing it to addNetworkExtrasBundle. This can now be done with a simple call to the addCustomTargeting method:


PublisherAdRequest newRequest = new PublisherAdRequest.Builder()
.addCustomTargeting("some_key", "some_value")
.addCustomTargeting("some_other_key", aListOfStringValues)

.build();

The new addCategoryExclusion method makes setting a slot-level category exclusion label for a request just as straightforward:


PublisherAdRequest newRequest = new PublisherAdRequest.Builder()
.addCategoryExclusion("some_unwanted_category")
.addCategoryExclusion("some_other_unwanted_category")

.build();

Another new feature is the setRequestAgent method that’s been added to AdRequest.Builder and PublisherAdRequest.Builder. Third party libraries that reference the Mobile Ads SDK should call this method to denote the platform from which the ad request originated. For example, if a third-party ad network called "CoolAds" mediates requests to the Mobile Ads SDK, it should call this method with "CoolAds":


AdRequest newRequest = new AdRequest.Builder()
.setRequestAgent("CoolAds")
.build();

This SDK release coincides with version 7.0 of Google Play services, which was recently announced on the Android Developer blog. For a full list of Mobile Ads SDK changes, check out our release notes. For technical questions, post them on our forum.