B4A Library FirebaseAdMob - Admob ads integrated with Firebase backend

Status
Not open for further replies.
Use FirebaseAdMob2 instead: https://www.b4x.com/android/forum/threads/firebaseadmob2-google-mobile-ads-sdk-v20.129609/

This library required B4A v6+.

This library allows showing AdMob ads. It is integrated with Firebase services so you can better track and analyze the results.
https://firebase.google.com/docs/admob/

It supports banner ads and interstitial ads (full screen ads).

First you need to follow the Firebase integration tutorial: https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/
Make sure to include the Ads manifest snippet.

Full example that shows a banner ad and an interstitial ad when clicking on the activity:
B4X:
Sub Process_Globals

End Sub

Sub Globals
   Private BannerAd As AdView
   Private IAd As InterstitialAd
End Sub

Sub Activity_Create(FirstTime As Boolean)
   BannerAd.Initialize2("BannerAd", "ca-app-pub-3940256099942544/6300978111", BannerAd.SIZE_SMART_BANNER)
   Dim height As Int
   If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
    'phones
    If 100%x > 100%y Then height = 32dip Else height = 50dip
   Else
    'tablets
    height = 90dip
   End If
   Activity.AddView(BannerAd, 0dip, 100%y - height, 100%x, height)
   BannerAd.LoadAd
   IAd.Initialize("iad", "ca-app-pub-3940256099942544/1033173712")
   IAd.LoadAd
End Sub

Sub Activity_Click
   If IAd.Ready Then IAd.Show
End Sub

Sub IAD_AdClosed
   IAd.LoadAd 'prepare a new ad
End Sub
These are test ids and they will show test ads.

Edit: It is also required to request user consent for personalized ads. See this tutorial: https://www.b4x.com/android/forum/threads/firebaseadmob-and-user-consent.93347/#post-590593

V1.60 - Few new requirements, explained here: https://www.b4x.com/android/forum/threads/firebaseadmob-v1-6.108552/
V1.50 - Adds support for requesting consent.
V1.31 - Fixes an issue related to InMobi mediation ads.
V1.30 - Adds support for rewarded video ads: https://www.b4x.com/android/forum/threads/firebaseadmob-rewarded-video-ads.71430/
V1.20 - Adds support for native ads: https://www.b4x.com/android/forum/t...integrated-with-firebase-backend.67710/page-3
https://www.b4x.com/android/forum/t...integrated-with-firebase-backend.67710/page-3
 
Last edited:

Douglas Farias

Expert
Licensed User
Longtime User
hi @Erel
many thx for this lib.

one question.
i not tested the lib, because i dont have b4a 6, i m waiting the email

this lib will support native ads for listviews, clv etc..?
and the video ads too will support?


thx again.

 

Douglas Farias

Expert
Licensed User
Longtime User
erel what the avaible events?

IAD_AdClosed etc...

Have event about error? clicked, opened etc...

the iad here is never ready i need to know why


Edit. i found this
B4X:
Sub iad_AdClosed
    iad.LoadAd 'prepare a new ad
End Sub

Sub iad_ReceiveAd
    Log("Received")
End Sub

Sub iad_FailedToReceiveAd (ErrorCode As String)
    Log("not Received - " &"Error Code: "&ErrorCode)
    iad.LoadAd
End Sub

Sub iad_adopened
End Sub

----------------------------------------------------------------------

The problem now is the error code: 0

- Make new app intersticial and get the code OK
- Sync with firebase and put the package name to download the json file OK
- Put the json file on the app folder OK

- Download the last sdk, google play services and etc... OK
- Add the permisions code at manifest OK
https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/
i made all this tutorial.

- Start the iad OK
B4X:
   iad.Initialize("iad","ca-app-pub-xxxxxxxxxxxxxx/xxxxxxxxx")
   iad.LoadAd

Error Log : Code 0 FAIL

what can is this error? its new app made only to test, this is not on google play or banned.
the code and tutorials are ok


EDIT
I m reinstaled the google play services again and now its working

thx again
 
Last edited:

Douglas Farias

Expert
Licensed User
Longtime User
@Erel
Just a simple question.
This lib need this?
B4X:
#AdditionalJar: android-support-v4
Like the old lib?

thx
 

itgirl

Active Member
Licensed User
Longtime User
Currently it only supports banner ads and interstitial ads.

If anyone likes I can post the source code of this library.

can you plz share the source so maybe we can extend it to support the rest ads?
 

sorex

Expert
Licensed User
Longtime User
I upgraded to v6.0
I added the lib to my additional libs folder
refreshed the list
when I select the firebaseadmob library I get what you see in the picture below...

 

sorex

Expert
Licensed User
Longtime User
I just read I had to install additional stuff for v6.0, will do that first and give another status later...
 

sorex

Expert
Licensed User
Longtime User
Adding these extra libraries solved my problem
 

sorex

Expert
Licensed User
Longtime User
first impressions...


it works well done!


it's bloated > app went from 1.4Mb to 2.34Mb compared to the old admob+googleplayservices method.

not sure if we can exclude some of the stuff that's not required when just using the ads part?


I'm not sure about the benefits of this FireBase thing, maybe it reflects tomorrow when the data from my tests are visible in the reports.
 

Douglas Farias

Expert
Licensed User
Longtime User
Hi @Erel
i m received this email from google admob, i dont know if cause any changes here.


Hello,
AdMob is committed to providing you the most effective monetization solutions. As we innovate, it is important to use the latest technologies to enhance our platform. As part of this move, we will disable the 6.4.1 and earlier versions of Ads SDK for Google mobile on Android on September 15, 2016.
To ensure your ads run after September 15, 2016, upgrade to the SDK mobile ads Google 7.0.0 or later.
SDKs ads for the latest Google mobile devices have much more advantages for you:
Continuous automatic updates. Users receive the changes in Ads SDK for Google mobile on Android continuously through the Google Play services so you can use your time on what's important
You do not have to spend time updating your applications with the latest versions of the SDK ads whenever it changes
Users also receive new features and bug fixes through Automatic Updates
Best user experience. The management of the application updates will be easier for users because some improvements will be received automatically in the background.
To upgrade your SDK add the latest version of Google Play services (facilities) in your Gradle Build configuration file. For example, see the following addition of v9.0:


B4X:
apply plugin: 'com.android.application'
...
dependencies {
    compile 'com.google.android.gms:play-services:9.0.2'
}

Stay tuned for more updates and tips.
Regards,




this will change something in this library? or will not change anything?

ps: google play services now is REV 31

thx
 
Last edited:

Computersmith64

Well-Known Member
Licensed User
Longtime User
Hi Erel,

I also received the email from AdMob advising of the impending deprecation of SDK 6.4.1. I have been using the mwAdmobInterstitial2 library for a long time & it works great, however I don't know what version of the AdMob SDK it uses - so I thought I'd switch to AdMob through Firebase. I'm also using the Google Play Services library written by NFOBoy for leaderboards & achievements (I know it's an old library, but it has worked well for me) & now after switching Admob to Firebase, I get the following error when I compile the app:


I'm guessing that there's some kind of conflict between the version of Google Play Services that Firebase is using & the version (v14 I think) that NFOBoy's library is using?

- Colin.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…