Skip to content

Commit 5197bfd

Browse files
authored
Merge pull request #82 from amirisback/develop/ad-consent-EEA-UK
DEVELOP :: AD Consent For Countries EEA and UK
2 parents 77c3726 + c410861 commit 5197bfd

File tree

12 files changed

+99
-34
lines changed

12 files changed

+99
-34
lines changed

README.md

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
## Version Release
3333

34-
$version_release = 5.3.2
34+
$version_release = 5.3.3
3535

3636
// Suport Library
3737
$admob_version = 22.1.0 // https://developers.google.com/admob/android/sdk
@@ -83,16 +83,16 @@ allprojects {
8383
implementation 'com.unity3d.ads:unity-ads:${unity_ad_version}'
8484

8585
// library frogo-admob (Required - Recomended)
86-
implementation 'com.github.amirisback:frogo-admob:5.3.2'
86+
implementation 'com.github.amirisback:frogo-admob:5.3.3'
8787

8888
// -----------------------------------------------------------------------------------------
8989
// For Single Library Patch
9090

9191
// library frogo-admob (Admob Only)
92-
implementation 'com.github.amirisback.frogo-admob:ad-admob:5.3.2'
92+
implementation 'com.github.amirisback.frogo-admob:ad-admob:5.3.3'
9393

9494
// library frogo-admob (Unity Ads Only)
95-
implementation 'com.github.amirisback.frogo-admob:ad-unityad:5.3.2'
95+
implementation 'com.github.amirisback.frogo-admob:ad-unityad:5.3.3'
9696
}
9797

9898
#### <Option 2> Kotlin DSL
@@ -105,16 +105,16 @@ allprojects {
105105
implementation("com.unity3d.ads:unity-ads:${unity_ad_version}")
106106

107107
// library frogo-admob (Required - Recomended)
108-
implementation("com.github.amirisback:frogo-admob:5.3.2")
108+
implementation("com.github.amirisback:frogo-admob:5.3.3")
109109

110110
// -----------------------------------------------------------------------------------------
111111
// For Single Library Patch
112112

113113
// library frogo-admob (Admob Only)
114-
implementation("com.github.amirisback.frogo-admob:ad-admob:5.3.2")
114+
implementation("com.github.amirisback.frogo-admob:ad-admob:5.3.3")
115115

116116
// library frogo-admob (Unity Ads Only)
117-
implementation("com.github.amirisback.frogo-admob:ad-unityad:5.3.2")
117+
implementation("com.github.amirisback.frogo-admob:ad-unityad:5.3.3")
118118

119119
}
120120

