SDK docs 0.1.0 preview
ContentsNGASDK
0.1.0 preview. You install 0.1.0 from Maven Central and NGA's public repositories. Every 0.x version is a preview under the NGA SDK License, and the API can change until 1.0. Questions: hi@nga.network.

Reference

NGASDK

View as Markdown

The one class you call. Every member is static and may be called from any thread, before initialize too, unless its entry says otherwise.

initialize #

Starts the SDK with your app key and the player's consent. Call it once per launch, as early as you can.

Unity (C#)

public static void Initialize(NGAConfig config, NGAListener listener)

Android (Kotlin)

@JvmStatic fun initialize(context: Context, config: NGAConfig, listener: NGAListener?)

Android (Java)

public static void initialize(Context context, NGAConfig config, NGAListener listener)

iOS (Swift)

static func initialize(config: NGAConfig, listener: NGAListener?)

iOS (Objective-C)

+ (void)initializeWithConfig:(NGAConfig *)config listener:(id<NGAListener>)listener;
Name Required Description
context Android only your Application or any other Context. C# passes Unity's Activity for you
config yes your app key, the starting consent and test mode; see NGAConfig
listener no gets onInitialized once for this call, and from then on onError and onAdClosedAfterRestart. Null keeps the earlier listener
  • Returns: nothing; the answer is onInitialized, on the main thread.
  • Errors (in NGAInitResult.error): INVALID_CONFIG (app_key.format, app_key.changed, app_key.unknown, platform.unsupported), DISABLED, NETWORK / init.unreachable, TIMEOUT / init.timeout, SERVER_REJECTED, INTERNAL / init.parse. A retryable failure keeps retrying in the background.
  • Notes: a second call: see Calling initialize again.

getSdkVersion #

Returns the SDK's version, such as 0.1.0.

Unity (C#)

public static string GetSdkVersion()

Android (Kotlin)

@JvmStatic fun getSdkVersion(): String

Android (Java)

public static String getSdkVersion()

iOS (Swift)

static func getSdkVersion() -> String

iOS (Objective-C)

+ (NSString *)getSdkVersion;
  • Returns: the version, such as 0.1.0. A release candidate returns its release version, without -rc.N: 0.1.0-rc.6 returns 0.1.0, as 0.1.0 does (see Install).
  • Notes: include it when you contact NGA.

setLogLevel #

Sets how much the SDK writes to the device log. Default: WARN.

Unity (C#)

public static void SetLogLevel(NGALogLevel level)

Android (Kotlin)

@JvmStatic fun setLogLevel(level: NGALogLevel)

Android (Java)

public static void setLogLevel(NGALogLevel level)

iOS (Swift)

static func setLogLevel(_ level: NGALogLevel)

iOS (Objective-C)

+ (void)setLogLevel:(NGALogLevel)level;
Name Required Description
level yes NGALogLevel: NONE, ERROR, WARN, INFO or DEBUG
  • Lifetime: this process.
  • Notes: a DEBUG level set before initialize covers init. It governs both libraries. Outside test mode no level prints a player's identifiers.

setConsent, getConsent #

Sets the player's consent, and reads the consent in effect.

Unity (C#)

Android (Kotlin)

Android (Java)

iOS (Swift)

iOS (Objective-C)

Name Required Description
consent yes an NGAConsent. Null changes nothing and logs one warning
  • Returns: getConsent returns, per field, the stricter of your answer and the IAB TCF keys. UNKNOWN stays UNKNOWN; NGA's server applies the regional rule. ATT is not included. It never blocks, and reflects a setConsent made just before.
  • Lifetime: saved across launches.
  • Notes: setConsent replaces both fields, UNKNOWN included, and a change is recorded. How it combines with the builder's consent: Consent.

setAge, getAge #

Sets the player's age from your own age gate, and reads it.

Unity (C#)

public static void SetAge(NGAAgeState age)
public static NGAAgeState GetAge()

Android (Kotlin)

@JvmStatic fun setAge(age: NGAAgeState)
@JvmStatic fun getAge(): NGAAgeState

Android (Java)

public static void setAge(NGAAgeState age)
public static NGAAgeState getAge()

iOS (Swift)

static func setAge(_ age: NGAAgeState)
static func getAge() -> NGAAgeState

iOS (Objective-C)

+ (void)setAge:(NGAAgeState)age;
+ (NGAAgeState)getAge;
Name Required Description
age yes NGAAgeState: CHILD or ADULT
  • Returns: getAge returns the age you last set, UNKNOWN until you set one.
  • Lifetime: saved across launches.
  • Notes: setAge never touches consent. See Age and audience.

setCustomerUserId #

Attaches your own id for the player, or removes it.

Unity (C#)

public static NGAResult SetCustomerUserId(string id)

Android (Kotlin)

@JvmStatic fun setCustomerUserId(id: String?): NGAResult

Android (Java)

public static NGAResult setCustomerUserId(String id)

iOS (Swift)

@discardableResult static func setCustomerUserId(_ id: String?) -> NGAResult

iOS (Objective-C)

+ (NGAResult *)setCustomerUserId:(NSString *)id;
Name Required Description
id yes 1 to 128 characters (UTF-16 code units), no NUL character; null removes the id
  • Returns: an NGAResult, immediately.
  • Errors: INVALID_ARGUMENT / customer_user_id.length or customer_user_id.format; the previous id stays.
  • Lifetime: saved across launches.
  • Notes: NGA stores the id hashed. Without analytics consent, or under child treatment, NGA receives only the fact that an id is set, never the id.

logAdRevenue #

Records one impression's revenue from a network or mediation the SDK does not capture by itself.

Unity (C#)

public static NGAResult LogAdRevenue(NGAAdRevenue revenue)

Android (Kotlin)

@JvmStatic fun logAdRevenue(adRevenue: NGAAdRevenue): NGAResult

Android (Java)

public static NGAResult logAdRevenue(NGAAdRevenue adRevenue)

iOS (Swift)

@discardableResult static func logAdRevenue(_ adRevenue: NGAAdRevenue) -> NGAResult

iOS (Objective-C)

+ (NGAResult *)logAdRevenue:(NGAAdRevenue *)adRevenue;
Name Required Description
adRevenue yes an NGAAdRevenue
  • Returns: an NGAResult, immediately.
  • Errors: INVALID_ARGUMENT / ad_revenue.revenue, ad_revenue.currency, ad_revenue.length, argument.null.
  • Notes: MAX and LevelPlay are captured without this call; logging one of theirs too does no harm with that mediation's own impression id, or none. With an id of your own, NGA keeps both copies.

logPurchase #

Records a StoreKit 2 purchase, which the SDK cannot always see by itself. iOS and Unity only.

Unity (C#)

public static NGAResult LogPurchase(string jws)

iOS (Swift)

@discardableResult static func logPurchase(_ result: VerificationResult<Transaction>) -> NGAResult
Name Required Description
result (Swift) yes the result Product.purchase() returned, for every successful purchase
jws (C#) yes the order's JWS, order.Info.Apple.jwsRepresentation with Unity IAP 5
  • Returns: an NGAResult, immediately.
  • Errors: INVALID_ARGUMENT / purchase.jws (not a StoreKit 2 transaction's JWS), argument.null (C#).
  • Notes: a purchase is recorded once even if the SDK also saw it. In C# on Android it records nothing and returns accepted. There is no Kotlin, Java or Objective-C version: every Play purchase is captured without a call, and StoreKit 2 has no Objective-C API.

loadAd #

Loads an ad for a placement.

Unity (C#)

public static void LoadAd(string placementId, NGAAdLoadCallback callback)

Android (Kotlin)

@JvmStatic fun loadAd(placementId: String, callback: NGAAdLoadCallback)

Android (Java)

public static void loadAd(String placementId, NGAAdLoadCallback callback)

iOS (Swift)

static func loadAd(_ placementId: String, callback: NGAAdLoadCallback)

iOS (Objective-C)

+ (void)loadAd:(NSString *)placementId callback:(id<NGAAdLoadCallback>)callback;
Name Required Description
placementId yes plc_ and 3 to 64 lower-case letters, digits or _, the id you gave the placement in the portal
callback yes held strongly until onFailed, or until its ad is used, expires or fails
  • Returns: nothing; the answer is onLoaded with an NGAAd, or onFailed.
  • Errors (in onFailed): NO_FILL, INVALID_PLACEMENT, NETWORK, TIMEOUT, SERVER_REJECTED, NOT_INITIALIZED, DISABLED, RENDER_NOT_AVAILABLE, INTERNAL; the details are on Errors.
  • Notes: a placement holds at most one live ad. A loadAd for a placement that already has a ready ad gets onLoaded immediately, with that same ad; one made while a load is in flight is answered by that load. A loadAd before initialize waits for init. Without the render library, every load fails with RENDER_NOT_AVAILABLE / render.absent. A load that does not finish within 60 seconds fails with TIMEOUT / ad.timeout.

setImpressionListener #

Sets the one app-wide listener for NGA's impressions.

Unity (C#)

public static void SetImpressionListener(Action<NGAImpression> listener)

Android (Kotlin)

@JvmStatic fun setImpressionListener(listener: NGAImpressionListener?)
fun interface NGAImpressionListener { fun onImpression(impression: NGAImpression) }

Android (Java)

public static void setImpressionListener(NGAImpressionListener listener)

iOS (Swift)

static var impressionListener: ((NGAImpression) -> Void)?

iOS (Objective-C)

@property (class, nonatomic, copy, nullable) void (^impressionListener)(NGAImpression *);
Name Required Description
listener yes called once per impression, after the impression counted, with an NGAImpression. Null removes it
  • Lifetime: this process.
  • Notes: a later call replaces the listener. It is kept whether or not the render library is present.

setMuted, isMuted #

Mutes or unmutes all NGA ads, and reads the setting.

Unity (C#)

public static void SetMuted(bool muted)
public static bool IsMuted()

Android (Kotlin)

@JvmStatic fun setMuted(muted: Boolean)
@JvmStatic fun isMuted(): Boolean

Android (Java)

public static void setMuted(boolean muted)
public static boolean isMuted()

iOS (Swift)

static func setMuted(_ muted: Bool)
static func isMuted() -> Bool

iOS (Objective-C)

+ (void)setMuted:(BOOL)muted;
+ (BOOL)isMuted;
Name Required Description
muted yes true starts every NGA ad muted; the player can unmute within an ad
  • Returns: isMuted returns the setting.
  • Lifetime: this process.
  • Notes: one setting for the whole app; there is no per-placement mute. It also affects an ad already on screen. Only the ad's own sound changes, never the device volume or your game's audio. Like any video, an ad with sound may pause or duck other apps' audio while it plays.

setBannerYield #

Registers your own banner ad's hide and restore, which the SDK runs around every native banner show, or clears them.

Unity (C#)

public static void SetBannerYield(Action hide, Action restore)

Android (Kotlin)

@JvmStatic fun setBannerYield(hide: Runnable?, restore: Runnable?)

Android (Java)

public static void setBannerYield(Runnable hide, Runnable restore)

iOS (Swift)

static func setBannerYield(hide: (() -> Void)?, restore: (() -> Void)?)

iOS (Objective-C)

+ (void)setBannerYieldWithHide:(void (^)(void))hide restore:(void (^)(void))restore;
Name Required Description
hide with restore called once per native banner show, on the main thread (Unity: the game thread), just before NGA's banner is added; it takes your banner ad off the screen and pauses its refresh
restore with hide called exactly once for each hide, after NGA's banner is removed, whatever ended the show; it puts your banner ad back
  • Lifetime: this process. A later call replaces the pair; both null clears it; one null alone is ignored with one warning.
  • Errors: none returned. A hide that throws (in Unity: throws, or is not back within a second) refuses that show with INVALID_SHOW_TARGET / show.target.yield_failed: the ad stays READY, and restore is called. A throw from restore is not caught.
  • Notes: kept whether or not the render library is present. With no pair registered, the first native show in the process logs one WARN. What each callback does, with an example per mediation and engine: Your own banner ad. A game with no banner ad never calls this.