Search code examples
androidadmobbanneradbannerviewbanner-ads

Adding a banner ad unit id with Admob


In the admob documentation, it's written that:

An ad unit ID is a unique identifier given to the places in your app where ads are displayed. Create an ad unit for each activity your app will perform. If you have an app with two activities, for example, each displaying a banner, you need two ad units, each with its own ID. AdMob ad unit IDs have the form ca-app-pub-XXXXXXXXXXXXXXXX/NNNNNNNNNN.

With the example:

<string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string>

I have a few activities that will use banners ads. For each banner, I'll use a different string name for sure (i.e banner_ad1_unit_id, banner_ad2_unit_id...). My question is:

  • I guess I should change\invent the digits to be unique for each banner. Can I change all the digits of "3940256099942544/6300978111"? (without changing the beginning of "ca-app-pub-") or must I change only the digits of "6300978111" or specific ones?

I am asking because in some activities I may want to use 2 banners and in others I'll use only one.


Solution

  • I guess I should change\invent the digits to be unique for each banner.

    Ad Unit IDs are unique identifiers created in the AdMob console. The basic process goes like this:

    1. Create an AdMob account.
    2. Register an app for either Android or iOS.
    3. Create one or more ad units for the formats you want to display (banners, in this case).

    Each time you create an ad unit, AdMob will tell you the ID for it, so you can insert it into your code.

    Changing someone else's unit by altering a few digits (or simply inventing a new string of numbers) will not work. The server won't recognize the ID, and won't serve you any ads.

    For more information on how to register ad units, see this help center article.