capacitor-levelplay/dist/esm/definitions.d.ts
CRT e31f019a7c 0.3.0 design: owner decisions Q1-Q7; CUSTOM banner size, native template fonts, banner demo ids
- Per-ad impression listeners plus a capped (100) queue flushed on the first impressionData listener.
- Android adaptive width unit is dp (SDK bytecode).
- Adaptive banners without a fixed width are recreated on safe-area width changes.
- BannerSize gains CUSTOM with customSize { width, height }.
- NativeAdTemplateStyle gains titleFont / bodyFont / callToActionFont ({ family, size }).
- LEVELPLAY_DEMO gains the banner ad unit ids of Unity's sample apps.
- Capacitor 7 targeted for 0.3.0 (verified in a later phase).
2026-10-10 03:24:37 +08:00

1613 lines
43 KiB
TypeScript

import type { PluginListenerHandle } from '@capacitor/core';
/**
* Full-screen ad formats (`loadRewarded` / `loadInterstitial` family and the `loaded` ... `rewarded` events).
* Banners and native ads have their own methods and `banner*` / `nativeAd*` events (since 0.3.0), so this union
* stays unchanged for 0.2.x code.
*
* @since 0.1.0
*/
export type AdFormat = 'rewarded' | 'interstitial';
/**
* Options for `initialize()`.
*
* @since 0.1.0
*/
export interface InitOptions {
/**
* LevelPlay app key from the LevelPlay dashboard. Android and iOS apps have different keys.
*
* @since 0.1.0
*/
appKey: string;
/**
* Optional user id. Needed for server-to-server reward callbacks and the Ad Quality user journey.
*
* @since 0.1.0
*/
userId?: string;
/**
* Enable the LevelPlay Integration Test Suite: sets the `is_test_suite=enable` meta data before init.
* Call `launchTestSuite()` after `initialize` resolves. Never ship this enabled.
*
* @default false
* @since 0.1.0
*/
testSuite?: boolean;
/**
* Turn on debug logs of the mediated ad network adapters (`LevelPlay.setAdaptersDebug(true)`). Development only.
*
* @default false
* @since 0.1.0
*/
adaptersDebug?: boolean;
/**
* Privacy signals applied right before init (LevelPlay recommends setting them before the SDK starts).
* Same as calling `setConsent()` first.
*
* @since 0.1.0
*/
consent?: ConsentOptions;
}
/**
* Result of `initialize()` and `getSdkVersion()`.
*
* @since 0.1.0
*/
export interface InitResult {
/**
* Native LevelPlay SDK version, for example `9.6.1`. `web` on the web.
*
* @since 0.1.0
*/
sdkVersion: string;
}
/**
* Privacy signals forwarded to LevelPlay (`LevelPlayPrivacySettings` on Android, `LPMPrivacySettings` on iOS).
* Omitted fields are left untouched.
*
* @since 0.1.0
*/
export interface ConsentOptions {
/**
* GDPR: `true` when the user consented to personalised ads and data processing, `false` when they did not.
* For users in the EEA, UK and Switzerland pass `false` until a consent management platform (CMP) says otherwise.
*
* @since 0.1.0
*/
gdprConsent?: boolean;
/**
* CCPA and other US state privacy laws: `true` when the user opted OUT of the sale or sharing of personal data
* ("do not sell"), `false` otherwise.
*
* @since 0.1.0
*/
ccpaDoNotSell?: boolean;
/**
* COPPA: `true` when the user must be treated as a child (child-directed treatment).
*
* @since 0.1.0
*/
coppa?: boolean;
}
/**
* Options for `setMetaData()`.
*
* @since 0.1.0
*/
export interface MetaDataOptions {
/**
* Meta data key, for example `is_deviceid_optout` or a network-specific flag from Unity's docs.
*
* @since 0.1.0
*/
key: string;
/**
* Meta data value, always a string (for example `"true"`).
*
* @since 0.1.0
*/
value: string;
}
/**
* Identifies one ad unit.
*
* @since 0.1.0
*/
export interface AdUnitOptions {
/**
* Ad unit id from the LevelPlay dashboard (Ad units page). Android and iOS ad units have different ids.
*
* @since 0.1.0
*/
adUnitId: string;
}
/**
* Options for `showRewarded()` and `showInterstitial()`: `adUnitId` (see AdUnitOptions) plus an optional placement.
*
* @since 0.1.0
*/
export interface ShowOptions extends AdUnitOptions {
/**
* Optional placement name configured in the LevelPlay dashboard (capping, pacing and reward per placement).
* Omit it to use the default placement.
*
* @since 0.1.0
*/
placementName?: string;
}
/**
* Options for `isReady()`: `adUnitId` (see AdUnitOptions) plus the format.
*
* @since 0.1.0
*/
export interface IsReadyOptions extends AdUnitOptions {
/**
* Format of the ad unit.
*
* @since 0.1.0
*/
format: AdFormat;
}
/**
* Result of `isReady()`.
*
* @since 0.1.0
*/
export interface IsReadyResult {
/**
* `true` when a loaded ad can be shown right now.
*
* @since 0.1.0
*/
ready: boolean;
}
/**
* The reward of a rewarded ad, as configured in the LevelPlay dashboard (per ad unit or placement).
*
* @since 0.1.0
*/
export interface Reward {
/**
* Name of the reward, for example `Coins`.
*
* @since 0.1.0
*/
name: string;
/**
* Amount of the reward.
*
* @since 0.1.0
*/
amount: number;
}
/**
* Error reported by the SDK (load / display failures) or by the plugin.
*
* @since 0.1.0
*/
export interface AdError {
/**
* LevelPlay error code, for example `509` (no fill). `-1` is used by the plugin for "Ad not ready" and for the web
* stub.
*
* @since 0.1.0
*/
code: number;
/**
* Human readable message.
*
* @since 0.1.0
*/
message: string;
}
/**
* Subset of the native `LevelPlayAdInfo` (Android) / `LPMAdInfo` (iOS) that is useful in JavaScript.
* Fields the SDK does not report are omitted.
*
* @since 0.1.0
*/
export interface AdInfo {
/**
* Unique id of this ad.
*
* @since 0.1.0
*/
adId?: string;
/**
* Ad unit id.
*
* @since 0.1.0
*/
adUnitId: string;
/**
* Ad unit name from the dashboard.
*
* @since 0.1.0
*/
adUnitName?: string;
/**
* Ad format as reported by the SDK.
*
* @since 0.1.0
*/
adFormat?: string;
/**
* Placement name of the show call, when one was used.
*
* @since 0.1.0
*/
placementName?: string;
/**
* Name of the mediated network that served the ad.
*
* @since 0.1.0
*/
adNetwork?: string;
/**
* Mediation instance name.
*
* @since 0.1.0
*/
instanceName?: string;
/**
* Mediation instance id.
*
* @since 0.1.0
*/
instanceId?: string;
/**
* Country code of the impression.
*
* @since 0.1.0
*/
country?: string;
/**
* Auction id.
*
* @since 0.1.0
*/
auctionId?: string;
/**
* Impression revenue in USD as reported by the SDK (may be absent or 0 before display).
*
* @since 0.1.0
*/
revenue?: number;
/**
* Revenue precision as reported by the SDK.
*
* @since 0.1.0
*/
precision?: string;
/**
* A/B test group of the user (`ab`).
*
* @since 0.3.0
*/
ab?: string;
/**
* Segment name of the user, see `setSegment()`.
*
* @since 0.3.0
*/
segmentName?: string;
/**
* Encrypted CPM (`encryptedCPM`).
*
* @since 0.3.0
*/
encryptedCPM?: string;
/**
* Creative id of the served ad, when the network reports one.
*
* @since 0.3.0
*/
creativeId?: string;
/**
* iOS only: SKAdNetwork conversion value (`LPMAdInfo.conversionValue`). Android's `LevelPlayAdInfo` has no such
* field in SDK 9.6.1, so it is always absent there.
*
* @since 0.3.0
*/
conversionValue?: number;
/**
* Size of the ad. Banners only (`LevelPlayAdInfo.getAdSize()` / `LPMAdInfo.adSize`).
*
* @since 0.3.0
*/
adSize?: AdSizeInfo;
}
/**
* A resolved ad size as reported by the SDK (`LevelPlayAdSize` / `LPMAdSize`). Width and height are in dp on Android
* and points on iOS, which equal CSS px in the WebView at the default zoom.
*
* @since 0.3.0
*/
export interface AdSizeInfo {
/**
* Width in CSS px (dp / pt).
*
* @since 0.3.0
*/
width: number;
/**
* Height in CSS px (dp / pt).
*
* @since 0.3.0
*/
height: number;
/**
* SDK description of the size, for example `BANNER` or `ADAPTIVE`.
*
* @since 0.3.0
*/
description?: string;
/**
* `true` for an adaptive size.
*
* @since 0.3.0
*/
isAdaptive?: boolean;
}
/**
* Result of `showRewarded()` and `showInterstitial()`, resolved after the ad
* closed or failed to display.
*
* @since 0.1.0
*/
export interface ShowResult {
/**
* The ad was displayed (the `displayed` event fired).
*
* @since 0.1.0
*/
shown: boolean;
/**
* Rewarded only: the reward callback fired for this show. Grant the reward only when this is `true`.
* Always `false` for interstitials.
*
* @since 0.1.0
*/
rewarded: boolean;
/**
* The reward, present when `rewarded` is `true`.
*
* @since 0.1.0
*/
reward?: Reward;
/**
* Present when the ad was not ready (`code: -1`) or failed to display.
*
* @since 0.1.0
*/
error?: AdError;
/**
* Info of the displayed ad.
*
* @since 0.1.0
*/
adInfo?: AdInfo;
}
/**
* Payload of the `loaded`, `displayed`, `clicked` and `closed` events.
*
* @since 0.1.0
*/
export interface AdEvent {
/**
* Format of the ad unit that fired the event.
*
* @since 0.1.0
*/
format: AdFormat;
/**
* Ad unit that fired the event.
*
* @since 0.1.0
*/
adUnitId: string;
/**
* Ad info, when the SDK provides it (not on `loadFailed`).
*
* @since 0.1.0
*/
adInfo?: AdInfo;
}
/**
* Payload of the `loadFailed` and `displayFailed` events: the AdEvent fields plus `error`.
*
* @since 0.1.0
*/
export interface AdErrorEvent extends AdEvent {
/**
* What went wrong.
*
* @since 0.1.0
*/
error: AdError;
}
/**
* Payload of the `rewarded` event: the AdEvent fields plus `reward`.
*
* @since 0.1.0
*/
export interface AdRewardEvent extends AdEvent {
/**
* The reward earned.
*
* @since 0.1.0
*/
reward: Reward;
}
/**
* iOS App Tracking Transparency status. `unavailable` on Android, on the web and on unknown future iOS values.
*
* @since 0.1.0
*/
export type TrackingStatus = 'authorized' | 'denied' | 'restricted' | 'notDetermined' | 'unavailable';
/**
* Result of `requestTrackingAuthorization()` and
* `getTrackingAuthorizationStatus()`.
*
* @since 0.1.0
*/
export interface TrackingResult {
/**
* iOS App Tracking Transparency status. Always `unavailable` on Android and web.
*
* @since 0.1.0
*/
status: TrackingStatus;
}
/**
* Result of `getCapabilities()`: what this platform build of the plugin can do. Check it instead of the platform
* name, so the same game code runs on Android, iOS and the web.
*
* @since 0.3.0
*/
export interface Capabilities {
/**
* Banner ads (`createBanner()` and friends) are available.
*
* @since 0.3.0
*/
banner: boolean;
/**
* Native ads (`loadNativeAd()` and friends) are available.
*
* @since 0.3.0
*/
nativeAd: boolean;
/**
* Native ad templates this platform can render. Empty when `nativeAd` is `false`.
*
* @since 0.3.0
*/
nativeAdTemplates: NativeAdTemplate[];
/**
* The `impressionData` event is delivered.
*
* @since 0.3.0
*/
impressionData: boolean;
/**
* The `adInfoChanged` event is delivered (rewarded and interstitial only).
*
* @since 0.3.0
*/
adInfoChanged: boolean;
}
/**
* A rectangle in CSS px, relative to the top-left corner of the WebView viewport (the same space as
* `element.getBoundingClientRect()` without page scroll).
*
* @since 0.3.0
*/
export interface Rect {
/**
* Left edge in CSS px.
*
* @since 0.3.0
*/
x: number;
/**
* Top edge in CSS px.
*
* @since 0.3.0
*/
y: number;
/**
* Width in CSS px.
*
* @since 0.3.0
*/
width: number;
/**
* Height in CSS px.
*
* @since 0.3.0
*/
height: number;
}
/**
* Banner size presets, named after the SDK constants (`LevelPlayAdSize.BANNER` / `LPMAdSize.bannerSize()` ...).
*
* - `BANNER`: 320 x 50
* - `LARGE`: 320 x 90
* - `MEDIUM_RECTANGLE`: 300 x 250
* - `LEADERBOARD`: 728 x 90 (tablets)
* - `ADAPTIVE`: `LevelPlayAdSize.createAdaptiveAdSize(context, width)` / `LPMAdSize.createAdaptiveAdSize(withWidth:)`;
* the SDK picks the height (and BANNER or LEADERBOARD as fallback) for the given width. Requires a finished
* `initialize()`.
* - `CUSTOM`: `LevelPlayAdSize.createCustomSize(width, height)` / `LPMAdSize.customSizeWithWidth:height:` with
* `customSize`. Few networks fill custom sizes; prefer a preset or `ADAPTIVE`.
*
* @since 0.3.0
*/
export type BannerSize = 'BANNER' | 'LARGE' | 'MEDIUM_RECTANGLE' | 'LEADERBOARD' | 'ADAPTIVE' | 'CUSTOM';
/**
* Width and height of a `CUSTOM` banner, in CSS px (dp on Android, points on iOS).
*
* @since 0.3.0
*/
export interface BannerCustomSize {
/**
* Width in CSS px (positive integer).
*
* @since 0.3.0
*/
width: number;
/**
* Height in CSS px (positive integer).
*
* @since 0.3.0
*/
height: number;
}
/**
* Vertical anchor of a banner inside the WebView's safe area. Banners are always horizontally centred; use
* `offsetX` to move them sideways.
*
* @since 0.3.0
*/
export type BannerPosition = 'top' | 'bottom' | 'center';
/**
* Identifies one banner created with `createBanner()`.
*
* @since 0.3.0
*/
export interface BannerIdOptions {
/**
* Plugin-side banner id passed to `createBanner()` (defaults to the ad unit id there).
*
* @since 0.3.0
*/
bannerId: string;
}
/**
* Where a banner sits over the WebView.
*
* @since 0.3.0
*/
export interface BannerLayoutOptions {
/**
* Vertical anchor.
*
* @default 'bottom'
* @since 0.3.0
*/
position?: BannerPosition;
/**
* Horizontal offset from the centred position in CSS px (positive moves right).
*
* @default 0
* @since 0.3.0
*/
offsetX?: number;
/**
* Vertical offset from the anchored position in CSS px (positive moves down).
*
* @default 0
* @since 0.3.0
*/
offsetY?: number;
/**
* Keep the banner inside the safe area (status bar, notch / display cutout, home indicator, navigation bar), measured
* against the WebView's own on-screen rect. Set `false` to anchor to the raw WebView edges.
*
* @default true
* @since 0.3.0
*/
respectSafeArea?: boolean;
}
/**
* Options for `createBanner()`.
*
* @since 0.3.0
*/
export interface CreateBannerOptions extends AdUnitOptions, BannerLayoutOptions {
/**
* Plugin-side id of this banner, used by every other banner method and in banner events. Lets one ad unit back
* several banners. Defaults to `adUnitId`.
*
* @since 0.3.0
*/
bannerId?: string;
/**
* Size preset.
*
* @default 'ADAPTIVE'
* @since 0.3.0
*/
size?: BannerSize;
/**
* `CUSTOM` only: the banner size. When `customSize` is set and `size` is omitted, `size` defaults to `CUSTOM`.
*
* @since 0.3.0
*/
customSize?: BannerCustomSize;
/**
* `ADAPTIVE` only: width in CSS px to compute the adaptive size for. Defaults to the width of the WebView's safe
* area; in that case the plugin recreates and reloads the banner automatically when that width changes (rotation,
* split screen, window resize), keeping its id, layout and visibility. A fixed `adaptiveWidth` is never recreated.
*
* @since 0.3.0
*/
adaptiveWidth?: number;
/**
* Placement name (reporting only for banners). Applied through the banner config before the first load.
*
* @since 0.3.0
*/
placementName?: string;
/**
* Bid floor in USD (`LevelPlayBannerAdView.Config.Builder.setBidFloor` / `LPMBannerAdViewConfigBuilder set(bidFloor:)`).
*
* @since 0.3.0
*/
bidFloor?: number;
}
/**
* Options for `setBannerLayout()`: `bannerId` plus the layout fields (see BannerLayoutOptions).
*
* @since 0.3.0
*/
export interface SetBannerLayoutOptions extends BannerIdOptions, BannerLayoutOptions {
}
/**
* Result of `createBanner()`, `showBanner()` and `setBannerLayout()`.
*
* @since 0.3.0
*/
export interface BannerResult {
/**
* The banner id.
*
* @since 0.3.0
*/
bannerId: string;
/**
* Requested ad size (the creative may be smaller for adaptive sizes; it is centred in this frame).
*
* @since 0.3.0
*/
adSize: AdSizeInfo;
/**
* Where the banner frame is (or will be, while hidden) in CSS px, relative to the WebView viewport. Use it to pad
* game UI away from the banner.
*
* @since 0.3.0
*/
frame: Rect;
/**
* The banner view is currently visible.
*
* @since 0.3.0
*/
visible: boolean;
}
/**
* Payload of the `banner*` events.
*
* @since 0.3.0
*/
export interface BannerEvent {
/**
* Banner that fired the event.
*
* @since 0.3.0
*/
bannerId: string;
/**
* Ad unit of the banner.
*
* @since 0.3.0
*/
adUnitId: string;
/**
* Ad info, when the SDK provides it (not on `bannerLoadFailed`).
*
* @since 0.3.0
*/
adInfo?: AdInfo;
/**
* Current frame of the banner in CSS px.
*
* @since 0.3.0
*/
frame?: Rect;
}
/**
* Payload of `bannerLoadFailed` and `bannerDisplayFailed`.
*
* @since 0.3.0
*/
export interface BannerErrorEvent extends BannerEvent {
/**
* What went wrong.
*
* @since 0.3.0
*/
error: AdError;
}
/**
* Native ad template rendered by the plugin (the LevelPlay SDK ships no template views; the plugin provides its own
* layouts, like Unity's Flutter and React Native wrappers do).
*
* - `small`: icon, title, advertiser, body, call to action; no media view. Recommended 300 x 175 or a row at least
* 90 px tall.
* - `medium`: the `small` assets plus a media view. Recommended 300 x 350.
*
* @since 0.3.0
*/
export type NativeAdTemplate = 'small' | 'medium';
/**
* Optional styling of a native ad template. Colours are CSS hex strings (`#RRGGBB` or `#RRGGBBAA`).
*
* @since 0.3.0
*/
export interface NativeAdTemplateStyle {
/**
* Template background.
*
* @since 0.3.0
*/
backgroundColor?: string;
/**
* Title text colour.
*
* @since 0.3.0
*/
titleColor?: string;
/**
* Body and advertiser text colour.
*
* @since 0.3.0
*/
bodyColor?: string;
/**
* Call-to-action button background.
*
* @since 0.3.0
*/
callToActionBackgroundColor?: string;
/**
* Call-to-action button text colour.
*
* @since 0.3.0
*/
callToActionTextColor?: string;
/**
* Corner radius of the template in CSS px.
*
* @default 0
* @since 0.3.0
*/
cornerRadius?: number;
/**
* Title font.
*
* @since 0.3.0
*/
titleFont?: NativeAdFont;
/**
* Body and advertiser font.
*
* @since 0.3.0
*/
bodyFont?: NativeAdFont;
/**
* Call-to-action button font.
*
* @since 0.3.0
*/
callToActionFont?: NativeAdFont;
}
/**
* A font of a native ad template text. Omitted fields keep the template default (system font).
*
* @since 0.3.0
*/
export interface NativeAdFont {
/**
* Font family. Either a system family name (Android: `sans-serif`, `sans-serif-medium`, `serif`, `monospace` ...;
* iOS: a `UIFont` family or PostScript name such as `Avenir Next` or `Menlo-Bold`), or the path of a `.ttf` / `.otf`
* file inside the app's web assets, relative to the web root (for example `fonts/Inter-Bold.ttf`, the same file the
* page loads with `@font-face`). Unknown families fall back to the system font.
*
* @since 0.3.0
*/
family?: string;
/**
* Font size in CSS px (dp / pt; not scaled by the system font size setting, like text in the WebView).
*
* @since 0.3.0
*/
size?: number;
}
/**
* Identifies one native ad slot.
*
* @since 0.3.0
*/
export interface NativeAdIdOptions {
/**
* Plugin-side id of the native ad slot.
*
* @since 0.3.0
*/
nativeAdId: string;
}
/**
* Options for `loadNativeAd()`.
*
* @since 0.3.0
*/
export interface LoadNativeAdOptions extends NativeAdIdOptions {
/**
* Placement name. LevelPlay 9.6.1 native ads are addressed by placement only (`LevelPlayNativeAd.Builder
* .withPlacementName` / `LevelPlayNativeAdBuilder withPlacementName:`); there is no ad unit id for native ads in
* this SDK version. Omit it for the default placement.
*
* @since 0.3.0
*/
placementName?: string;
/**
* Template used when the ad is shown.
*
* @default 'medium'
* @since 0.3.0
*/
template?: NativeAdTemplate;
/**
* Template styling.
*
* @since 0.3.0
*/
style?: NativeAdTemplateStyle;
}
/**
* Options for `showNativeAd()` and `setNativeAdRect()`.
*
* @since 0.3.0
*/
export interface NativeAdRectOptions extends NativeAdIdOptions {
/**
* Where the template goes, in CSS px relative to the WebView viewport (for example a placeholder element's
* `getBoundingClientRect()`).
*
* @since 0.3.0
*/
rect: Rect;
}
/**
* Ad info of a native ad (`AdInfo` on Android / `ISAdInfo` on iOS: the older ironSource info type, which has no ad
* unit, ad id or placement fields).
*
* @since 0.3.0
*/
export interface NativeAdInfo {
/**
* Auction id.
*
* @since 0.3.0
*/
auctionId?: string;
/**
* Mediated network that served the ad.
*
* @since 0.3.0
*/
adNetwork?: string;
/**
* Mediation instance name.
*
* @since 0.3.0
*/
instanceName?: string;
/**
* Mediation instance id.
*
* @since 0.3.0
*/
instanceId?: string;
/**
* Country code.
*
* @since 0.3.0
*/
country?: string;
/**
* Impression revenue in USD.
*
* @since 0.3.0
*/
revenue?: number;
/**
* Revenue precision.
*
* @since 0.3.0
*/
precision?: string;
/**
* A/B test group.
*
* @since 0.3.0
*/
ab?: string;
/**
* Segment name.
*
* @since 0.3.0
*/
segmentName?: string;
/**
* Encrypted CPM.
*
* @since 0.3.0
*/
encryptedCPM?: string;
/**
* iOS only: SKAdNetwork conversion value.
*
* @since 0.3.0
*/
conversionValue?: number;
}
/**
* Payload of the `nativeAd*` events.
*
* @since 0.3.0
*/
export interface NativeAdEvent {
/**
* Native ad slot that fired the event.
*
* @since 0.3.0
*/
nativeAdId: string;
/**
* Placement passed to `loadNativeAd()`, if any.
*
* @since 0.3.0
*/
placementName?: string;
/**
* Ad info, when the SDK provides it (not on `nativeAdLoadFailed`).
*
* @since 0.3.0
*/
adInfo?: NativeAdInfo;
}
/**
* Payload of `nativeAdLoadFailed`.
*
* @since 0.3.0
*/
export interface NativeAdErrorEvent extends NativeAdEvent {
/**
* What went wrong.
*
* @since 0.3.0
*/
error: AdError;
}
/**
* Impression-level revenue data (`LevelPlayImpressionData` on Android, `LPMImpressionData` on iOS). Every field the
* SDK 9.6.1 data class exposes is mapped; fields the SDK leaves empty are omitted.
*
* Not available in SDK 9.6.1 on either platform: `lifetimeRevenue` (removed from the impression data class). If the
* server ever sends extra keys they are still visible in `allData`.
*
* @since 0.3.0
*/
export interface ImpressionData {
/**
* Which ad format produced the impression, as the SDK reports it (for example `Rewarded Video`, `Interstitial`,
* `Banner`, or `nativead` for impressions synthesised from native ad info).
*
* @since 0.3.0
*/
adFormat?: string;
/**
* Auction id.
*
* @since 0.3.0
*/
auctionId?: string;
/**
* Mediation ad unit id (`mediationAdUnitId`).
*
* @since 0.3.0
*/
adUnitId?: string;
/**
* Mediation ad unit name (`mediationAdUnitName`).
*
* @since 0.3.0
*/
adUnitName?: string;
/**
* Mediated network that served the ad.
*
* @since 0.3.0
*/
adNetwork?: string;
/**
* Mediation instance name.
*
* @since 0.3.0
*/
instanceName?: string;
/**
* Mediation instance id.
*
* @since 0.3.0
*/
instanceId?: string;
/**
* Country code.
*
* @since 0.3.0
*/
country?: string;
/**
* Placement name of the impression.
*
* @since 0.3.0
*/
placement?: string;
/**
* Revenue of this impression in USD.
*
* @since 0.3.0
*/
revenue?: number;
/**
* Revenue precision (for example `BID`, `RATE`, `ESTIMATED`).
*
* @since 0.3.0
*/
precision?: string;
/**
* A/B test group.
*
* @since 0.3.0
*/
ab?: string;
/**
* Segment name, see `setSegment()`.
*
* @since 0.3.0
*/
segmentName?: string;
/**
* Encrypted CPM (`encryptedCPM` on Android, `encryptedCpm` on iOS).
*
* @since 0.3.0
*/
encryptedCPM?: string;
/**
* Creative id.
*
* @since 0.3.0
*/
creativeId?: string;
/**
* iOS only: SKAdNetwork conversion value.
*
* @since 0.3.0
*/
conversionValue?: number;
/**
* The raw `allData` map of the SDK (`getAllData()` JSON on Android, `allData` dictionary on iOS). Keys and value
* types are SDK defined and may change between SDK versions.
*
* @since 0.3.0
*/
allData?: {
[key: string]: unknown;
};
}
/**
* Options for `isPlacementCapped()`.
*
* @since 0.3.0
*/
export interface PlacementCappedOptions {
/**
* Format of the placement. LevelPlay 9.6.1 has capping checks for rewarded and interstitial only.
*
* @since 0.3.0
*/
format: AdFormat;
/**
* Placement name from the LevelPlay dashboard.
*
* @since 0.3.0
*/
placementName: string;
}
/**
* Result of `isPlacementCapped()`.
*
* @since 0.3.0
*/
export interface PlacementCappedResult {
/**
* `true` when the placement reached its capping or pacing limit; showing it now fails.
*
* @since 0.3.0
*/
capped: boolean;
}
/**
* Options for `getReward()`: `adUnitId` (see AdUnitOptions) plus an optional placement.
*
* @since 0.3.0
*/
export interface GetRewardOptions extends AdUnitOptions {
/**
* Placement whose reward to read. Its reward takes precedence over the ad unit reward. Omit for the ad unit reward.
*
* @since 0.3.0
*/
placementName?: string;
}
/**
* Options for `setSegment()` (`LevelPlaySegment` / `LPMSegment`). Omitted fields are not sent.
*
* @since 0.3.0
*/
export interface SegmentOptions {
/**
* Segment name.
*
* @since 0.3.0
*/
segmentName?: string;
/**
* User level (integer).
*
* @since 0.3.0
*/
level?: number;
/**
* The user has paid in the app.
*
* @since 0.3.0
*/
isPaying?: boolean;
/**
* When the user was created, in milliseconds since the Unix epoch (`Date.now()` style).
*
* @since 0.3.0
*/
userCreationDate?: number;
/**
* Total in-app purchase amount of the user (USD).
*
* @since 0.3.0
*/
iapTotal?: number;
/**
* Custom segment parameters. SDK 9.6.1 limits: at most 5 pairs; keys and values 1-32 characters, letters and digits
* only (`^[a-zA-Z0-9]*$`). The plugin rejects with `INVALID_ARGUMENT` instead of letting the SDK silently drop pairs.
*
* @since 0.3.0
*/
customParameters?: {
[key: string]: string;
};
}
/**
* Options for `setDynamicUserId()`.
*
* @since 0.3.0
*/
export interface DynamicUserIdOptions {
/**
* Dynamic user id, forwarded in server-to-server reward callbacks. Can change during the session.
*
* @since 0.3.0
*/
userId: string;
}
/**
* Result of `setDynamicUserId()`.
*
* @since 0.3.0
*/
export interface DynamicUserIdResult {
/**
* The SDK accepted the id (`LevelPlay.setDynamicUserId` returns a boolean on both platforms).
*
* @since 0.3.0
*/
valid: boolean;
}
/**
* Event names emitted by the plugin.
*
* @since 0.1.0
*/
export type LevelPlayEventName = 'loaded' | 'loadFailed' | 'displayed' | 'displayFailed' | 'clicked' | 'closed' | 'rewarded' | 'adInfoChanged' | 'impressionData' | 'bannerLoaded' | 'bannerLoadFailed' | 'bannerDisplayed' | 'bannerDisplayFailed' | 'bannerClicked' | 'bannerExpanded' | 'bannerCollapsed' | 'bannerLeftApplication' | 'nativeAdLoaded' | 'nativeAdLoadFailed' | 'nativeAdImpression' | 'nativeAdClicked';
/**
* Unity LevelPlay ads (ad-unit API): rewarded, interstitial and (since 0.3.0) banner and native ads, impression-level
* revenue, segments and placement capping.
*
* @since 0.1.0
*/
export interface LevelPlayPlugin {
/**
* Initialise the LevelPlay SDK (`LevelPlay.init`). Resolves on init success, rejects with the init error
* (code and message from the SDK) otherwise. Calling it again after a successful init resolves immediately;
* concurrent calls share one init. Load ads only after this resolves.
*
* Set consent (and on iOS ask for ATT) before calling it.
*
* On the web it rejects as unimplemented.
*
* @since 0.1.0
*/
initialize(options: InitOptions): Promise<InitResult>;
/**
* Native LevelPlay SDK version. Works before init.
*
* @since 0.1.0
*/
getSdkVersion(): Promise<InitResult>;
/**
* Forward GDPR / CCPA / COPPA signals to LevelPlay. Call it before `initialize()` when you
* can, and again whenever the user changes their choice.
*
* @since 0.1.0
*/
setConsent(options: ConsentOptions): Promise<void>;
/**
* Raw `LevelPlay.setMetaData(key, value)` for SDK or network-specific flags. Call it before init.
*
* @since 0.1.0
*/
setMetaData(options: MetaDataOptions): Promise<void>;
/**
* iOS: show the App Tracking Transparency prompt and resolve with the resulting status. Needs
* `NSUserTrackingUsageDescription` in `Info.plist`. iOS only shows the prompt once; later calls resolve the stored
* status. Call it before `initialize()`, while the app is active.
*
* Android and web: resolves `unavailable`.
*
* @since 0.1.0
*/
requestTrackingAuthorization(): Promise<TrackingResult>;
/**
* Current App Tracking Transparency status without prompting (iOS). Android and web: `unavailable`.
*
* @since 0.1.0
*/
getTrackingAuthorizationStatus(): Promise<TrackingResult>;
/**
* Start loading a rewarded ad for the ad unit. The native ad object is created on first use and reused for the
* ad unit. Resolves once the request is issued; the outcome arrives as a `loaded` or `loadFailed` event.
* Load the next ad after each show.
*
* @since 0.1.0
*/
loadRewarded(options: AdUnitOptions): Promise<void>;
/**
* Show a loaded rewarded ad. Resolves after the ad closed (or failed to display) with what happened. The reward
* and close callbacks can arrive in either order on some networks, so the plugin waits up to 1 second after the close
* for a late reward. Never rejects for "not ready": resolves `{ shown: false, rewarded: false, error }` instead.
*
* @since 0.1.0
*/
showRewarded(options: ShowOptions): Promise<ShowResult>;
/**
* Start loading an interstitial ad for the ad unit. Works like `loadRewarded()`.
*
* @since 0.1.0
*/
loadInterstitial(options: AdUnitOptions): Promise<void>;
/**
* Show a loaded interstitial. Resolves after it closed (or failed to display). Never rejects for "not ready".
*
* @since 0.1.0
*/
showInterstitial(options: ShowOptions): Promise<ShowResult>;
/**
* `isAdReady()` of the native ad object for this ad unit. `false` when the ad unit was never loaded.
*
* @since 0.1.0
*/
isReady(options: IsReadyOptions): Promise<IsReadyResult>;
/**
* Open the LevelPlay Integration Test Suite. Requires `initialize({ testSuite: true })` first.
* Development builds only. Rejects on the web.
*
* @since 0.1.0
*/
launchTestSuite(): Promise<void>;
/**
* Write the LevelPlay integration helper report to the native log (Xcode console; Android logcat tag
* `IntegrationHelper`): SDK, adapter and network SDK versions, each `VERIFIED` or not. Development only.
*
* @since 0.1.0
*/
validateIntegration(): Promise<void>;
/**
* What this platform supports (banners, native ad templates, impression data, `adInfoChanged`). Works before init.
* Web: everything `false`.
*
* @since 0.3.0
*/
getCapabilities(): Promise<Capabilities>;
/**
* Set the user segment (`LevelPlay.setSegment` with a `LevelPlaySegment` / `LPMSegment`). Call it before
* `initialize()` so the first ad requests use it; later calls apply to the following requests. Rejects with
* `INVALID_ARGUMENT` when `customParameters` break the SDK limits. Web: no-op.
*
* @since 0.3.0
*/
setSegment(options: SegmentOptions): Promise<void>;
/**
* Set or change the dynamic user id used in server-to-server reward callbacks (`LevelPlay.setDynamicUserId` on
* both platforms). Set it before `showRewarded()`. Web: resolves `{ valid: false }`.
*
* @since 0.3.0
*/
setDynamicUserId(options: DynamicUserIdOptions): Promise<DynamicUserIdResult>;
/**
* Whether a rewarded or interstitial placement is capped right now (static
* `LevelPlayRewardedAd.isPlacementCapped` / `LevelPlayInterstitialAd.isPlacementCapped` on Android,
* `LPMRewardedAd.isPlacementCapped:` / `LPMInterstitialAd.isPlacementCapped:` on iOS). Works without a loaded ad.
* Web: `{ capped: false }`.
*
* @since 0.3.0
*/
isPlacementCapped(options: PlacementCappedOptions): Promise<PlacementCappedResult>;
/**
* The reward configured for a rewarded ad unit or one of its placements (`LevelPlayRewardedAd.getReward(placement)` /
* `LPMRewardedAd getReward(placementName:)`), for "watch a video for N coins" buttons. The SDK returns
* `{ name: '', amount: 0 }` when it has no reward configuration (for example before init). Web: the same empty
* reward.
*
* @since 0.3.0
*/
getReward(options: GetRewardOptions): Promise<Reward>;
/**
* Create a banner (`LevelPlayBannerAdView` / `LPMBannerAdView`) for the ad unit and attach it, hidden, in a
* pass-through overlay above the WebView. Requires a finished `initialize()` (`NOT_INITIALIZED` otherwise). Rejects
* with `ALREADY_EXISTS` when `bannerId` is in use; destroy it first. Does not load: call `loadBanner()`.
* Web: rejects as unimplemented.
*
* @since 0.3.0
*/
createBanner(options: CreateBannerOptions): Promise<BannerResult>;
/**
* Load the banner (`loadAd()` / `loadAdWithViewController:`). The outcome arrives as `bannerLoaded` or
* `bannerLoadFailed`; after the first load the SDK refreshes the banner on the dashboard interval. Web: no-op.
*
* @since 0.3.0
*/
loadBanner(options: BannerIdOptions): Promise<void>;
/**
* Make the banner visible and resume auto refresh (`resumeAutoRefresh`). Can be called before the load finished;
* the creative appears when it arrives. Web: rejects as unimplemented.
*
* @since 0.3.0
*/
showBanner(options: BannerIdOptions): Promise<BannerResult>;
/**
* Hide the banner and pause auto refresh (`pauseAutoRefresh`) so hidden banners do not burn impressions. The view
* stays attached; `showBanner()` brings it back. Web: no-op.
*
* @since 0.3.0
*/
hideBanner(options: BannerIdOptions): Promise<void>;
/**
* Move a banner (position, offsets, safe area). Resolves with the new frame. Web: rejects as unimplemented.
*
* @since 0.3.0
*/
setBannerLayout(options: SetBannerLayoutOptions): Promise<BannerResult>;
/**
* Remove the banner from the screen and `destroy()` it. A destroyed banner cannot be reused; create a new one.
* Resolves also for unknown ids. Web: no-op.
*
* @since 0.3.0
*/
destroyBanner(options: BannerIdOptions): Promise<void>;
/**
* Load a native ad into a slot. Following the SDK rule "one native ad object per load", it destroys the slot's
* previous ad (hiding it if shown), builds a new `LevelPlayNativeAd` with the placement and loads it. The outcome
* arrives as `nativeAdLoaded` or `nativeAdLoadFailed`. Requires a finished `initialize()`. Rejects with
* `UNSUPPORTED` when `getCapabilities().nativeAd` is `false` or the template is not listed there. Web: rejects as
* unimplemented.
*
* @since 0.3.0
*/
loadNativeAd(options: LoadNativeAdOptions): Promise<void>;
/**
* Render the loaded native ad into its template, register the asset views with the SDK
* (`NativeAdLayout.registerNativeAdViews` / `ISNativeAdView registerNativeAdViews:`) and place it at `rect` above the
* WebView. Rejects with `NOT_LOADED` before `nativeAdLoaded`. The impression is reported by `nativeAdImpression`.
* Web: rejects as unimplemented.
*
* @since 0.3.0
*/
showNativeAd(options: NativeAdRectOptions): Promise<void>;
/**
* Move or resize a shown native ad, for example after the placeholder element moved. Web: no-op.
*
* @since 0.3.0
*/
setNativeAdRect(options: NativeAdRectOptions): Promise<void>;
/**
* Hide a shown native ad (the view stays registered; `showNativeAd()` shows it again). Web: no-op.
*
* @since 0.3.0
*/
hideNativeAd(options: NativeAdIdOptions): Promise<void>;
/**
* Remove the native ad view and `destroyAd()` it. Resolves also for unknown ids. Web: no-op.
*
* @since 0.3.0
*/
destroyNativeAd(options: NativeAdIdOptions): Promise<void>;
/**
* An ad finished loading for the ad unit and can be shown.
*
* @since 0.1.0
*/
addListener(eventName: 'loaded', listenerFunc: (event: AdEvent) => void): Promise<PluginListenerHandle>;
/**
* Loading failed, for example `509` (no fill). Retry later with a backoff.
*
* @since 0.1.0
*/
addListener(eventName: 'loadFailed', listenerFunc: (event: AdErrorEvent) => void): Promise<PluginListenerHandle>;
/**
* The ad was displayed (impression). `adInfo.revenue` is available here.
*
* @since 0.1.0
*/
addListener(eventName: 'displayed', listenerFunc: (event: AdEvent) => void): Promise<PluginListenerHandle>;
/**
* The ad failed to display. The pending show call resolves with the same error.
*
* @since 0.1.0
*/
addListener(eventName: 'displayFailed', listenerFunc: (event: AdErrorEvent) => void): Promise<PluginListenerHandle>;
/**
* The user clicked the ad.
*
* @since 0.1.0
*/
addListener(eventName: 'clicked', listenerFunc: (event: AdEvent) => void): Promise<PluginListenerHandle>;
/**
* The ad was closed and the app is back in front.
*
* @since 0.1.0
*/
addListener(eventName: 'closed', listenerFunc: (event: AdEvent) => void): Promise<PluginListenerHandle>;
/**
* Rewarded only: the user earned the reward. Can fire before or after `closed`.
*
* @since 0.1.0
*/
addListener(eventName: 'rewarded', listenerFunc: (event: AdRewardEvent) => void): Promise<PluginListenerHandle>;
/**
* Rewarded and interstitial: the SDK reloaded the ad in the background and its ad info (network, revenue ...)
* changed (`onAdInfoChanged` / `didChangeAdInfo:`). Banners and native ads have no such callback in SDK 9.6.1.
*
* @since 0.3.0
*/
addListener(eventName: 'adInfoChanged', listenerFunc: (event: AdEvent) => void): Promise<PluginListenerHandle>;
/**
* Impression-level revenue data for every rewarded, interstitial and banner impression (per-ad
* `setImpressionDataListener` / `setImpressionDataDelegate:`, attached by the plugin to every ad object it creates),
* plus native ad impressions synthesised from the native ad info (`adFormat: 'nativead'`, `adInfo` fields only).
* Add the listener at any time, also before `initialize()`; nothing is delivered before the first ad shows.
*
* @since 0.3.0
*/
addListener(eventName: 'impressionData', listenerFunc: (event: ImpressionData) => void): Promise<PluginListenerHandle>;
/**
* A banner loaded or refreshed with a new creative.
*
* @since 0.3.0
*/
addListener(eventName: 'bannerLoaded', listenerFunc: (event: BannerEvent) => void): Promise<PluginListenerHandle>;
/**
* A banner load (or refresh) failed. The SDK keeps retrying on its refresh interval.
*
* @since 0.3.0
*/
addListener(eventName: 'bannerLoadFailed', listenerFunc: (event: BannerErrorEvent) => void): Promise<PluginListenerHandle>;
/**
* A banner creative was displayed on screen (impression).
*
* @since 0.3.0
*/
addListener(eventName: 'bannerDisplayed', listenerFunc: (event: BannerEvent) => void): Promise<PluginListenerHandle>;
/**
* A banner creative failed to display.
*
* @since 0.3.0
*/
addListener(eventName: 'bannerDisplayFailed', listenerFunc: (event: BannerErrorEvent) => void): Promise<PluginListenerHandle>;
/**
* The user clicked a banner.
*
* @since 0.3.0
*/
addListener(eventName: 'bannerClicked', listenerFunc: (event: BannerEvent) => void): Promise<PluginListenerHandle>;
/**
* A banner opened full screen (for example an expandable creative). Pause the game.
*
* @since 0.3.0
*/
addListener(eventName: 'bannerExpanded', listenerFunc: (event: BannerEvent) => void): Promise<PluginListenerHandle>;
/**
* A banner returned to its normal size. Resume the game.
*
* @since 0.3.0
*/
addListener(eventName: 'bannerCollapsed', listenerFunc: (event: BannerEvent) => void): Promise<PluginListenerHandle>;
/**
* A banner click sent the user out of the app (browser or store).
*
* @since 0.3.0
*/
addListener(eventName: 'bannerLeftApplication', listenerFunc: (event: BannerEvent) => void): Promise<PluginListenerHandle>;
/**
* A native ad loaded and can be shown with `showNativeAd()`.
*
* @since 0.3.0
*/
addListener(eventName: 'nativeAdLoaded', listenerFunc: (event: NativeAdEvent) => void): Promise<PluginListenerHandle>;
/**
* A native ad failed to load. Load again later (the plugin already destroyed the failed ad object).
*
* @since 0.3.0
*/
addListener(eventName: 'nativeAdLoadFailed', listenerFunc: (event: NativeAdErrorEvent) => void): Promise<PluginListenerHandle>;
/**
* A shown native ad recorded its impression (first pixel visible).
*
* @since 0.3.0
*/
addListener(eventName: 'nativeAdImpression', listenerFunc: (event: NativeAdEvent) => void): Promise<PluginListenerHandle>;
/**
* The user clicked a native ad.
*
* @since 0.3.0
*/
addListener(eventName: 'nativeAdClicked', listenerFunc: (event: NativeAdEvent) => void): Promise<PluginListenerHandle>;
/**
* Remove every listener of this plugin.
*
* @since 0.1.0
*/
removeAllListeners(): Promise<void>;
}