- How to control a multiple standalone ad networks in one place?
- Maybe you need to use multiple mediation SDKs? How to set network priority?
- You can mix mediated SDKs with standalone SDKs or with another mediated SDKs.
- Enable/disable ad network remotely. Configure display priorities.
- Target countries for each ad network.
- Have you been looking for a well documented sample of UnityAds & UnityMediation for Android native?
- My library not a mediation. Without control of mediated ads price.
Implemented ad types: interstitials, rewarded. Ad networks: Admob, UnityAds (mediated or standalone), Admob Mediation, Unity Mediation, SuperAwesome, Kidoz, IronSource. Written in Kotlin. No UI sample. Android library.
My library will organize your common use cases for each ad network implementation that you will add.
- Handle which ad network to enable/disable via a Firebase remote config.
- Define countries for each ad network. Currently separating LATAM region only.
- Define min/max Android version for each ad network.
- Processing data privacy: GDPR, CCPA, LGPD, ...
- Processing some user & device data for better targeting: app language, country, age, gender, phone/tablet..
- Add to your project build.gradle:
to the app build.gradle:
allprojects { repositories { ... maven { url 'https://jitpack.io' } } }
dependencies { implementation 'com.github.Almaren:Android_AdNetworks_PrioritiesManager_with_RemoteControl:1.0.2' }
- Add to your /android/../AndroidManifest.xml in your where the ads will be used:
The necessary activities and overrides of ad networks are stored in my lib/AndroidManifest.xml. For better targeting some networks use coarse location, check if it required for you and complies with a Google policies, if so uncomment that line in the manifest.
<activity ... android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|mcc|mnc" />
All methods of AdManager must be called from the main ui thread.
- Set app ID for each network in AdManager: APP_ID_YOUR_NET_AD. Set ad unit id for each network where marked "todo set your id". Check local.properties.
- Implement interface lib.ads.event.AdUserDeviceDataBinder, in my case implemented by MainActivity.
- First init: call AdManager.initAds() in your Activity.create(..). In my case calling it after age gate and consent dialog. At the second app launching I call it in a main page with already stored age and consent state.
- Implement your own logic in AdManager.getConsentUserData(). Implement age gate and consent dialog. Detect if user consent given for GDPR/CCPA/LGPD/PIPL.
- Enable/Disable test mode flags (marked as todo) in AdManager.createAdSources().
- Whenever your got a user ads data & consent state -> call AdManager.setPrivacyMetaData() to update ad networks with a privacy/consent data.
- Define default ad sources and their priority in AdSourcePriorityHandler.init(). Define adSourceForLatam, or comment the content of method updatePrioritiesRegardingToUserRegion() if it's not relevant to you.
- To load and display ad unit type just call a suitable methods from the AdManager. Call dispose() on YourActivity.onDestroy().
- Not mandatory: implement performing actions on each ad state in AdUnitBaseHandler.
Establishing Firebase remote config. (not mandatory) You can use the lib without firebase remote. If your firebase project is configured skip to step #4.
-
Create project in Firebase if not exist yet.
-
Configure a project in Firebase Settings -> SDK setup and configuration.
add release and debug SHA keys. -
Download google-services.json from a project settings and place to /YourProject/android folder.
-
Navigate in Firebase project to Remote config. Add parameter "adSourcesPriority" with the following value:
{"IronSrc":[-1,-1], "AdmobMediation":[3,3], "UnityAdsMediation":[2,2],"UnityAds":[1,-1]}
where array values indicates: [interstitial, rewarded], -1 = disabled, 1+ - priorities, the highest is more prioritized to display first.
-
Fetch once the remote config from the server whenever required by creating RemoteConfigCoordinator object, passing AdManager and just calling RemoteConfigCoordinator.fetchAllData().
NOTICE: © On modifying and expanding lib be sure to attribute the link in your code headers: https://github.com/Almaren Thank You!