The following sections show you how to load and then show and hide a banner or MREC ad.
Loading a Banner or MREC
To load a banner or MREC, call create_banner()
or create_mrec()
.
Pass that method your Ad Unit ID, desired ad view position, and (for banners) desired background color.
MAX sizes the ad for you automatically:
local banner_ad_unit_ids = {
android = " «android-ad-unit-ID» " ,
function initialize_banner_ads ()
local sysinfo = sys . get_sys_info ()
if sysinfo .system_name == " Android " then
ad_unit_id = banner_ad_unit_ids [ " android " ]
elseif sysinfo .system_name == " iPhone OS " then
ad_unit_id = banner_ad_unit_ids [ " ios " ]
-- Banners are automatically sized to 320x50 on phones and 728x90 on tablets
applovin . create_banner ( ad_unit_id , " bottom_center " )
-- Set background or background color for banners to be fully functional
-- this sets it to black - USE HEX STRINGS ONLY
applovin . set_banner_background_color ( ad_unit_id , " #000000 " );
local mrec_ad_unit_ids = {
android = " «android-ad-unit-ID» " ,
function initialize_mrec_ads ()
local sysinfo = sys . get_sys_info ()
if sysinfo .system_name == " Android " then
ad_unit_id = mrec_ad_unit_ids [ " android " ]
elseif sysinfo .system_name == " iPhone OS " then
ad_unit_id = mrec_ad_unit_ids [ " ios " ]
-- MRECs are sized to 300x250 on phones and tablets
applovin . create_mrec ( ad_unit_id , " centered " )
The complete list of position options are:
top_left
top_center
top_right
centered
bottom_left
bottom_center
bottom_right
MAX automatically sizes banners to 320×50 on phones or 728×90 on tablets.
It sizes MRECs to 300×250 on both phones and tablets.
Showing and Hiding a Banner or MREC
To show a banner or MREC, call showBanner()
or showMRec()
:
applovin . show_banner ( « ad - unit - ID » )
applovin . show_mrec ( « ad - unit - ID » )
To hide a banner or MREC, call hideBanner()
or hideMRec()
:
applovin . hide_banner ( « ad - unit - ID » )
applovin . hide_mrec ( « ad - unit - ID » )
Stopping and Starting Auto-Refresh
You may want to stop auto-refresh for an ad.
For instance, you may want to do this when you hide an ad or you want to manually refresh.
Stop auto-refresh with the following code:
applovin . show_banner ( « ad - unit - ID » )
applovin . stop_banner_auto_refresh ( « ad - unit - ID » )
applovin . show_mrec ( « ad - unit - ID » )
applovin . stop_mrec_auto_refresh ( « ad - unit - ID » )
Start auto-refresh for an ad with the following code:
applovin . start_banner_auto_refresh ( « ad - unit - ID » )
applovin . start_mrec_auto_refresh ( « ad - unit - ID » )