I have searched online but had not luck so far in my research, I have set up admobs in my android app and now I only want relevant ads to show up based on keyword that I set. My app is based on toys, so I only want ads related to toys to show
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
Looking at this: Admob ad on custom Dialog
This person has used:
AdRequest request = new AdRequest();
Set<String> keywords = new HashSet<String>();
keywords.add("game");
request.setKeywords(keywords);
However, this does not work.
I think you need this:
AdRequest request = new AdRequest.Builder()
.addKeyword("game").build();
.adView.loadAd(request);
You can try with this, but here are some examples, maybe you find what you allso need:
1.Test ads
Set up test ads by passing your hashed Device ID to AdRequest.Builder.addTestDevice:
AdRequest request = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // All emulators
.addTestDevice("AC98C820A50B4AD8A2106EDE96FB87D4") // An example device ID
.build();
2.Location
Location targeting information may also be specified in the AdRequest:
AdRequest request = new AdRequest.Builder()
.setLocation(location)
.build();
3.Gender
If your app already knows a user's gender, it can provide that information in the ad request for targeting purposes. The information is also forwarded to ad network mediation adapters if mediation is enabled.
AdRequest request = new AdRequest.Builder()
.setGender(AdRequest.GENDER_FEMALE)
.build();
4.Birthday
If your app already knows a user's birthday, it can provide that information in the ad request for targeting purposes. This information is also forwarded to ad network mediation adapters if mediation is enabled.
AdRequest request = new AdRequest.Builder()
.setBirthday(new GregorianCalendar(1985, 1, 1).getTime())
.build();
5.Designed for Families setting
If you have opted your app in to Google Play's Designed for Families program and you show ads in your app, you need to ensure those ads comply with the Designed for Families program requirements and ad policies.
Ad requests can be tagged as designed for families by setting the is_designed_for_families parameter to true in the extras:
Bundle extras = new Bundle();
extras.putBoolean("is_designed_for_families", true);
AdRequest request = new AdRequest.Builder()
.addNetworkExtrasBundle(AdMobAdapter.class, extras)
.build();
6.Child-directed setting
For purposes of the Children's Online Privacy Protection Act (COPPA), there is a setting called "tag for child directed treatment".
As an app developer, you can indicate whether you want Google to treat your content as child-directed when you make an ad request. If you indicate that you want Google to treat your content as child-directed, we will take steps to disable IBA and remarketing ads on that ad request. The setting can be used with all versions of the Google Play services SDK, via AdRequest.Builder.tagForChildDirectedTreatment(boolean):
If you set tagForChildDirectedTreatment to true, you will indicate that your content should be treated as child-directed for purposes of COPPA.
If you set tagForChildDirectedTreatment to false, you will indicate that your content should not be treated as child-directed for purposes of COPPA.
If you do not set tagForChildDirectedTreatment, ad requests will include no indication of how you would like your content treated with respect to COPPA.
AdRequest request = new AdRequest.Builder() .tagForChildDirectedTreatment(true) .build();
By setting this tag, you certify that this notification is accurate and you are authorized to act on behalf of the owner of the app. You understand that abuse of this setting may result in termination of your Google account.
7.Keyword
Add a keyword for targeting purposes.
AdRequest request = new AdRequest.Builder() .addKeyword(someKeyword) .build();
Loading an ad with targeting
Once your request targeting information is set, call loadAd on the AdView with your AdRequest instance.
AdRequest request = new AdRequest.Builder()
.setLocation(location)
.setGender(AdRequest.GENDER_FEMALE)
.setBirthday(new GregorianCalendar(1985, 1, 1).getTime())
.tagForChildDirectedTreatment(true)
.addKeyword("game")
.build();
adView.loadAd(request);
Additional information can be found on this link.
After doing some research, it does not look like keywords are supported.
There have been various questions over the years that all have the same answer:
The documentation for targeting ads does not include any information on using keywords.
You can add keywords to your AdRequest using addKeyword(String keyword) in AdRequest.Builder, which is documented here. An example call would be like below:
AdRequest adRequest = new AdRequest.Builder().addKeyword("game").build();
adView.loadAd(adRequest);
However, as stated above- it does not look like these keywords are being used on the backend.
The AdMob support site shows that there are three ways advertisers can choose to target their ads- context (keywords, presumably implicit rather than explicit), placement, and interest.
You can filter outside of your app by allowing and blocking ads, which if you truly do only want to show ads related to toys, then you will have to block everything except the toys category shown in the general category list.
You can try doing this :
AdRequest.Builder builder = new AdRequest.Builder()
.addKeyword("game");
Now you can build the adrequest.
As per the documentation to add a keyword for targeting purposes.
You can use this single line code.
public AdRequest.Builder addKeyword (String keyword)
Related
There isn't much documentation on this. I was wondering, should we first call
RequestConfiguration conf= new RequestConfiguration.Builder()
.setMaxAdContentRating(
MAX_AD_CONTENT_RATING_T)
.build();
MobileAds.setRequestConfiguration(conf);
MobileAds.initialize(context, APP_ID);
Or
MobileAds.initialize(context, APP_ID);
RequestConfiguration conf= new RequestConfiguration.Builder()
.setMaxAdContentRating(
MAX_AD_CONTENT_RATING_T)
.build();
MobileAds.setRequestConfiguration(conf);
In https://developers.google.com/admob/android/quick-start
Although Google recommend calling MobileAds.initialize as early as possible
Before loading ads, have your app initialize the Mobile Ads SDK by
calling MobileAds.initialize() which initializes the SDK and calls
back a completion listener once initialization is complete (or after a
30-second timeout). This needs to be done only once, ideally at app
launch.
They also mention "request-specific flags" need to be set before MobileAds.initialize.
Warning: Ads may be preloaded by the Mobile Ads SDK or mediation
partner SDKs upon calling MobileAds.initialize(). If you need to
obtain consent from users in the European Economic Area (EEA), set any
request-specific flags (such as tagForChildDirectedTreatment or
tag_for_under_age_of_consent), or otherwise take action before loading
ads, ensure you do so before initializing the Mobile Ads SDK.
So, not super clear on which should be called first.
According to Google Developer support, the following is the right way to do
https://groups.google.com/forum/#!category-topic/google-admob-ads-sdk/android/17oVu0sABjs
RequestConfiguration conf= new RequestConfiguration.Builder()
.setMaxAdContentRating(
MAX_AD_CONTENT_RATING_T)
.build();
MobileAds.setRequestConfiguration(conf);
MobileAds.initialize(context, APP_ID);
It's done as such:
MobileAds.RequestConfiguration =
new RequestConfiguration
.Builder()
.SetTagForChildDirectedTreatment(RequestConfiguration.TagForChildDirectedTreatmentTrue)
.SetMaxAdContentRating(RequestConfiguration.MaxAdContentRatingG)
#if DEBUG
.SetTestDeviceIds(new[] { "..." })
#endif
.Build();
according to the official documentation
Before loading ads, have your app initialize the Mobile Ads SDK by calling MobileAds.initialize() which initializes the SDK and calls back a completion listener once initialization is complete (or after a 30-second timeout). This needs to be done only once, ideally at app launch.
So , you should initialize MobileAds first ,look at the example here form the official documentation :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
I am using admob to display ads in my android app. I can add single Test Device using addTestDevice("DEVICE_ID")
But how to add multiple devices as Test Devices?
I tried addTestDevice("DEVICE_ID_1, DEVICE_ID_2, DEVICE_ID_3") but its not working.
Call addTestDevice for each device_id.
Builder adRequestBuilder = new AdRequest.Builder();
adRequestBuilder.addTestDevice(DEVICE_ID_1);
adRequestBuilder.addTestDevice(DEVICE_ID_2);
adRequestBuilder.addTestDevice(DEVICE_ID_3);
...
AdRequest adRequest = adRequestBuilder.build();
You can call this method multiple times before build it.
From the google api docs:
AdRequest request = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // All emulators
.addTestDevice("AC98C820A50B4AD8A2106EDE96FB87D4") // My Galaxy Nexus test phone
.build();
So you can add an unlimited number of devices in the same request by just calling addTestDevice again.
Or you can do it in the xml like the comment of karan mer suggested.
Add this way and to get device id check this post
.addTestDevice("DEVICE_ID_1")
.addTestDevice("DEVICE_ID_2")
.addTestDevice("DEVICE_ID_3")
I have set up an AdMob mediation in my android app, it's working fine, but I also want AdMob to mediate interstitial ads from the other providers. I was unable to find any help or documentation on that, so I am asking here.
This is the code I have for the banner mediation:
MMSDK.initialize(this);
millennialExtras = new MillennialAdapterExtras();
inmobiExtras = new InMobiAdapterExtras();
mopubExtras = new MoPubExtras();
FlurryAgent.init(this, "some id");
flurryExtras = new FlurryAdapterExtras();
mAdView = (AdView) findViewById(R.id.adView);
adRequest = new AdRequest.Builder()
.addNetworkExtras(millennialExtras)
.addNetworkExtras(inmobiExtras)
.addNetworkExtras(mopubExtras)
.build();
mAdView.loadAd(adRequest);
And then the ads start rolling.
Now for the interstitials, I am trying to do it like this:
in onCreate I have this:
interstitialAd = new InterstitialAd(MainActivity.this);
interstitialAd.setAdUnitId("some id");
adRequestInterstitial = new AdRequest.Builder()
.addNetworkExtras(millennialExtras)
.addNetworkExtras(inmobiExtras)
.addNetworkExtras(mopubExtras)
.build();
interstitialAd.loadAd(adRequestInterstitial);
and then I have this button for showing interstitial:
public void showInterstitial(View v) {
interstitialAd.show();
}
My problem is, that I don't know if this is the proper way to do it. I use the same adapter objects for both the AdMob banner and the AdMob interstitial. I have added the needed networks and ad spaces in AdMob dashboard for the interstitial ad space.
So is this way correct?
You can definitely mediate interstitials for other ad networks using Admob mediation. And the way that you have done it is exactly correct.
I would like to an admob banner in my app, showing ads in specific categories (every device would have a specific categories).
For example, app installed on one device would show only music, other would show only travel, etc.
I looked in Google developers guide and PublisherAdRequest API and notice the following example:
// Example: Pass custom targeting "Age=25", "Color=Blue,Green,Red"
private PublisherAdRequest createRequest() {
Bundle bundle = new Bundle();
bundle.putString("Age", "25");
bundle.putString("Color", "Blue,Green,Red");
return new PublisherAdRequest.Builder()
.addNetworkExtras(new AdMobExtras(bundle))
.build();
}
My question is - What keywords are available for me?
If I would like to get only Music and travel related ads, what keywords should I use?
Is there another way to do it?
I've been trying to get AdMob to work for some time on my app. I keep getting onFailedToRecieveAd(Invalid Ad Request) message in the log. I've paired down my test application to this:
AdView adView;
LinearLayout ll;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adView = new AdView(this, AdSize.BANNER, "pub-2...............");//inserted my 16 digit pub id here
adView.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(adView);
setContentView(ll);
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice("3...............");// 16 digits, tried other strings as
// follows:
//for addTestDevice I've tried several numbers, including the 16 digit device
// number given me by my "device id" application, the "0123456789ABCDEF" device number
// given by my console and device windows, the "CECE.........................." 32 digit
// device number my logcat file told me to use in a logcat message,
// "AdRequest.TEST_EMULATOR"
// which an admob example in the docs said to use, "9774d56d682e549c" which another
// admob docs example said to use.
adView.loadAd(adRequest);
I've also tried adView.loadAd(new AdRequest()); using no device id as in another one of the google admob example apps.
nothing has worked to show anything, it's not even creating space for the ad, just the onFailedToRecieveAd(Invalid Ad Request) message in the logcat
I've also included the necessary permissions and "com.google.ads.AdActivity" in the manifest.
Wow, after days of frustration and posts to various forums I've found the answer.
You have to go to your account on the Admob website to set up your specific app for the admob ads and get a new longer publisher number. My publisher number only started with 'pub-......' where my new number is longer and starts with 'ca-app-pub-.......'. I was curious about this from the start when I saw the 'ca-app-pub' preface in an example banner ap.
Nowhere on the Google Admob "Google Mobile Ads SDK" development site in the "banner ads 1" instructions (https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals?hl=en_US#android) does it mention having to go back to your admob account to set up your specific app for ads and get a new publisher number.
The stupid mistakes are the hardest to fix.
Be carefull with the id, there are 2 codes: the editor number (like this: pub-xxxxxxxxxxxxxxxx) and the other is the banner id (like this: ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx) (this one you need to use)
You need to use the last one, if you use the first doesnt work:)
It is not unusual to get a failed to receive ad. This is a normal message essentially saying that there are no ads to serve for your app at this point in time.
It means that your Admob integration is working, you are getting a response back from the server. As your app sends more requests it will be more likely to receive ad impressions.
Have you tried requesting an ad without setting the test device ID?
adView.loadAd(new AdRequest());
Try adding the following lines of code to get more info about the failure:
// Set AdListener
adView.setAdListener(new AdListener() {
#Override
public void onFailedToReceiveAd(Ad ad, ErrorCode error) {
System.err.println("Ad failed: " + ad.toString() + error.toString());
}
#Override
public void onReceiveAd(Ad ad) {
System.out.println("Ad received: " + ad.toString());
}
});