Skip to content

Commit 5cf939c

Browse files
atamanataman
ataman
authored and
ataman
committed
v1.0.1: Ready. Minor fixes.
1 parent 8c55c6c commit 5cf939c

File tree

3 files changed

+92
-6
lines changed

3 files changed

+92
-6
lines changed

Diff for: README.md

+88-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,89 @@
11
# Android_AdNetworks_PrioritiesManager_with_RemoteControl
2-
Handle which ad network to use via a Firebase remote config. Ad types: interstitials, rewarded. Ad networks: UnityAds (mediated or standalone), IronSource. Add other ad networks implementations.
2+
* ***How to control a multiple standalone ad networks in one place?***
3+
* ***Maybe you need to use multiple mediation SDKs? How to set network priority?***
4+
* ***You can mix mediated SDKs with standalone SDKs or with another mediated SDKs.***
5+
* ***Enable/disable ad network remotely. Configure display priorities.***
6+
* ***Target countries for each ad network.***
7+
* ***Have you been looking for a well documented sample of UnityAds & UnityMediation for Android native?***
8+
* *My library not a mediation. Without control of mediated ads price.*
9+
10+
Implemented ad types: interstitials, rewarded.
11+
Ad networks: UnityAds (mediated or standalone), UnityMediation, SuperAwesome, Kidoz, IronSource.
12+
Written in **Kotlin**. No UI sample. Android library.
13+
14+
**My library will organize your common use cases for each ad network implementation that you will add.**
15+
## Use cases:
16+
1. Handle which ad network to enable/disable via a Firebase remote config.
17+
2. Define countries for each ad network. Currently separating LATAM region only.
18+
3. Define min/max Android version for each ad network.
19+
4. Processing data privacy: GDPR, CCPA, LGPD, ...
20+
5. Processing some user & device data for better targeting: app language, country, age, gender, phone/tablet..
21+
22+
[![](https://jitpack.io/v/Almaren/Android_AdNetworks_PrioritiesManager_with_RemoteControl.svg)](https://jitpack.io/#Almaren/Android_AdNetworks_PrioritiesManager_with_RemoteControl)
23+
24+
## Preparing:
25+
* Add to your project build.gradle:
26+
```
27+
allprojects {
28+
repositories {
29+
...
30+
maven { url 'https://jitpack.io' }
31+
}
32+
}
33+
```
34+
to the app build.gradle:
35+
```
36+
dependencies {
37+
implementation 'com.github.Almaren:Android_AdNetworks_PrioritiesManager_with_RemoteControl:1.0.1'
38+
}
39+
```
40+
* Add to your /android/../AndroidManifest.xml in your <activity> where the ads will be used:
41+
```
42+
<activity
43+
...
44+
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|mcc|mnc"
45+
/>
46+
```
47+
The necessary activities and overrides of ad networks are stored in my lib/AndroidManifest.xml.
48+
For better targeting some networks use coarse location, check if it required for you and complies with a Google policies, if so
49+
uncomment that line in the manifest.
50+
51+
## How to use:
52+
**All methods of AdManager must be called from the main ui thread.**
53+
1. Set app ID for each network in AdManager: APP_ID_YOUR_NET_AD.
54+
Set ad unit id for each network where marked "todo set your id".
55+
2. Implement interface lib.ads.event.AdUserDeviceDataBinder, in my case implemented by MainActivity.
56+
3. First init: call AdManager.initAds() in your Activity.create(..).
57+
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.
58+
4. Implement your own logic in AdManager.getConsentUserData().
59+
Implement age gate and consent dialog. Detect if user consent given for GDPR/CCPA/LGPD/PIPL.
60+
5. Enable/Disable test mode flags (marked as todo) in AdManager.createAdSources().
61+
6. Whenever your got a user ads data & consent state -> call AdManager.setPrivacyMetaData() to update ad networks with a privacy/consent data.
62+
7. Define default ad sources and their priority in AdSourcePriorityHandler.init().
63+
Define adSourceForLatam, or comment the content of method updatePrioritiesRegardingToUserRegion() if it's not relevant to you.
64+
8. To load and display ad unit type just call a suitable methods from the AdManager.
65+
Call dispose() on YourActivity.onDestroy().
66+
9. Not mandatory: implement performing actions on each ad state in AdUnitBaseHandler.
67+
68+
**Establishing Firebase remote config. (not mandatory)** *You can use the lib without firebase remote.*
69+
If your firebase project is configured skip to step #4.
70+
1. Create project in Firebase if not exist yet.
71+
2. Configure a project in Firebase Settings -> SDK setup and configuration.
72+
add release and debug SHA keys.
73+
3. Download google-services.json from a project settings and place to /YourProject/android folder.
74+
75+
4. Navigate in Firebase project to Remote config. Add parameter "adSourcesPriority" with the following value:
76+
```
77+
{"IronSrc":[-1,-1],"UnityAdsMediation":[2,2],"UnityAds":[1,-1]}
78+
```
79+
where array values indicates: [interstitial, rewarded],
80+
-1 = disabled, 1+ - priorities, the highest is more prioritized to display first.
81+
82+
5. Fetch once the remote config from the server whenever required by creating RemoteConfigCoordinator object, passing
83+
AdManager and just calling RemoteConfigCoordinator.fetchAllData().
84+
85+
86+
____________________________________________________________________________________________________
87+
**NOTICE:** © On modifying and expanding lib be sure to attribute the link in your code headers:
88+
https://github.com/Almaren
89+
Thank You!

Diff for: library/src/main/kotlin/com/almatime/lib/ads/AdSourcePriorityHandler.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object AdSourcePriorityHandler {
3737
val spanishAndPortuguese = setOf("ES", "PT")
3838
val latamLanguages = setOf(AppLangCode.PT, AppLangCode.ES)
3939

40-
lateinit var latestLangCode: AppLangCode
40+
private var latestLangCode: AppLangCode? = null
4141

4242
/** <b>MUST BE CALLED FIRST BEFORE FIRST USE OF THIS SINGLETON!!!</b> */
4343
fun init(userDeviceData: UserDeviceData) {
@@ -104,7 +104,7 @@ object AdSourcePriorityHandler {
104104
* Call it on language changing!
105105
*/
106106
fun updatePrioritiesRegardingToUserRegion(updateOnlyOnLocaleChange: Boolean, userDeviceData: UserDeviceData) {
107-
if (updateOnlyOnLocaleChange && userDeviceData.appLangCode == latestLangCode) {
107+
if (updateOnlyOnLocaleChange && latestLangCode?.let { userDeviceData.appLangCode == it } ?: false) {
108108
return
109109
}
110110
latestLangCode = userDeviceData.appLangCode
@@ -122,7 +122,6 @@ object AdSourcePriorityHandler {
122122
// rm adSourceForLatam
123123
adSourcesInterstitials = removeAdSource(adSourceForLatam, adSourcesInterstitials)
124124
adSourcesRewarded = removeAdSource(adSourceForLatam, adSourcesRewarded)
125-
//setAdSourceAsHighestPriority(AdSource.UnityAds)
126125
}
127126
Log.i("ads", "updatePrioritiesRegardingToUserRegion updated INTERSTITIALS: $adSourcesInterstitials, " +
128127
" REWARDED: $adSourcesRewarded")

Diff for: library/src/main/kotlin/com/almatime/lib/ads/AdUnitBaseHandler.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ abstract class AdUnitBaseHandler(val activity: Activity) : OnAdStateChange {
4545

4646
private fun loadAdSource(adSourceIndex: Int) {
4747
val sortedAdSources = getSortedAdSources()
48-
Log.i("ads", "LOAD adSourceIndex = $adSourceIndex = ${sortedAdSources[adSourceIndex]}")
4948
if (adSourceIndex > sortedAdSources.size - 1) return
49+
Log.i("ads", "LOAD adSourceIndex = $adSourceIndex = ${sortedAdSources[adSourceIndex]}")
5050

5151
adSources[sortedAdSources[adSourceIndex]]?.let {
5252
it.loadIfNotReady()
@@ -209,4 +209,4 @@ abstract class AdUnitBaseHandler(val activity: Activity) : OnAdStateChange {
209209
}
210210
}
211211

212-
}
212+
}

0 commit comments

Comments
 (0)