Unofficial Google Mobile Ads Consent SDK bindings for Haxe OpenFL Android and iOS targets. See the demo app here.
This is deprecated - I am no longer updating it because I do not currently use ads requiring GDPR consent in my projects. Feel free to fork this and bring it up to date though!
Supports:
- Retrieving GDPR/ads consent status a user has picked.
- Displaying pre-made Google Mobile Ads SDK consent form.
- Customizable listeners for handling Consent SDK events.
- Checking if a consent request came from within the EEA.
haxelib git samcodes-consent https://github.com/Tw1ddle/samcodes-consent
See the demo app for an example.
Getting the user's current consent status:
// Extend ConsentListener to handle the onConsentInfoUpdated and onFailedToUpdateConsentInfo callbacks
Consent.setConsentListener(new MyConsentListener());
// Make the request to determine the status of a user's consent
Consent.requestStatus("your-publisher-id-from-ads-dashboard");
When we receive the current status, we can check if the request came from within the European Economic Area:
// Note this will only return a valid value after the onConsentInfoUpdated callback triggers
if(!Consent.isRequestLocationInEeaOrUnknown()) {
return; // There is no need to show a consent form to users outside EEA, and the SDK might not let you anyway
}
Finally you can load and display the consent form:
// Extend ConsentFormListener to handle the onConsentFormLoaded, onConsentFormOpened, onConsentFormClosed and onConsentFormError callbacks
// Note, you need to call Consent.showConsentForm() in the onConsentFormLoaded callback to actually show the form once it loads.
Consent.setConsentFormListener(new MyConsentFormListener());
// Request the Google-rendered consent form
var personalizedAdsOption = true;
var nonPersonalizedAdsOption = true;
var adFreeOption = false;
Consent.requestConsentForm("https://www.samcodes.co.uk", personalizedAdsOption, nonPersonalizedAdsOption, adFreeOption);
Finally record the consent response from the onConsentFormClosed callback to game saved data (or whatever is appropriate) so you don't have to show the form every time.
- At time of writing, callbacks on Android run on the wrong thread due to an issue in lime.
- At time of writing, the Consent SDK form shows lots of partner privacy policies that may be irrelevant to your app.
- On iOS you have to drag-drop the consent form from the PersonalizedAdConsent bundle into your Xcode project. See this thread in the OpenFL forums.
- Refer to the official Google Mobile Ads Consent SDK documentation for Android and iOS.
- Use
#if (android || ios)
conditionals around your imports and calls to this library for cross platform projects - there is no stub/fallback implementation included in the haxelib. - If you need to rebuild the iOS or simulator ndlls, navigate to
/project
and runrebuild_ndlls.sh
. - Got an idea or suggestion? Open an issue on GitHub, or send Sam a message on Twitter.