Skip to content

Commit

Permalink
Merge pull request #82 from amirisback/develop/ad-consent-EEA-UK
Browse files Browse the repository at this point in the history
DEVELOP :: AD Consent For Countries EEA and UK
  • Loading branch information
amirisback committed Jun 24, 2023
2 parents 77c3726 + c410861 commit 5197bfd
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 34 deletions.
50 changes: 43 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

## Version Release

$version_release = 5.3.2
$version_release = 5.3.3

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

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

// -----------------------------------------------------------------------------------------
// For Single Library Patch

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

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

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

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

// -----------------------------------------------------------------------------------------
// For Single Library Patch

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

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

}

Expand Down Expand Up @@ -822,6 +822,42 @@ fun FrogoAdmobBannerView(

```

## User Messaging Platform (UMP)

### How to use
```kotlin
showAdConsent(object : IFrogoAdConsent {

override fun activity(): Activity {
return this@MainActivity
}

override fun isDebug(): Boolean {
return BuildConfig.DEBUG
}

override fun isUnderAgeAd(): Boolean {
return false
}

override fun onNotUsingAdConsent() {
// On Not Using Ad Consent
}

override fun onConsentSuccess() {
// On Consent Success
}

override fun onConsentError(formError: FormError) {
// On Consent Error
}

})
```

### Notes
- Read This [Stack Overflow](https://stackoverflow.com/questions/65351543/how-to-implement-ump-sdk-correctly-for-eu-consent?rq=3)

## Allert

### Update
Expand Down
48 changes: 44 additions & 4 deletions ad-admob/src/main/java/com/frogobox/admob/core/FrogoAdConsent.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.frogobox.admob.core

import android.content.Context
import android.telephony.TelephonyManager
import com.google.android.ump.ConsentDebugSettings
import com.google.android.ump.ConsentInformation
import com.google.android.ump.ConsentRequestParameters
Expand All @@ -22,9 +24,42 @@ import com.google.android.ump.UserMessagingPlatform

object FrogoAdConsent {

fun getCountryCode(context: Context): String {
val tm = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
return tm.networkCountryIso.uppercase()
}

fun listEEACountry(): List<String> {
return listOf(
"AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", "HU", "IE",
"IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE"
)
}

fun listUKCountry(): List<String> {
return listOf("GB", "GG", "IM", "JE")
}

fun listAdConsentCountry(): List<String> {
return listEEACountry() + listUKCountry()
}

fun isAdConsentCountry(context: Context): Boolean {
return listAdConsentCountry().contains(getCountryCode(context))
}

fun showConsent(callback: IFrogoAdConsent) {
if (isAdConsentCountry(callback.activity())) {
setupConsent(callback)
} else {
callback.onNotUsingAdConsent()
}
}

private fun setupConsent(callback: IFrogoAdConsent) {

val consentInformation: ConsentInformation = UserMessagingPlatform.getConsentInformation(callback.activity())
val consentInformation: ConsentInformation =
UserMessagingPlatform.getConsentInformation(callback.activity())

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

consentInformation.requestConsentInfoUpdate(callback.activity(), params,
{ // The consent information state was updated.
{
// The consent information state was updated.
// You are now ready to check if a form is available.
if (consentInformation.isConsentFormAvailable) {
loadForm(consentInformation, callback)
} else {
callback.onNotUsingAdConsent()
}
},
{
{ formError ->
// Handle the error.
callback.onConsentError(it)
callback.onConsentError(formError)
})
}

Expand All @@ -72,6 +110,8 @@ object FrogoAdConsent {
// Handle dismissal by reloading form.
loadForm(consentInformation, callback)
}
} else if (consentInformation.consentStatus == ConsentInformation.ConsentStatus.NOT_REQUIRED) {
callback.onNotUsingAdConsent()
}
}, { formError ->
// Handle the error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.FullScreenContentCallback
import com.google.android.gms.ads.LoadAdError
import com.google.android.gms.ads.appopen.AppOpenAd
import java.util.*
import java.util.Date

/**
* Created by Faisal Amir on 24/10/22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ interface IFrogoAdConsent {

fun isUnderAgeAd(): Boolean

fun onNotUsingAdConsent()

fun onConsentSuccess()

fun onConsentError(formError: FormError)
Expand Down
7 changes: 0 additions & 7 deletions ad-admob/src/main/java/com/frogobox/admob/core/IFrogoAdmob.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package com.frogobox.admob.core

import android.content.Context
import android.widget.RelativeLayout
import androidx.appcompat.app.AppCompatActivity
import com.frogobox.admob.callback.FrogoAdmobBannerCallback
import com.frogobox.admob.callback.FrogoAdmobInterstitialCallback
import com.frogobox.admob.callback.FrogoAdmobRewardedCallback
import com.google.android.gms.ads.AdSize
import com.google.android.gms.ads.AdView

/**
* Created by Faisal Amir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.frogobox.admob.delegate.AdmobDelegates
import com.frogobox.admob.delegate.AdmobDelegatesImpl
import com.frogobox.sdk.ext.showLogDebug

/**
* Created by Faisal Amir on 07/02/23
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package com.frogobox.admob.ui

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
import com.frogobox.admob.delegate.AdmobDelegates
import com.frogobox.admob.delegate.AdmobDelegatesImpl
import com.frogobox.sdk.ext.showLogDebug

/**
* Created by Faisal Amir on 07/02/23
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package com.frogobox.admob.ui

import com.frogobox.admob.delegate.AdmobDelegates
import com.frogobox.admob.delegate.AdmobDelegatesImpl
import com.frogobox.sdk.ext.showLogDebug
import com.frogobox.sdk.view.FrogoActivity
import com.google.android.gms.ads.AdView

/**
* Created by Faisal Amir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package com.frogobox.admob.ui
import androidx.viewbinding.ViewBinding
import com.frogobox.admob.delegate.AdmobDelegates
import com.frogobox.admob.delegate.AdmobDelegatesImpl
import com.frogobox.sdk.ext.showLogDebug
import com.frogobox.sdk.view.FrogoBindActivity
import com.google.android.gms.ads.AdView


/**
Expand Down
4 changes: 1 addition & 3 deletions ad-admob/src/main/res/layout/frogo_ads_banner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
*
-->

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frogo_ads_banner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,20 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
return false
}

override fun onNotUsingAdConsent() {
requestAdmobApi()
setupButtonClick()
setupBannerAds()
}

override fun onConsentSuccess() {
requestAdmobApi()
setupButtonClick()
setupBannerAds()
}

override fun onConsentError(formError: FormError) {
showLogDebug("onConsentError ${formError.message}")
showLogDebug("FrogoAdConsent ${formError.message}")
}

})
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/ProjectSetting.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object ProjectSetting {

const val VERSION_MAJOR = 5
const val VERSION_MINOR = 3
const val VERSION_PATCH = 2
const val VERSION_PATCH = 3

// ---------------------------------------------------------------------------------------------

Expand Down

0 comments on commit 5197bfd

Please sign in to comment.