appnext.createAd()

Type Function
Return value String
Revision 2017.3060
Keywords ads, advertising, Appnext, createAd
See also appnext.loadAd()
appnext.*

Overview

This function is used to create an ad with a specific type and placement ID. If an ad with the same type and placement ID already exists, it will not be recreated.

Syntax

appnext.createAd( adType, placementID [, configParams] )
adType (required)

String. The type of the ad. Possible values include "interstitial", "fullscreen", and "rewarded".

placementID (required)

String. The placement ID for the ad.

configParams (optional)

Table. A Lua table with configuration parameters for the created ad — see the next section for details.

Parameter Reference

The configParams table includes configuration parameters for the ad.

Notes
  • Certain parameters apply only to specific ad types, per the indicated sections.
  • Following creation of the ad, parameters can also be set and read via related appnext.set* and appnext.get* functions.

General

  • Categories — A comma-delimited list of strings which set the preferred ad categories.
  • Postback — Postback parameters (string) that will be posted to your server after user installs an app. Make sure to encode the values.
  • ButtonTextString indicating the install button's text. Default is "Install".
  • ButtonColorString indicating the install button's color as a 6-character hexadecimal color starting with #.
  • BackButtonCanClose — Android only; boolean value indicating if the "Back" key can close the ad. Default is false.
  • MuteBoolean value which can mute the video which is played in the ad. Default is false.

Interstitial

  • CreativeTypeString which sets the creative type for the main section of the interstitial. Possible values are "managed", "video", or "static". Default is "managed".
  • SkipTextString which sets a custom text for the "skip" button. Default is "Skip".
  • AutoPlayBoolean which sets the video to auto-play. Default is true.

Full-Screen / Rewarded

  • ProgressTypeString which sets or hides the progress type. Possible values are "clock", "bar", "none", or "default". Default is "clock".
  • ProgressColorString indicating the progress bar and clock color as a 6-character hexadecimal color starting with #.
  • VideoLengthString indicating the video length of 15 or 30 seconds. Possible values are "15", "30", or "default". Default is "15".
  • ShowCloseBoolean value which can display or hide the "close" button.
  • CloseDelay — If the "close" button is shown, this delays its appearance by the set number value, in seconds.
  • PreferredOrientationString which sets the preferred orientation, assuming both landscape and portrait are supported by the application. Possible values are "automatic", "landscape", or "portrait". Default is "automatic".

Rewarded

  • RewardsTransactionIdString indicating a transaction ID per ad view. Make sure this is a unique rewards ID.
  • RewardsUserIdString indicating the user ID so that you will know which user to reward.
  • RewardsRewardTypeCurrencyString indicating the type of reward (life/credit/points).
  • RewardsAmountRewardedString indicating the amount of currency that was rewarded.
  • RewardsCustomParameterString which allows you to pass any custom value/data.

Example

local appnext = require( "plugin.appnext" )

local function adListener( event )
    print( "Received " .. event.event .. " for " .. event.adKey .. " with message: " .. event.message )
end

-- Initialize the Appnext plugin
appnext.init( adListener )

-- Create your ads
local interstitialPlacementID
local fullscreenPlacementID
local rewardedPlacementID

local platform = system.getInfo( "platformName" )
if ( platform == "iPhone OS" ) then
    interstitialPlacementID = "YOUR_IOS_INTERSTITIAL_PLACEMENT_ID"
    fullscreenPlacementID = "YOUR_IOS_FULLSCREEN_PLACEMENT_ID"
    rewardedPlacementID = "YOUR_IOS_REWARDED_PLACEMENT_ID"
elseif ( platform == "Android" ) then
    interstitialPlacementID = "YOUR_ANDROID_INTERSTITIAL_PLACEMENT_ID"
    fullscreenPlacementID = "YOUR_ANDROID_FULLSCREEN_PLACEMENT_ID"
    rewardedPlacementID = "YOUR_ANDROID_REWARDED_PLACEMENT_ID"
end

local interstitialConfig = {
    SkipText = "Close Ad",
    CreativeType = "video"
}

local videoConfig = {
    ShowClose = true,
    CloseDelay = 5.5
}

local interstitialAdKey = appnext.createAd( "interstitial", interstitialPlacementID, interstitialConfig )
local fullscreenAdKey = appnext.createAd( "fullscreen", fullscreenPlacementID, videoConfig )
local rewardedAdKey = appnext.createAd( "rewarded", rewardedPlacementID )