@@ -822,6 +822,42 @@ fun FrogoAdmobBannerView(
822822

823823
```
824824

825+
## User Messaging Platform (UMP)
826+
827+
### How to use
828+
```kotlin
829+
showAdConsent(object : IFrogoAdConsent {
830+
831+
override fun activity(): Activity {
832+
return this@MainActivity
833+
}
834+
835+
override fun isDebug(): Boolean {
836+
return BuildConfig.DEBUG
837+
}
838+
839+
override fun isUnderAgeAd(): Boolean {
840+
return false
841+
}
842+
843+
override fun onNotUsingAdConsent() {
844+
// On Not Using Ad Consent
845+
}
846+
847+
override fun onConsentSuccess() {
848+
// On Consent Success
849+
}
850+
851+
override fun onConsentError(formError: FormError) {
852+
// On Consent Error
853+
}
854+
855+
})
856+
```
857+
858+
### Notes
859+
- Read This [Stack Overflow](https://stackoverflow.com/questions/65351543/how-to-implement-ump-sdk-correctly-for-eu-consent?rq=3)
860+
825861
## Allert
826862

827863
### Update

ad-admob/src/main/java/com/frogobox/admob/core/FrogoAdConsent.kt

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.frogobox.admob.core
22

3+
import android.content.Context
4+
import android.telephony.TelephonyManager
35
import com.google.android.ump.ConsentDebugSettings
46
import com.google.android.ump.ConsentInformation
57
import com.google.android.ump.ConsentRequestParameters
@@ -22,9 +24,42 @@ import com.google.android.ump.UserMessagingPlatform
2224

2325
object FrogoAdConsent {
2426

27+
fun getCountryCode(context: Context): String {
28+
val tm = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
29+
return tm.networkCountryIso.uppercase()
30+
}
31+
32+
fun listEEACountry(): List<String> {
33+
return listOf(
34+
"AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", "HU", "IE",
35+
"IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE"
36+
)
37+
}
38+
39+
fun listUKCountry(): List<String> {
40+
return listOf("GB", "GG", "IM", "JE")
41+
}
42+
43+
fun listAdConsentCountry(): List<String> {
44+
return listEEACountry() + listUKCountry()
45+
}
46+
47+
fun isAdConsentCountry(context: Context): Boolean {
48+
return listAdConsentCountry().contains(getCountryCode(context))
49+
}
50+
2551
fun showConsent(callback: IFrogoAdConsent) {
52+
if (isAdConsentCountry(callback.activity())) {
53+
setupConsent(callback)
54+
} else {
55+
callback.onNotUsingAdConsent()
56+
}
57+
}
58+
59+
private fun setupConsent(callback: IFrogoAdConsent) {
2660

27-
val consentInformation: ConsentInformation = UserMessagingPlatform.getConsentInformation(callback.activity())
61+
val consentInformation: ConsentInformation =
62+
UserMessagingPlatform.getConsentInformation(callback.activity())
2863

2964
// Set tag for underage of consent. false means users are not underage.
3065
val params = if (callback.isDebug()) {
@@ -47,15 +82,18 @@ object FrogoAdConsent {
4782
}
4883

4984
consentInformation.requestConsentInfoUpdate(callback.activity(), params,
50-
{ // The consent information state was updated.
85+
{
86+
// The consent information state was updated.
5187
// You are now ready to check if a form is available.
5288
if (consentInformation.isConsentFormAvailable) {
5389
loadForm(consentInformation, callback)
90+
} else {
91+
callback.onNotUsingAdConsent()
5492
}
5593
},
56-
{
94+
{ formError ->
5795
// Handle the error.
58-
callback.onConsentError(it)
96+
callback.onConsentError(formError)
5997
})
6098
}
6199

@@ -72,6 +110,8 @@ object FrogoAdConsent {
72110
// Handle dismissal by reloading form.
73111
loadForm(consentInformation, callback)
74112
}
113+
} else if (consentInformation.consentStatus == ConsentInformation.ConsentStatus.NOT_REQUIRED) {
114+
callback.onNotUsingAdConsent()
75115
}
76116
}, { formError ->
77117
// Handle the error.

ad-admob/src/main/java/com/frogobox/admob/core/FrogoAppOpenAdManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import com.google.android.gms.ads.AdRequest
1010
import com.google.android.gms.ads.FullScreenContentCallback
1111
import com.google.android.gms.ads.LoadAdError
1212
import com.google.android.gms.ads.appopen.AppOpenAd
13-
import java.util.*
13+
import java.util.Date
1414

1515
/**
1616
* Created by Faisal Amir on 24/10/22

ad-admob/src/main/java/com/frogobox/admob/core/IFrogoAdConsent.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ interface IFrogoAdConsent {
2323

2424
fun isUnderAgeAd(): Boolean
2525

26+
fun onNotUsingAdConsent()
27+
2628
fun onConsentSuccess()
2729

2830
fun onConsentError(formError: FormError)

ad-admob/src/main/java/com/frogobox/admob/core/IFrogoAdmob.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
package com.frogobox.admob.core
22

33
import android.content.Context
4-
import android.widget.RelativeLayout
5-
import androidx.appcompat.app.AppCompatActivity
6-
import com.frogobox.admob.callback.FrogoAdmobBannerCallback
7-
import com.frogobox.admob.callback.FrogoAdmobInterstitialCallback
8-
import com.frogobox.admob.callback.FrogoAdmobRewardedCallback
9-
import com.google.android.gms.ads.AdSize
10-
import com.google.android.gms.ads.AdView
114

125
/**
136
* Created by Faisal Amir

ad-admob/src/main/java/com/frogobox/admob/ui/AdmobActivity.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import android.os.Bundle
44
import androidx.appcompat.app.AppCompatActivity
55
import com.frogobox.admob.delegate.AdmobDelegates
66
import com.frogobox.admob.delegate.AdmobDelegatesImpl
7-
import com.frogobox.sdk.ext.showLogDebug
87

98
/**
109
* Created by Faisal Amir on 07/02/23

ad-admob/src/main/java/com/frogobox/admob/ui/AdmobBindActivity.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
package com.frogobox.admob.ui
22

3-
import android.os.Bundle
4-
import androidx.appcompat.app.AppCompatActivity
53
import androidx.viewbinding.ViewBinding
6-
import com.frogobox.admob.delegate.AdmobDelegates
7-
import com.frogobox.admob.delegate.AdmobDelegatesImpl
8-
import com.frogobox.sdk.ext.showLogDebug
94

105
/**
116
* Created by Faisal Amir on 07/02/23

ad-admob/src/main/java/com/frogobox/admob/ui/FrogoAdmobActivity.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package com.frogobox.admob.ui
22

33
import com.frogobox.admob.delegate.AdmobDelegates
44
import com.frogobox.admob.delegate.AdmobDelegatesImpl
5-
import com.frogobox.sdk.ext.showLogDebug
65
import com.frogobox.sdk.view.FrogoActivity
7-
import com.google.android.gms.ads.AdView
86

97
/**
108
* Created by Faisal Amir

ad-admob/src/main/java/com/frogobox/admob/ui/FrogoAdmobBindActivity.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ package com.frogobox.admob.ui
33
import androidx.viewbinding.ViewBinding
44
import com.frogobox.admob.delegate.AdmobDelegates
55
import com.frogobox.admob.delegate.AdmobDelegatesImpl
6-
import com.frogobox.sdk.ext.showLogDebug
76
import com.frogobox.sdk.view.FrogoBindActivity
8-
import com.google.android.gms.ads.AdView
97

108

119
/**

ad-admob/src/main/res/layout/frogo_ads_banner.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
*
1313
-->
1414

15-
<RelativeLayout
16-
xmlns:android="http://schemas.android.com/apk/res/android"
17-
xmlns:ads="http://schemas.android.com/apk/res-auto"
15+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
1816
android:id="@+id/frogo_ads_banner"
1917
android:layout_width="match_parent"
2018
android:layout_height="wrap_content"

0 commit comments

Comments
 (0)