A Haxe/Lime extension for integrating Google AdMob on iOS and Android.
To install extension-admob, follow these steps:
-
Haxelib Installation
haxelib install extension-admob
-
Haxelib Git Installation (for latest updates)
haxelib git extension-admob https://github.com/HaxeExtension/extension-admob.git
-
Project Configuration (Add the following code to your project.xml file)
<section if="cpp"> <haxelib name="extension-admob" if="mobile" /> </section>
To configure extension-admob for your project, follow these steps:
-
iOS Frameworks Installation
To set up the required frameworks for iOS compilation, navigate to the directory where the library is installed and execute the following command:chmod +x setup_admob_ios.sh && ./setup_admob_ios.sh
-
Add AdMob App IDs
Include your AdMob app IDs in your project.xml. Ensure you specify the correct IDs for both Android and iOS platforms.<setenv name="ADMOB_APPID" value="ca-app-pub-XXXXX123457" if="android"/> <setenv name="ADMOB_APPID" value="ca-app-pub-XXXXX123458" if="ios"/>
-
GDPR Consent Management
Beginning January 16, 2024, Google requires publishers serving ads in the EEA and UK to use a certified consent management platform (CMP). This extension integrates Google's UMP SDK to display a consent dialog during the first app launch. Ads may not function if the user does not provide consent. -
Initializing Admob extension
If GDPR consent dialog and/or iOS 14+ tracking authorization dialog are required, they are should automatically upon Admob initialization.import extension.admob.*; ... Admob.setCallback(function(event:String, message:String):Void { if (event == AdmobEvent.INIT_OK) //you can load your ads here }); Admob.init();
-
Checking GDPR Consent Requirements
After consenting (or not) to show ads, user must have an option to change his choice. To give this choice an access to GDPR consent dialog should be provided somewhere in the app. You can determine if the GDPR consent dialog is required (ie user is from EEA or UK):if (Admob.isPrivacyOptionsRequired()) trace("GDPR consent dialog is required.");
-
Reopen Privacy Options Dialog
If needed, allow users to manage their GDPR consent options again.Admob.showPrivacyOptionsForm();
-
Verify User Consent
Check if the user has consented to personalized ads:if (Admob.getConsent() == AdmobConsent.FULL) trace("User consented to personalized ads."); else trace("User did not consent to personalized ads.");
-
Check Consent for Specific Purposes
Verify if the user has consented to individual purposes, such as purpose 0:if (Admob.hasConsentForPurpose(0) == 1) trace("User has consented to purpose 0."); else trace("User has not consented to purpose 0.");
-
Load and Show Ads
Add the following snippets to display ads in your app:-
Banner Ad
Admob.showBanner("ca-app-pub-XXXX/XXXXXXXXXX");
-
Interstitial Ad
Admob.setCallback(function(event:String, message:String):Void { if (event == AdmobEvent.INTERSTITIAL_LOADED) Admob.showInterstitial(); }); Admob.loadInterstitial("ca-app-pub-XXXX/XXXXXXXXXX");
-
Rewarded Ad
Admob.setCallback(function(event:String, message:String):Void { if (event == AdmobEvent.REWARDED_LOADED) Admob.showRewarded(); }); Admob.loadRewarded("ca-app-pub-XXXX/XXXXXXXXXX");
-
App Open Ad
Admob.setCallback(function(event:String, message:String):Void { if (event == AdmobEvent.APP_OPEN_LOADED) Admob.showAppOpen(); }); Admob.loadAppOpen("ca-app-pub-XXXX/XXXXXXXXXX");
-
Google is a registered trademark of Google Inc.
AdMob is a registrered trademark of Google Inc.
The MIT License (MIT) - LICENSE.md
Copyright (c) 2025 Haxe/Lime/NME/OpenFL contributors