admob

Version: stable

FUNCTION
initialize()
set_callback()
set_privacy_settings()
request_idfa()
show_ad_inspector()
load_interstitial()
show_interstitial()
is_interstitial_loaded()
load_rewarded()
show_rewarded()
is_rewarded_loaded()
load_banner()
show_banner()
hide_banner()
is_banner_loaded()
destroy_banner()
CONSTANT
MSG_INITIALIZATION
MSG_INTERSTITIAL
MSG_REWARDED
MSG_BANNER
MSG_IDFA
EVENT_CLOSED
EVENT_FAILED_TO_SHOW
EVENT_OPENING
EVENT_FAILED_TO_LOAD
EVENT_LOADED
EVENT_NOT_LOADED
EVENT_EARNED_REWARD
EVENT_COMPLETE
EVENT_CLICKED
EVENT_DESTROYED
EVENT_JSON_ERROR
EVENT_IMPRESSION_RECORDED
EVENT_STATUS_AUTORIZED
EVENT_STATUS_DENIED
EVENT_STATUS_NOT_DETERMINED
EVENT_STATUS_RESTRICTED
EVENT_NOT_SUPPORTED
SIZE_ADAPTIVE_BANNER
SIZE_BANNER
SIZE_FLUID
SIZE_FULL_BANNER
SIZE_LARGE_BANNER
SIZE_LEADEARBOARD
SIZE_MEDIUM_RECTANGLE
SIZE_SEARH
SIZE_SKYSCRAPER
SIZE_SMART_BANNER
POS_NONE
POS_TOP_LEFT
POS_TOP_CENTER
POS_TOP_RIGHT
POS_BOTTOM_LEFT
POS_BOTTOM_CENTER
POS_BOTTOM_RIGHT
POS_CENTER

Functions

initialize()

initialize()

