# `NGASDK` The one class you call. Every member is static and may be called from any thread, before `initialize` too, unless its entry says otherwise. *NGA SDK 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. This page: https://nga.io/docs/sdk/reference/ngasdk/* ## `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#)** ```csharp public static void Initialize(NGAConfig config, NGAListener listener) ``` **Android (Kotlin)** ```kotlin @JvmStatic fun initialize(context: Context, config: NGAConfig, listener: NGAListener?) ``` **Android (Java)** ```java public static void initialize(Context context, NGAConfig config, NGAListener listener) ``` **iOS (Swift)** ```swift static func initialize(config: NGAConfig, listener: NGAListener?) ``` **iOS (Objective-C)** ```objectivec + (void)initializeWithConfig:(NGAConfig *)config listener:(id)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`](https://nga.io/docs/sdk/reference/configuration/#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](https://nga.io/docs/sdk/initialize/#calling-initialize-again). ## `getSdkVersion` Returns the SDK's version, such as `0.1.0`. **Unity (C#)** ```csharp public static string GetSdkVersion() ``` **Android (Kotlin)** ```kotlin @JvmStatic fun getSdkVersion(): String ``` **Android (Java)** ```java public static String getSdkVersion() ``` **iOS (Swift)** ```swift static func getSdkVersion() -> String ``` **iOS (Objective-C)** ```objectivec + (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](https://nga.io/docs/sdk/install/#what-you-add)). - **Notes:** include it when you contact NGA. ## `setLogLevel` Sets how much the SDK writes to the device log. Default: `WARN`. **Unity (C#)** ```csharp public static void SetLogLevel(NGALogLevel level) ``` **Android (Kotlin)** ```kotlin @JvmStatic fun setLogLevel(level: NGALogLevel) ``` **Android (Java)** ```java public static void setLogLevel(NGALogLevel level) ``` **iOS (Swift)** ```swift static func setLogLevel(_ level: NGALogLevel) ``` **iOS (Objective-C)** ```objectivec + (void)setLogLevel:(NGALogLevel)level; ``` | Name | Required | Description | | --- | --- | --- | | `level` | yes | [`NGALogLevel`](https://nga.io/docs/sdk/reference/enums/#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#)** ```csharp public static void SetConsent(NGAConsent consent) public static NGAConsent GetConsent() ``` **Android (Kotlin)** ```kotlin @JvmStatic fun setConsent(consent: NGAConsent) @JvmStatic fun getConsent(): NGAConsent ``` **Android (Java)** ```java public static void setConsent(NGAConsent consent) public static NGAConsent getConsent() ``` **iOS (Swift)** ```swift static func setConsent(_ consent: NGAConsent) static func getConsent() -> NGAConsent ``` **iOS (Objective-C)** ```objectivec + (void)setConsent:(NGAConsent *)consent; + (NGAConsent *)getConsent; ``` | Name | Required | Description | | --- | --- | --- | | `consent` | yes | an [`NGAConsent`](https://nga.io/docs/sdk/reference/configuration/#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](https://nga.io/docs/sdk/privacy/#consent). ## `setAge`, `getAge` Sets the player's age from your own age gate, and reads it. **Unity (C#)** ```csharp public static void SetAge(NGAAgeState age) public static NGAAgeState GetAge() ``` **Android (Kotlin)** ```kotlin @JvmStatic fun setAge(age: NGAAgeState) @JvmStatic fun getAge(): NGAAgeState ``` **Android (Java)** ```java public static void setAge(NGAAgeState age) public static NGAAgeState getAge() ``` **iOS (Swift)** ```swift static func setAge(_ age: NGAAgeState) static func getAge() -> NGAAgeState ``` **iOS (Objective-C)** ```objectivec + (void)setAge:(NGAAgeState)age; + (NGAAgeState)getAge; ``` | Name | Required | Description | | --- | --- | --- | | `age` | yes | [`NGAAgeState`](https://nga.io/docs/sdk/reference/enums/#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](https://nga.io/docs/sdk/privacy/#age-and-audience). ## `setCustomerUserId` Attaches your own id for the player, or removes it. **Unity (C#)** ```csharp public static NGAResult SetCustomerUserId(string id) ``` **Android (Kotlin)** ```kotlin @JvmStatic fun setCustomerUserId(id: String?): NGAResult ``` **Android (Java)** ```java public static NGAResult setCustomerUserId(String id) ``` **iOS (Swift)** ```swift @discardableResult static func setCustomerUserId(_ id: String?) -> NGAResult ``` **iOS (Objective-C)** ```objectivec + (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`](https://nga.io/docs/sdk/reference/values/#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#)** ```csharp public static NGAResult LogAdRevenue(NGAAdRevenue revenue) ``` **Android (Kotlin)** ```kotlin @JvmStatic fun logAdRevenue(adRevenue: NGAAdRevenue): NGAResult ``` **Android (Java)** ```java public static NGAResult logAdRevenue(NGAAdRevenue adRevenue) ``` **iOS (Swift)** ```swift @discardableResult static func logAdRevenue(_ adRevenue: NGAAdRevenue) -> NGAResult ``` **iOS (Objective-C)** ```objectivec + (NGAResult *)logAdRevenue:(NGAAdRevenue *)adRevenue; ``` | Name | Required | Description | | --- | --- | --- | | `adRevenue` | yes | an [`NGAAdRevenue`](https://nga.io/docs/sdk/reference/configuration/#ngaadrevenue) | - **Returns:** an [`NGAResult`](https://nga.io/docs/sdk/reference/values/#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#)** ```csharp public static NGAResult LogPurchase(string jws) ``` **iOS (Swift)** ```swift @discardableResult static func logPurchase(_ result: VerificationResult) -> 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`](https://nga.io/docs/sdk/reference/values/#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#)** ```csharp public static void LoadAd(string placementId, NGAAdLoadCallback callback) ``` **Android (Kotlin)** ```kotlin @JvmStatic fun loadAd(placementId: String, callback: NGAAdLoadCallback) ``` **Android (Java)** ```java public static void loadAd(String placementId, NGAAdLoadCallback callback) ``` **iOS (Swift)** ```swift static func loadAd(_ placementId: String, callback: NGAAdLoadCallback) ``` **iOS (Objective-C)** ```objectivec + (void)loadAd:(NSString *)placementId callback:(id)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`](https://nga.io/docs/sdk/reference/values/#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](https://nga.io/docs/sdk/reference/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#)** ```csharp public static void SetImpressionListener(Action listener) ``` **Android (Kotlin)** ```kotlin @JvmStatic fun setImpressionListener(listener: NGAImpressionListener?) fun interface NGAImpressionListener { fun onImpression(impression: NGAImpression) } ``` **Android (Java)** ```java public static void setImpressionListener(NGAImpressionListener listener) ``` **iOS (Swift)** ```swift static var impressionListener: ((NGAImpression) -> Void)? ``` **iOS (Objective-C)** ```objectivec @property (class, nonatomic, copy, nullable) void (^impressionListener)(NGAImpression *); ``` | Name | Required | Description | | --- | --- | --- | | `listener` | yes | called once per impression, after the impression counted, with an [`NGAImpression`](https://nga.io/docs/sdk/reference/values/#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#)** ```csharp public static void SetMuted(bool muted) public static bool IsMuted() ``` **Android (Kotlin)** ```kotlin @JvmStatic fun setMuted(muted: Boolean) @JvmStatic fun isMuted(): Boolean ``` **Android (Java)** ```java public static void setMuted(boolean muted) public static boolean isMuted() ``` **iOS (Swift)** ```swift static func setMuted(_ muted: Bool) static func isMuted() -> Bool ``` **iOS (Objective-C)** ```objectivec + (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#)** ```csharp public static void SetBannerYield(Action hide, Action restore) ``` **Android (Kotlin)** ```kotlin @JvmStatic fun setBannerYield(hide: Runnable?, restore: Runnable?) ``` **Android (Java)** ```java public static void setBannerYield(Runnable hide, Runnable restore) ``` **iOS (Swift)** ```swift static func setBannerYield(hide: (() -> Void)?, restore: (() -> Void)?) ``` **iOS (Objective-C)** ```objectivec + (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](https://nga.io/docs/sdk/native-cross-promo/#your-own-banner-ad). A game with no banner ad never calls this.