Initialize the Mobile Ads SDK. Warning: If you need to obtain consent from users in the European Economic Area (EEA), set any request-specific flags, or otherwise take action before loading ads, ensure you do so before initializing the Mobile Ads SDK. Original docs [Android](https://developers.google.com/admob/android/quick-start#initialize_the_mobile_ads_sdk), [iOS](https://developers.google.com/admob/ios/quick-start#initialize_the_mobile_ads_sdk)

PARAMETERS


set_callback()

set_callback(callback)

Sets a callback function for receiving events from the SDK. Call `admob.set_callback(nil)` to remove callback

PARAMETERS

callback Callback function that is executed on any event in the SDK.

EXAMPLES

local function admob_callback(self, message_id, message)
    pprint(message_id, message)
    if message_id == admob.MSG_INITIALIZATION then
       if message.event == admob.EVENT_COMPLETE then
           print("EVENT_COMPLETE: Initialization complete")
       elseif message.event == admob.EVENT_JSON_ERROR then
           print("EVENT_JSON_ERROR: Internal NE json error "..message.error)
       end
   elseif message_id == admob.MSG_IDFA then
       if message.event == admob.EVENT_STATUS_AUTORIZED then
           print("EVENT_STATUS_AUTORIZED: ATTrackingManagerAuthorizationStatusAuthorized")
       elseif message.event == admob.EVENT_STATUS_DENIED then
           print("EVENT_STATUS_DENIED: ATTrackingManagerAuthorizationStatusDenied")
       elseif message.event == admob.EVENT_STATUS_NOT_DETERMINED then
           print("EVENT_STATUS_NOT_DETERMINED: ATTrackingManagerAuthorizationStatusNotDetermined")
       elseif message.event == admob.EVENT_STATUS_RESTRICTED then
           print("EVENT_STATUS_RESTRICTED: ATTrackingManagerAuthorizationStatusRestricted")
       elseif message.event == admob.EVENT_NOT_SUPPORTED then
           print("EVENT_NOT_SUPPORTED: IDFA request not supported on this platform or OS version")
       end
   elseif message_id == admob.MSG_INTERSTITIAL then
       if message.event == admob.EVENT_CLOSED then
           print("EVENT_CLOSED: Interstitial AD closed")
       elseif message.event == admob.EVENT_FAILED_TO_SHOW then
           print("EVENT_FAILED_TO_SHOW: Interstitial AD failed to show\nCode: "..message.code.."\nError: "..message.error)
       elseif message.event == admob.EVENT_OPENING then
           print("EVENT_OPENING: Interstitial AD is opening")
       elseif message.event == admob.EVENT_FAILED_TO_LOAD then
           print("EVENT_FAILED_TO_LOAD: Interstitial AD failed to load\nCode: "..message.code.."\nError: "..message.error)
       elseif message.event == admob.EVENT_LOADED then
           print("EVENT_LOADED: Interstitial AD loaded")
       elseif message.event == admob.EVENT_NOT_LOADED then
           print("EVENT_NOT_LOADED: can't call show_interstitial() before EVENT_LOADED\nError: "..message.error)
       elseif message.event == admob.EVENT_IMPRESSION_RECORDED then
           print("EVENT_IMPRESSION_RECORDED: Interstitial did record impression")
       elseif message.event == admob.EVENT_JSON_ERROR then
           print("EVENT_JSON_ERROR: Internal NE json error: "..message.error)
       end
   elseif message_id == admob.MSG_REWARDED then
       if message.event == admob.EVENT_CLOSED then
           print("EVENT_CLOSED: Rewarded AD closed")
       elseif message.event == admob.EVENT_FAILED_TO_SHOW then
           print("EVENT_FAILED_TO_SHOW: Rewarded AD failed to show\nCode: "..message.code.."\nError: "..message.error)
       elseif message.event == admob.EVENT_OPENING then
           print("EVENT_OPENING: Rewarded AD is opening")
       elseif message.event == admob.EVENT_FAILED_TO_LOAD then
           print("EVENT_FAILED_TO_LOAD: Rewarded AD failed to load\nCode: "..message.code.."\nError: "..message.error)
       elseif message.event == admob.EVENT_LOADED then
           print("EVENT_LOADED: Rewarded AD loaded")
       elseif message.event == admob.EVENT_NOT_LOADED then
           print("EVENT_NOT_LOADED: can't call show_rewarded() before EVENT_LOADED\nError: "..message.error)
       elseif message.event == admob.EVENT_EARNED_REWARD then
           print("EVENT_EARNED_REWARD: Reward: " .. tostring(message.amount) .. " " .. tostring(message.type))
       elseif message.event == admob.EVENT_IMPRESSION_RECORDED then
           print("EVENT_IMPRESSION_RECORDED: Rewarded did record impression")
       elseif message.event == admob.EVENT_JSON_ERROR then
           print("EVENT_JSON_ERROR: Internal NE json error: "..message.error)
       end
   elseif message_id == admob.MSG_BANNER then
       if message.event == admob.EVENT_LOADED then
           print("EVENT_LOADED: Banner AD loaded. Height: "..message.height.."px Width: "..message.width.."px")
       elseif message.event == admob.EVENT_OPENING then
           print("EVENT_OPENING: Banner AD is opening")
       elseif message.event == admob.EVENT_FAILED_TO_LOAD then
           print("EVENT_FAILED_TO_LOAD: Banner AD failed to load\nCode: "..message.code.."\nError: "..message.error)
       elseif message.event == admob.EVENT_CLICKED then
           print("EVENT_CLICKED: Banner AD loaded")
       elseif message.event == admob.EVENT_CLOSED then
           print("EVENT_CLOSED: Banner AD closed")
       elseif message.event == admob.EVENT_DESTROYED then
           print("EVENT_DESTROYED: Banner AD destroyed")
       elseif message.event == admob.EVENT_IMPRESSION_RECORDED then
           print("EVENT_IMPRESSION_RECORDED: Banner did record impression")
       elseif message.event == admob.EVENT_JSON_ERROR then
           print("EVENT_JSON_ERROR: Internal NE json error: "..message.error)
       end
   end
end

function init(self)
    if admob then
        admob.set_callback(admob_callback)
        admob.initialize()
    end
end

set_privacy_settings()

set_privacy_settings(bool)

Sets user privacy preferences (must be called before `admod.initialize()`). Original docs [Android](https://developers.google.com/admob/android/ccpa), [iOS](https://developers.google.com/admob/ios/ccpa)

PARAMETERS

bool

request_idfa()

request_idfa()

Display the App Tracking Transparency authorization request for accessing the IDFA. Original docs [iOS](https://developers.google.com/admob/ios/ios14#request)

PARAMETERS


show_ad_inspector()

show_ad_inspector()

Show Ad Inspector. This is an in-app overlay that enables authorized devices to perform realtime analysis of test ad requests directly within a mobile app. Ad Inspector only launces on [test devices](https://support.google.com/admob/answer/9691433). Original docs [Android](https://developers.google.com/admob/android/ad-inspector), [iOS](https://developers.google.com/admob/ios/ad-inspector)

PARAMETERS


load_interstitial()

load_interstitial(ad_unit_id)

Starts loading an Interstitial Ad, can only be called after `admob.MSG_INITIALIZATION` event Original docs [Android](https://developers.google.com/admob/android/interstitial-fullscreen), [iOS](https://developers.google.com/admob/ios/interstitial)

PARAMETERS

ad_unit_id Ad unit ID, for test ads use on Android `"ca-app-pub-3940256099942544/1033173712"`, or on iOS `"ca-app-pub-3940256099942544/4411468910"` Original docs [Android](https://developers.google.com/admob/android/interstitial-fullscreen), [iOS](https://developers.google.com/admob/ios/interstitial)

show_interstitial()

show_interstitial()

Shows loaded Interstitial Ad, can only be called after `admob.EVENT_LOADED` Original docs [Android](https://developers.google.com/admob/android/interstitial-fullscreen), [iOS](https://developers.google.com/admob/ios/interstitial)

PARAMETERS

EXAMPLES

if admob and admod.is_interstitial_loaded() then
    admob.show_interstitial()
end

is_interstitial_loaded()

is_interstitial_loaded()

Checks if Interstitial Ad is loaded and ready to show Original docs [Android](https://developers.google.com/admob/android/interstitial-fullscreen), [iOS](https://developers.google.com/admob/ios/interstitial)

PARAMETERS

RETURNS

boolean

load_rewarded()

load_rewarded(ad_unit_id)

Starts loading a Rewarded Ad, can only be called after `admob.MSG_INITIALIZATION` event Original docs [Android](https://developers.google.com/admob/android/rewarded-fullscreen), [iOS](https://developers.google.com/admob/ios/rewarded-ads)

PARAMETERS

ad_unit_id Ad unit ID, for test ads use on Android `"ca-app-pub-3940256099942544/1712485313"`, or on iOS `"ca-app-pub-3940256099942544/4411468910"` Original docs [Android](https://developers.google.com/admob/android/rewarded-fullscreen), [iOS](https://developers.google.com/admob/ios/rewarded-ads)

show_rewarded()

show_rewarded()

Shows loaded Rewarded Ad, can only be called after `admob.EVENT_LOADED` Original docs [Android](https://developers.google.com/admob/android/rewarded-fullscreen), [iOS](https://developers.google.com/admob/ios/rewarded-ads)

PARAMETERS

EXAMPLES

if admob and admod.is_rewarded_loaded() then
    admob.show_rewarded()
end

is_rewarded_loaded()

is_rewarded_loaded()

Checks if Rewarded Ad is loaded and ready to show Original docs [Android](https://developers.google.com/admob/android/rewarded-fullscreen), [iOS](https://developers.google.com/admob/ios/rewarded-ads)

PARAMETERS

RETURNS

boolean

load_banner()

load_banner(ad_unit_id,size)

Starts loading a Banner Ad, can only be called after `admob.MSG_INITIALIZATION` event Original docs [Android](https://developers.google.com/admob/android/banner), [iOS](https://developers.google.com/admob/ios/banner)

PARAMETERS

ad_unit_id Ad unit ID, for test ads use on Android `"ca-app-pub-3940256099942544/6300978111"`, or on iOS `"ca-app-pub-3940256099942544/2934735716"` Original docs [Android](https://developers.google.com/admob/android/banner), [iOS](https://developers.google.com/admob/ios/banner)
size Requested Banner Ad size, possible values: `admod.SIZE_ADAPTIVE_BANNER` (default), `admod.SIZE_BANNER`, `admod.SIZE_FLUID`, `admod.SIZE_FULL_BANNER`, `admod.SIZE_LARGE_BANNER`, `admod.SIZE_LEADEARBOARD`, `admod.SIZE_MEDIUM_RECTANGLE`, `admod.SIZE_SEARH`, `admod.SIZE_SKYSCRAPER`, `admod.SIZE_SMART_BANNER`. Original docs [Android](https://developers.google.com/admob/android/banner#banner_sizes), [iOS](https://developers.google.com/admob/ios/banner#banner_sizes)

show_banner()

show_banner(position)

Shows loaded Banner Ad, can only be called after `admob.EVENT_LOADED` Original docs [Android](https://developers.google.com/admob/android/banner), [iOS](https://developers.google.com/admob/ios/banner)

PARAMETERS

position Banner Ad position, possible values: `admod.POS_NONE` (default), `admod.POS_TOP_LEFT`, `admod.POS_TOP_CENTER`, `admod.POS_TOP_RIGHT`, `admod.POS_BOTTOM_LEFT`, `admod.POS_BOTTOM_CENTER`, `admod.POS_BOTTOM_RIGHT`, `admod.POS_CENTER`

EXAMPLES

if admob and admod.is_banner_loaded() then
    admob.show_banner(admod.POS_TOP_CENTER)
end

hide_banner()

hide_banner()

Temporarily hides Banner Ad, banner can be shown again using `admob.show_banner()` Original docs [Android](https://developers.google.com/admob/android/banner), [iOS](https://developers.google.com/admob/ios/banner)

PARAMETERS


is_banner_loaded()

is_banner_loaded()

Checks if Banner Ad is loaded and ready to show Original docs [Android](https://developers.google.com/admob/android/banner), [iOS](https://developers.google.com/admob/ios/banner)

PARAMETERS

RETURNS

boolean

destroy_banner()

destroy_banner()

Hides and unloads Banner Ad (needs to call `admob.load_banner()` later to show Banner Ad) Original docs [Android](https://developers.google.com/admob/android/banner), [iOS](https://developers.google.com/admob/ios/banner)

PARAMETERS


Constants

MSG_INITIALIZATION


MSG_INTERSTITIAL


MSG_REWARDED


MSG_BANNER


MSG_IDFA


EVENT_CLOSED


EVENT_FAILED_TO_SHOW


EVENT_OPENING


EVENT_FAILED_TO_LOAD


EVENT_LOADED


EVENT_NOT_LOADED


EVENT_EARNED_REWARD


EVENT_COMPLETE


EVENT_CLICKED


EVENT_DESTROYED


EVENT_JSON_ERROR


EVENT_IMPRESSION_RECORDED


EVENT_STATUS_AUTORIZED


EVENT_STATUS_DENIED


EVENT_STATUS_NOT_DETERMINED


EVENT_STATUS_RESTRICTED


EVENT_NOT_SUPPORTED


SIZE_ADAPTIVE_BANNER


SIZE_BANNER


SIZE_FLUID


SIZE_FULL_BANNER


SIZE_LARGE_BANNER


SIZE_LEADEARBOARD


SIZE_MEDIUM_RECTANGLE


SIZE_SEARH


SIZE_SKYSCRAPER


SIZE_SMART_BANNER


POS_NONE


POS_TOP_LEFT


POS_TOP_CENTER


POS_TOP_RIGHT


POS_BOTTOM_LEFT


POS_BOTTOM_CENTER


POS_BOTTOM_RIGHT


POS_CENTER