0.3.0 API design: banners, native ad templates, impression data, adInfoChanged, placement capping and rewards, segments, dynamic user id

docs/design-0.3.md maps every feature to the exact LevelPlay 9.6.1 Android and iOS
classes (read from the AAR and xcframework headers), describes the WebView overlay,
error codes, platform gaps, Capacitor 7 findings and the test plan. definitions.ts
and web.ts carry the new typed API; native bridges follow in phase 2.
This commit is contained in:
CRTkafa 2026-10-10 03:19:02 +08:00
parent 9cb0e74cf7
commit 7a187f5dd1
15 changed files with 6010 additions and 29 deletions

View file

@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
## [Unreleased] ## [Unreleased]
### Added (API design for 0.3.0; Android and iOS bridges not implemented yet)
- `docs/design-0.3.md`: banner, native ad, impression data, placement, segment and dynamic user id design with the
exact LevelPlay 9.6.1 Android / iOS mappings, overlay positioning, error codes, Capacitor 7 findings, test plan.
- TypeScript API (`@since 0.3.0`): `getCapabilities`, `setSegment`, `setDynamicUserId`, `isPlacementCapped`,
`getReward`, `createBanner` / `loadBanner` / `showBanner` / `hideBanner` / `setBannerLayout` / `destroyBanner`,
`loadNativeAd` / `showNativeAd` / `setNativeAdRect` / `hideNativeAd` / `destroyNativeAd`; events `adInfoChanged`,
`impressionData`, `banner*` and `nativeAd*`.
- `AdInfo` gains optional `ab`, `segmentName`, `encryptedCPM`, `creativeId`, `conversionValue` (iOS) and `adSize`.
- Web stubs for every new method.
## [0.2.1] - 2026-10-10 ## [0.2.1] - 2026-10-10
### Changed ### Changed

934
README.md
View file

@ -542,6 +542,22 @@ covered by Unity's terms.
* [`isReady(...)`](#isready) * [`isReady(...)`](#isready)
* [`launchTestSuite()`](#launchtestsuite) * [`launchTestSuite()`](#launchtestsuite)
* [`validateIntegration()`](#validateintegration) * [`validateIntegration()`](#validateintegration)
* [`getCapabilities()`](#getcapabilities)
* [`setSegment(...)`](#setsegment)
* [`setDynamicUserId(...)`](#setdynamicuserid)
* [`isPlacementCapped(...)`](#isplacementcapped)
* [`getReward(...)`](#getreward)
* [`createBanner(...)`](#createbanner)
* [`loadBanner(...)`](#loadbanner)
* [`showBanner(...)`](#showbanner)
* [`hideBanner(...)`](#hidebanner)
* [`setBannerLayout(...)`](#setbannerlayout)
* [`destroyBanner(...)`](#destroybanner)
* [`loadNativeAd(...)`](#loadnativead)
* [`showNativeAd(...)`](#shownativead)
* [`setNativeAdRect(...)`](#setnativeadrect)
* [`hideNativeAd(...)`](#hidenativead)
* [`destroyNativeAd(...)`](#destroynativead)
* [`addListener('loaded', ...)`](#addlistenerloaded-) * [`addListener('loaded', ...)`](#addlistenerloaded-)
* [`addListener('loadFailed', ...)`](#addlistenerloadfailed-) * [`addListener('loadFailed', ...)`](#addlistenerloadfailed-)
* [`addListener('displayed', ...)`](#addlistenerdisplayed-) * [`addListener('displayed', ...)`](#addlistenerdisplayed-)
@ -549,6 +565,20 @@ covered by Unity's terms.
* [`addListener('clicked', ...)`](#addlistenerclicked-) * [`addListener('clicked', ...)`](#addlistenerclicked-)
* [`addListener('closed', ...)`](#addlistenerclosed-) * [`addListener('closed', ...)`](#addlistenerclosed-)
* [`addListener('rewarded', ...)`](#addlistenerrewarded-) * [`addListener('rewarded', ...)`](#addlistenerrewarded-)
* [`addListener('adInfoChanged', ...)`](#addlisteneradinfochanged-)
* [`addListener('impressionData', ...)`](#addlistenerimpressiondata-)
* [`addListener('bannerLoaded', ...)`](#addlistenerbannerloaded-)
* [`addListener('bannerLoadFailed', ...)`](#addlistenerbannerloadfailed-)
* [`addListener('bannerDisplayed', ...)`](#addlistenerbannerdisplayed-)
* [`addListener('bannerDisplayFailed', ...)`](#addlistenerbannerdisplayfailed-)
* [`addListener('bannerClicked', ...)`](#addlistenerbannerclicked-)
* [`addListener('bannerExpanded', ...)`](#addlistenerbannerexpanded-)
* [`addListener('bannerCollapsed', ...)`](#addlistenerbannercollapsed-)
* [`addListener('bannerLeftApplication', ...)`](#addlistenerbannerleftapplication-)
* [`addListener('nativeAdLoaded', ...)`](#addlistenernativeadloaded-)
* [`addListener('nativeAdLoadFailed', ...)`](#addlistenernativeadloadfailed-)
* [`addListener('nativeAdImpression', ...)`](#addlistenernativeadimpression-)
* [`addListener('nativeAdClicked', ...)`](#addlistenernativeadclicked-)
* [`removeAllListeners()`](#removealllisteners) * [`removeAllListeners()`](#removealllisteners)
* [Interfaces](#interfaces) * [Interfaces](#interfaces)
* [Type Aliases](#type-aliases) * [Type Aliases](#type-aliases)
@ -558,7 +588,8 @@ covered by Unity's terms.
<docgen-api> <docgen-api>
<!--Update the source file JSDoc comments and rerun docgen to update the docs below--> <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
Unity LevelPlay rewarded and interstitial ads (ad-unit API). Unity LevelPlay ads (ad-unit API): rewarded, interstitial and (since 0.3.0) banner and native ads, impression-level
revenue, segments and placement capping.
### initialize(...) ### initialize(...)
@ -792,6 +823,312 @@ Write the LevelPlay integration helper report to the native log (Xcode console;
-------------------- --------------------
### getCapabilities()
```typescript
getCapabilities() => Promise<Capabilities>
```
What this platform supports (banners, native ad templates, impression data, `adInfoChanged`). Works before init.
Web: everything `false`.
**Returns:** <code>Promise&lt;<a href="#capabilities">Capabilities</a>&gt;</code>
**Since:** 0.3.0
--------------------
### setSegment(...)
```typescript
setSegment(options: SegmentOptions) => Promise<void>
```
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.
| Param | Type |
| ------------- | --------------------------------------------------------- |
| **`options`** | <code><a href="#segmentoptions">SegmentOptions</a></code> |
**Since:** 0.3.0
--------------------
### setDynamicUserId(...)
```typescript
setDynamicUserId(options: DynamicUserIdOptions) => Promise<DynamicUserIdResult>
```
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 }`.
| Param | Type |
| ------------- | --------------------------------------------------------------------- |
| **`options`** | <code><a href="#dynamicuseridoptions">DynamicUserIdOptions</a></code> |
**Returns:** <code>Promise&lt;<a href="#dynamicuseridresult">DynamicUserIdResult</a>&gt;</code>
**Since:** 0.3.0
--------------------
### isPlacementCapped(...)
```typescript
isPlacementCapped(options: PlacementCappedOptions) => Promise<PlacementCappedResult>
```
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 }`.
| Param | Type |
| ------------- | ------------------------------------------------------------------------- |
| **`options`** | <code><a href="#placementcappedoptions">PlacementCappedOptions</a></code> |
**Returns:** <code>Promise&lt;<a href="#placementcappedresult">PlacementCappedResult</a>&gt;</code>
**Since:** 0.3.0
--------------------
### getReward(...)
```typescript
getReward(options: GetRewardOptions) => Promise<Reward>
```
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.
| Param | Type |
| ------------- | ------------------------------------------------------------- |
| **`options`** | <code><a href="#getrewardoptions">GetRewardOptions</a></code> |
**Returns:** <code>Promise&lt;<a href="#reward">Reward</a>&gt;</code>
**Since:** 0.3.0
--------------------
### createBanner(...)
```typescript
createBanner(options: CreateBannerOptions) => Promise<BannerResult>
```
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.
| Param | Type |
| ------------- | ------------------------------------------------------------------- |
| **`options`** | <code><a href="#createbanneroptions">CreateBannerOptions</a></code> |
**Returns:** <code>Promise&lt;<a href="#bannerresult">BannerResult</a>&gt;</code>
**Since:** 0.3.0
--------------------
### loadBanner(...)
```typescript
loadBanner(options: BannerIdOptions) => Promise<void>
```
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.
| Param | Type |
| ------------- | ----------------------------------------------------------- |
| **`options`** | <code><a href="#banneridoptions">BannerIdOptions</a></code> |
**Since:** 0.3.0
--------------------
### showBanner(...)
```typescript
showBanner(options: BannerIdOptions) => Promise<BannerResult>
```
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.
| Param | Type |
| ------------- | ----------------------------------------------------------- |
| **`options`** | <code><a href="#banneridoptions">BannerIdOptions</a></code> |
**Returns:** <code>Promise&lt;<a href="#bannerresult">BannerResult</a>&gt;</code>
**Since:** 0.3.0
--------------------
### hideBanner(...)
```typescript
hideBanner(options: BannerIdOptions) => Promise<void>
```
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.
| Param | Type |
| ------------- | ----------------------------------------------------------- |
| **`options`** | <code><a href="#banneridoptions">BannerIdOptions</a></code> |
**Since:** 0.3.0
--------------------
### setBannerLayout(...)
```typescript
setBannerLayout(options: SetBannerLayoutOptions) => Promise<BannerResult>
```
Move a banner (position, offsets, safe area). Resolves with the new frame. Web: rejects as unimplemented.
| Param | Type |
| ------------- | ------------------------------------------------------------------------- |
| **`options`** | <code><a href="#setbannerlayoutoptions">SetBannerLayoutOptions</a></code> |
**Returns:** <code>Promise&lt;<a href="#bannerresult">BannerResult</a>&gt;</code>
**Since:** 0.3.0
--------------------
### destroyBanner(...)
```typescript
destroyBanner(options: BannerIdOptions) => Promise<void>
```
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.
| Param | Type |
| ------------- | ----------------------------------------------------------- |
| **`options`** | <code><a href="#banneridoptions">BannerIdOptions</a></code> |
**Since:** 0.3.0
--------------------
### loadNativeAd(...)
```typescript
loadNativeAd(options: LoadNativeAdOptions) => 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.
| Param | Type |
| ------------- | ------------------------------------------------------------------- |
| **`options`** | <code><a href="#loadnativeadoptions">LoadNativeAdOptions</a></code> |
**Since:** 0.3.0
--------------------
### showNativeAd(...)
```typescript
showNativeAd(options: NativeAdRectOptions) => 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.
| Param | Type |
| ------------- | ------------------------------------------------------------------- |
| **`options`** | <code><a href="#nativeadrectoptions">NativeAdRectOptions</a></code> |
**Since:** 0.3.0
--------------------
### setNativeAdRect(...)
```typescript
setNativeAdRect(options: NativeAdRectOptions) => Promise<void>
```
Move or resize a shown native ad, for example after the placeholder element moved. Web: no-op.
| Param | Type |
| ------------- | ------------------------------------------------------------------- |
| **`options`** | <code><a href="#nativeadrectoptions">NativeAdRectOptions</a></code> |
**Since:** 0.3.0
--------------------
### hideNativeAd(...)
```typescript
hideNativeAd(options: NativeAdIdOptions) => Promise<void>
```
Hide a shown native ad (the view stays registered; `showNativeAd()` shows it again). Web: no-op.
| Param | Type |
| ------------- | --------------------------------------------------------------- |
| **`options`** | <code><a href="#nativeadidoptions">NativeAdIdOptions</a></code> |
**Since:** 0.3.0
--------------------
### destroyNativeAd(...)
```typescript
destroyNativeAd(options: NativeAdIdOptions) => Promise<void>
```
Remove the native ad view and `destroyAd()` it. Resolves also for unknown ids. Web: no-op.
| Param | Type |
| ------------- | --------------------------------------------------------------- |
| **`options`** | <code><a href="#nativeadidoptions">NativeAdIdOptions</a></code> |
**Since:** 0.3.0
--------------------
### addListener('loaded', ...) ### addListener('loaded', ...)
```typescript ```typescript
@ -932,6 +1269,290 @@ Rewarded only: the user earned the reward. Can fire before or after `closed`.
-------------------- --------------------
### addListener('adInfoChanged', ...)
```typescript
addListener(eventName: 'adInfoChanged', listenerFunc: (event: AdEvent) => 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.
| Param | Type |
| ------------------ | --------------------------------------------------------------- |
| **`eventName`** | <code>'adInfoChanged'</code> |
| **`listenerFunc`** | <code>(event: <a href="#adevent">AdEvent</a>) =&gt; void</code> |
**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
**Since:** 0.3.0
--------------------
### addListener('impressionData', ...)
```typescript
addListener(eventName: 'impressionData', listenerFunc: (event: ImpressionData) => 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.
| Param | Type |
| ------------------ | ----------------------------------------------------------------------------- |
| **`eventName`** | <code>'impressionData'</code> |
| **`listenerFunc`** | <code>(event: <a href="#impressiondata">ImpressionData</a>) =&gt; void</code> |
**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
**Since:** 0.3.0
--------------------
### addListener('bannerLoaded', ...)
```typescript
addListener(eventName: 'bannerLoaded', listenerFunc: (event: BannerEvent) => void) => Promise<PluginListenerHandle>
```
A banner loaded or refreshed with a new creative.
| Param | Type |
| ------------------ | ----------------------------------------------------------------------- |
| **`eventName`** | <code>'bannerLoaded'</code> |
| **`listenerFunc`** | <code>(event: <a href="#bannerevent">BannerEvent</a>) =&gt; void</code> |
**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
**Since:** 0.3.0
--------------------
### addListener('bannerLoadFailed', ...)
```typescript
addListener(eventName: 'bannerLoadFailed', listenerFunc: (event: BannerErrorEvent) => void) => Promise<PluginListenerHandle>
```
A banner load (or refresh) failed. The SDK keeps retrying on its refresh interval.
| Param | Type |
| ------------------ | --------------------------------------------------------------------------------- |
| **`eventName`** | <code>'bannerLoadFailed'</code> |
| **`listenerFunc`** | <code>(event: <a href="#bannererrorevent">BannerErrorEvent</a>) =&gt; void</code> |
**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
**Since:** 0.3.0
--------------------
### addListener('bannerDisplayed', ...)
```typescript
addListener(eventName: 'bannerDisplayed', listenerFunc: (event: BannerEvent) => void) => Promise<PluginListenerHandle>
```
A banner creative was displayed on screen (impression).
| Param | Type |
| ------------------ | ----------------------------------------------------------------------- |
| **`eventName`** | <code>'bannerDisplayed'</code> |
| **`listenerFunc`** | <code>(event: <a href="#bannerevent">BannerEvent</a>) =&gt; void</code> |
**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
**Since:** 0.3.0
--------------------
### addListener('bannerDisplayFailed', ...)
```typescript
addListener(eventName: 'bannerDisplayFailed', listenerFunc: (event: BannerErrorEvent) => void) => Promise<PluginListenerHandle>
```
A banner creative failed to display.
| Param | Type |
| ------------------ | --------------------------------------------------------------------------------- |
| **`eventName`** | <code>'bannerDisplayFailed'</code> |
| **`listenerFunc`** | <code>(event: <a href="#bannererrorevent">BannerErrorEvent</a>) =&gt; void</code> |
**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
**Since:** 0.3.0
--------------------
### addListener('bannerClicked', ...)
```typescript
addListener(eventName: 'bannerClicked', listenerFunc: (event: BannerEvent) => void) => Promise<PluginListenerHandle>
```
The user clicked a banner.
| Param | Type |
| ------------------ | ----------------------------------------------------------------------- |
| **`eventName`** | <code>'bannerClicked'</code> |
| **`listenerFunc`** | <code>(event: <a href="#bannerevent">BannerEvent</a>) =&gt; void</code> |
**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
**Since:** 0.3.0
--------------------
### addListener('bannerExpanded', ...)
```typescript
addListener(eventName: 'bannerExpanded', listenerFunc: (event: BannerEvent) => void) => Promise<PluginListenerHandle>
```
A banner opened full screen (for example an expandable creative). Pause the game.
| Param | Type |
| ------------------ | ----------------------------------------------------------------------- |
| **`eventName`** | <code>'bannerExpanded'</code> |
| **`listenerFunc`** | <code>(event: <a href="#bannerevent">BannerEvent</a>) =&gt; void</code> |
**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
**Since:** 0.3.0
--------------------
### addListener('bannerCollapsed', ...)
```typescript
addListener(eventName: 'bannerCollapsed', listenerFunc: (event: BannerEvent) => void) => Promise<PluginListenerHandle>
```
A banner returned to its normal size. Resume the game.
| Param | Type |
| ------------------ | ----------------------------------------------------------------------- |
| **`eventName`** | <code>'bannerCollapsed'</code> |
| **`listenerFunc`** | <code>(event: <a href="#bannerevent">BannerEvent</a>) =&gt; void</code> |
**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
**Since:** 0.3.0
--------------------
### addListener('bannerLeftApplication', ...)
```typescript
addListener(eventName: 'bannerLeftApplication', listenerFunc: (event: BannerEvent) => void) => Promise<PluginListenerHandle>
```
A banner click sent the user out of the app (browser or store).
| Param | Type |
| ------------------ | ----------------------------------------------------------------------- |
| **`eventName`** | <code>'bannerLeftApplication'</code> |
| **`listenerFunc`** | <code>(event: <a href="#bannerevent">BannerEvent</a>) =&gt; void</code> |
**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
**Since:** 0.3.0
--------------------
### addListener('nativeAdLoaded', ...)
```typescript
addListener(eventName: 'nativeAdLoaded', listenerFunc: (event: NativeAdEvent) => void) => Promise<PluginListenerHandle>
```
A native ad loaded and can be shown with `showNativeAd()`.
| Param | Type |
| ------------------ | --------------------------------------------------------------------------- |
| **`eventName`** | <code>'nativeAdLoaded'</code> |
| **`listenerFunc`** | <code>(event: <a href="#nativeadevent">NativeAdEvent</a>) =&gt; void</code> |
**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
**Since:** 0.3.0
--------------------
### addListener('nativeAdLoadFailed', ...)
```typescript
addListener(eventName: 'nativeAdLoadFailed', listenerFunc: (event: NativeAdErrorEvent) => void) => Promise<PluginListenerHandle>
```
A native ad failed to load. Load again later (the plugin already destroyed the failed ad object).
| Param | Type |
| ------------------ | ------------------------------------------------------------------------------------- |
| **`eventName`** | <code>'nativeAdLoadFailed'</code> |
| **`listenerFunc`** | <code>(event: <a href="#nativeaderrorevent">NativeAdErrorEvent</a>) =&gt; void</code> |
**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
**Since:** 0.3.0
--------------------
### addListener('nativeAdImpression', ...)
```typescript
addListener(eventName: 'nativeAdImpression', listenerFunc: (event: NativeAdEvent) => void) => Promise<PluginListenerHandle>
```
A shown native ad recorded its impression (first pixel visible).
| Param | Type |
| ------------------ | --------------------------------------------------------------------------- |
| **`eventName`** | <code>'nativeAdImpression'</code> |
| **`listenerFunc`** | <code>(event: <a href="#nativeadevent">NativeAdEvent</a>) =&gt; void</code> |
**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
**Since:** 0.3.0
--------------------
### addListener('nativeAdClicked', ...)
```typescript
addListener(eventName: 'nativeAdClicked', listenerFunc: (event: NativeAdEvent) => void) => Promise<PluginListenerHandle>
```
The user clicked a native ad.
| Param | Type |
| ------------------ | --------------------------------------------------------------------------- |
| **`eventName`** | <code>'nativeAdClicked'</code> |
| **`listenerFunc`** | <code>(event: <a href="#nativeadevent">NativeAdEvent</a>) =&gt; void</code> |
**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
**Since:** 0.3.0
--------------------
### removeAllListeners() ### removeAllListeners()
```typescript ```typescript
@ -1051,7 +1672,7 @@ Subset of the native `LevelPlayAdInfo` (Android) / `LPMAdInfo` (iOS) that is use
Fields the SDK does not report are omitted. Fields the SDK does not report are omitted.
| Prop | Type | Description | Since | | Prop | Type | Description | Since |
| ------------------- | ------------------- | ------------------------------------------------------------------------------------- | ----- | | --------------------- | ------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`adId`** | <code>string</code> | Unique id of this ad. | 0.1.0 | | **`adId`** | <code>string</code> | Unique id of this ad. | 0.1.0 |
| **`adUnitId`** | <code>string</code> | Ad unit id. | 0.1.0 | | **`adUnitId`** | <code>string</code> | Ad unit id. | 0.1.0 |
| **`adUnitName`** | <code>string</code> | Ad unit name from the dashboard. | 0.1.0 | | **`adUnitName`** | <code>string</code> | Ad unit name from the dashboard. | 0.1.0 |
@ -1064,6 +1685,25 @@ Fields the SDK does not report are omitted.
| **`auctionId`** | <code>string</code> | Auction id. | 0.1.0 | | **`auctionId`** | <code>string</code> | Auction id. | 0.1.0 |
| **`revenue`** | <code>number</code> | Impression revenue in USD as reported by the SDK (may be absent or 0 before display). | 0.1.0 | | **`revenue`** | <code>number</code> | Impression revenue in USD as reported by the SDK (may be absent or 0 before display). | 0.1.0 |
| **`precision`** | <code>string</code> | Revenue precision as reported by the SDK. | 0.1.0 | | **`precision`** | <code>string</code> | Revenue precision as reported by the SDK. | 0.1.0 |
| **`ab`** | <code>string</code> | A/B test group of the user (`ab`). | 0.3.0 |
| **`segmentName`** | <code>string</code> | Segment name of the user, see `setSegment()`. | 0.3.0 |
| **`encryptedCPM`** | <code>string</code> | Encrypted CPM (`encryptedCPM`). | 0.3.0 |
| **`creativeId`** | <code>string</code> | Creative id of the served ad, when the network reports one. | 0.3.0 |
| **`conversionValue`** | <code>number</code> | 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. | 0.3.0 |
| **`adSize`** | <code><a href="#adsizeinfo">AdSizeInfo</a></code> | Size of the ad. Banners only (`LevelPlayAdInfo.getAdSize()` / `LPMAdInfo.adSize`). | 0.3.0 |
#### 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.
| Prop | Type | Description | Since |
| ----------------- | -------------------- | ---------------------------------------------------------------- | ----- |
| **`width`** | <code>number</code> | Width in CSS px (dp / pt). | 0.3.0 |
| **`height`** | <code>number</code> | Height in CSS px (dp / pt). | 0.3.0 |
| **`description`** | <code>string</code> | SDK description of the size, for example `BANNER` or `ADAPTIVE`. | 0.3.0 |
| **`isAdaptive`** | <code>boolean</code> | `true` for an adaptive size. | 0.3.0 |
#### ShowOptions #### ShowOptions
@ -1093,6 +1733,175 @@ Options for `isReady()`: `adUnitId` (see <a href="#adunitoptions">AdUnitOptions<
| **`format`** | <code><a href="#adformat">AdFormat</a></code> | Format of the ad unit. | 0.1.0 | | **`format`** | <code><a href="#adformat">AdFormat</a></code> | Format of the ad unit. | 0.1.0 |
#### Capabilities
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.
| Prop | Type | Description | Since |
| ----------------------- | ------------------------------- | ------------------------------------------------------------------------------- | ----- |
| **`banner`** | <code>boolean</code> | Banner ads (`createBanner()` and friends) are available. | 0.3.0 |
| **`nativeAd`** | <code>boolean</code> | Native ads (`loadNativeAd()` and friends) are available. | 0.3.0 |
| **`nativeAdTemplates`** | <code>NativeAdTemplate[]</code> | Native ad templates this platform can render. Empty when `nativeAd` is `false`. | 0.3.0 |
| **`impressionData`** | <code>boolean</code> | The `impressionData` event is delivered. | 0.3.0 |
| **`adInfoChanged`** | <code>boolean</code> | The `adInfoChanged` event is delivered (rewarded and interstitial only). | 0.3.0 |
#### SegmentOptions
Options for `setSegment()` (`LevelPlaySegment` / `LPMSegment`). Omitted fields are not sent.
| Prop | Type | Description | Since |
| ---------------------- | --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`segmentName`** | <code>string</code> | Segment name. | 0.3.0 |
| **`level`** | <code>number</code> | User level (integer). | 0.3.0 |
| **`isPaying`** | <code>boolean</code> | The user has paid in the app. | 0.3.0 |
| **`userCreationDate`** | <code>number</code> | When the user was created, in milliseconds since the Unix epoch (`Date.now()` style). | 0.3.0 |
| **`iapTotal`** | <code>number</code> | Total in-app purchase amount of the user (USD). | 0.3.0 |
| **`customParameters`** | <code>{ [key: string]: string; }</code> | 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. | 0.3.0 |
#### DynamicUserIdResult
Result of `setDynamicUserId()`.
| Prop | Type | Description | Since |
| ----------- | -------------------- | ------------------------------------------------------------------------------------------- | ----- |
| **`valid`** | <code>boolean</code> | The SDK accepted the id (`LevelPlay.setDynamicUserId` returns a boolean on both platforms). | 0.3.0 |
#### DynamicUserIdOptions
Options for `setDynamicUserId()`.
| Prop | Type | Description | Since |
| ------------ | ------------------- | ----------------------------------------------------------------------------------------------- | ----- |
| **`userId`** | <code>string</code> | Dynamic user id, forwarded in server-to-server reward callbacks. Can change during the session. | 0.3.0 |
#### PlacementCappedResult
Result of `isPlacementCapped()`.
| Prop | Type | Description | Since |
| ------------ | -------------------- | ------------------------------------------------------------------------------------ | ----- |
| **`capped`** | <code>boolean</code> | `true` when the placement reached its capping or pacing limit; showing it now fails. | 0.3.0 |
#### PlacementCappedOptions
Options for `isPlacementCapped()`.
| Prop | Type | Description | Since |
| ------------------- | --------------------------------------------- | ----------------------------------------------------------------------------------------------- | ----- |
| **`format`** | <code><a href="#adformat">AdFormat</a></code> | Format of the placement. LevelPlay 9.6.1 has capping checks for rewarded and interstitial only. | 0.3.0 |
| **`placementName`** | <code>string</code> | Placement name from the LevelPlay dashboard. | 0.3.0 |
#### GetRewardOptions
Options for `getReward()`: `adUnitId` (see <a href="#adunitoptions">AdUnitOptions</a>) plus an optional placement.
| Prop | Type | Description | Since |
| ------------------- | ------------------- | ----------------------------------------------------------------------------------------------------------------- | ----- |
| **`placementName`** | <code>string</code> | Placement whose reward to read. Its reward takes precedence over the ad unit reward. Omit for the ad unit reward. | 0.3.0 |
#### BannerResult
Result of `createBanner()`, `showBanner()` and `setBannerLayout()`.
| Prop | Type | Description | Since |
| -------------- | ------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`bannerId`** | <code>string</code> | The banner id. | 0.3.0 |
| **`adSize`** | <code><a href="#adsizeinfo">AdSizeInfo</a></code> | Requested ad size (the creative may be smaller for adaptive sizes; it is centred in this frame). | 0.3.0 |
| **`frame`** | <code><a href="#rect">Rect</a></code> | 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. | 0.3.0 |
| **`visible`** | <code>boolean</code> | The banner view is currently visible. | 0.3.0 |
#### Rect
A rectangle in CSS px, relative to the top-left corner of the WebView viewport (the same space as
`element.getBoundingClientRect()` without page scroll).
| Prop | Type | Description | Since |
| ------------ | ------------------- | -------------------- | ----- |
| **`x`** | <code>number</code> | Left edge in CSS px. | 0.3.0 |
| **`y`** | <code>number</code> | Top edge in CSS px. | 0.3.0 |
| **`width`** | <code>number</code> | Width in CSS px. | 0.3.0 |
| **`height`** | <code>number</code> | Height in CSS px. | 0.3.0 |
#### CreateBannerOptions
Options for `createBanner()`.
| Prop | Type | Description | Default | Since |
| ------------------- | ------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- | ----- |
| **`bannerId`** | <code>string</code> | 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`. | | 0.3.0 |
| **`size`** | <code><a href="#bannersize">BannerSize</a></code> | Size preset. | <code>'ADAPTIVE'</code> | 0.3.0 |
| **`adaptiveWidth`** | <code>number</code> | `ADAPTIVE` only: width in CSS px to compute the adaptive size for. Defaults to the width of the WebView's safe area. | | 0.3.0 |
| **`placementName`** | <code>string</code> | Placement name (reporting only for banners). Applied through the banner config before the first load. | | 0.3.0 |
| **`bidFloor`** | <code>number</code> | Bid floor in USD (`LevelPlayBannerAdView.Config.Builder.setBidFloor` / `LPMBannerAdViewConfigBuilder set(bidFloor:)`). | | 0.3.0 |
#### BannerIdOptions
Identifies one banner created with `createBanner()`.
| Prop | Type | Description | Since |
| -------------- | ------------------- | ------------------------------------------------------------------------------------ | ----- |
| **`bannerId`** | <code>string</code> | Plugin-side banner id passed to `createBanner()` (defaults to the ad unit id there). | 0.3.0 |
#### SetBannerLayoutOptions
Options for `setBannerLayout()`: `bannerId` plus the layout fields (see BannerLayoutOptions).
#### LoadNativeAdOptions
Options for `loadNativeAd()`.
| Prop | Type | Description | Default | Since |
| ------------------- | ----------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ----- |
| **`placementName`** | <code>string</code> | 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. | | 0.3.0 |
| **`template`** | <code><a href="#nativeadtemplate">NativeAdTemplate</a></code> | Template used when the ad is shown. | <code>'medium'</code> | 0.3.0 |
| **`style`** | <code><a href="#nativeadtemplatestyle">NativeAdTemplateStyle</a></code> | Template styling. | | 0.3.0 |
#### NativeAdTemplateStyle
Optional styling of a native ad template. Colours are CSS hex strings (`#RRGGBB` or `#RRGGBBAA`).
| Prop | Type | Description | Default | Since |
| --------------------------------- | ------------------- | ---------------------------------------- | -------------- | ----- |
| **`backgroundColor`** | <code>string</code> | Template background. | | 0.3.0 |
| **`titleColor`** | <code>string</code> | Title text colour. | | 0.3.0 |
| **`bodyColor`** | <code>string</code> | Body and advertiser text colour. | | 0.3.0 |
| **`callToActionBackgroundColor`** | <code>string</code> | Call-to-action button background. | | 0.3.0 |
| **`callToActionTextColor`** | <code>string</code> | Call-to-action button text colour. | | 0.3.0 |
| **`cornerRadius`** | <code>number</code> | Corner radius of the template in CSS px. | <code>0</code> | 0.3.0 |
#### NativeAdRectOptions
Options for `showNativeAd()` and `setNativeAdRect()`.
| Prop | Type | Description | Since |
| ---------- | ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | ----- |
| **`rect`** | <code><a href="#rect">Rect</a></code> | Where the template goes, in CSS px relative to the WebView viewport (for example a placeholder element's `getBoundingClientRect()`). | 0.3.0 |
#### NativeAdIdOptions
Identifies one native ad slot.
| Prop | Type | Description | Since |
| ---------------- | ------------------- | ------------------------------------- | ----- |
| **`nativeAdId`** | <code>string</code> | Plugin-side id of the native ad slot. | 0.3.0 |
#### PluginListenerHandle #### PluginListenerHandle
| Prop | Type | | Prop | Type |
@ -1129,6 +1938,96 @@ Payload of the `rewarded` event: the <a href="#adevent">AdEvent</a> fields plus
| **`reward`** | <code><a href="#reward">Reward</a></code> | The reward earned. | 0.1.0 | | **`reward`** | <code><a href="#reward">Reward</a></code> | The reward earned. | 0.1.0 |
#### ImpressionData
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`.
| Prop | Type | Description | Since |
| --------------------- | ---------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`adFormat`** | <code>string</code> | 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). | 0.3.0 |
| **`auctionId`** | <code>string</code> | Auction id. | 0.3.0 |
| **`adUnitId`** | <code>string</code> | Mediation ad unit id (`mediationAdUnitId`). | 0.3.0 |
| **`adUnitName`** | <code>string</code> | Mediation ad unit name (`mediationAdUnitName`). | 0.3.0 |
| **`adNetwork`** | <code>string</code> | Mediated network that served the ad. | 0.3.0 |
| **`instanceName`** | <code>string</code> | Mediation instance name. | 0.3.0 |
| **`instanceId`** | <code>string</code> | Mediation instance id. | 0.3.0 |
| **`country`** | <code>string</code> | Country code. | 0.3.0 |
| **`placement`** | <code>string</code> | Placement name of the impression. | 0.3.0 |
| **`revenue`** | <code>number</code> | Revenue of this impression in USD. | 0.3.0 |
| **`precision`** | <code>string</code> | Revenue precision (for example `BID`, `RATE`, `ESTIMATED`). | 0.3.0 |
| **`ab`** | <code>string</code> | A/B test group. | 0.3.0 |
| **`segmentName`** | <code>string</code> | Segment name, see `setSegment()`. | 0.3.0 |
| **`encryptedCPM`** | <code>string</code> | Encrypted CPM (`encryptedCPM` on Android, `encryptedCpm` on iOS). | 0.3.0 |
| **`creativeId`** | <code>string</code> | Creative id. | 0.3.0 |
| **`conversionValue`** | <code>number</code> | iOS only: SKAdNetwork conversion value. | 0.3.0 |
| **`allData`** | <code>{ [key: string]: unknown; }</code> | 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. | 0.3.0 |
#### BannerEvent
Payload of the `banner*` events.
| Prop | Type | Description | Since |
| -------------- | ----------------------------------------- | -------------------------------------------------------------- | ----- |
| **`bannerId`** | <code>string</code> | Banner that fired the event. | 0.3.0 |
| **`adUnitId`** | <code>string</code> | Ad unit of the banner. | 0.3.0 |
| **`adInfo`** | <code><a href="#adinfo">AdInfo</a></code> | Ad info, when the SDK provides it (not on `bannerLoadFailed`). | 0.3.0 |
| **`frame`** | <code><a href="#rect">Rect</a></code> | Current frame of the banner in CSS px. | 0.3.0 |
#### BannerErrorEvent
Payload of `bannerLoadFailed` and `bannerDisplayFailed`.
| Prop | Type | Description | Since |
| ----------- | ------------------------------------------- | ---------------- | ----- |
| **`error`** | <code><a href="#aderror">AdError</a></code> | What went wrong. | 0.3.0 |
#### NativeAdEvent
Payload of the `nativeAd*` events.
| Prop | Type | Description | Since |
| ------------------- | ----------------------------------------------------- | ---------------------------------------------------------------- | ----- |
| **`nativeAdId`** | <code>string</code> | Native ad slot that fired the event. | 0.3.0 |
| **`placementName`** | <code>string</code> | Placement passed to `loadNativeAd()`, if any. | 0.3.0 |
| **`adInfo`** | <code><a href="#nativeadinfo">NativeAdInfo</a></code> | Ad info, when the SDK provides it (not on `nativeAdLoadFailed`). | 0.3.0 |
#### NativeAdInfo
Ad info of a native ad (<a href="#adinfo">`AdInfo`</a> on Android / `ISAdInfo` on iOS: the older ironSource info type, which has no ad
unit, ad id or placement fields).
| Prop | Type | Description | Since |
| --------------------- | ------------------- | --------------------------------------- | ----- |
| **`auctionId`** | <code>string</code> | Auction id. | 0.3.0 |
| **`adNetwork`** | <code>string</code> | Mediated network that served the ad. | 0.3.0 |
| **`instanceName`** | <code>string</code> | Mediation instance name. | 0.3.0 |
| **`instanceId`** | <code>string</code> | Mediation instance id. | 0.3.0 |
| **`country`** | <code>string</code> | Country code. | 0.3.0 |
| **`revenue`** | <code>number</code> | Impression revenue in USD. | 0.3.0 |
| **`precision`** | <code>string</code> | Revenue precision. | 0.3.0 |
| **`ab`** | <code>string</code> | A/B test group. | 0.3.0 |
| **`segmentName`** | <code>string</code> | Segment name. | 0.3.0 |
| **`encryptedCPM`** | <code>string</code> | Encrypted CPM. | 0.3.0 |
| **`conversionValue`** | <code>number</code> | iOS only: SKAdNetwork conversion value. | 0.3.0 |
#### NativeAdErrorEvent
Payload of `nativeAdLoadFailed`.
| Prop | Type | Description | Since |
| ----------- | ------------------------------------------- | ---------------- | ----- |
| **`error`** | <code><a href="#aderror">AdError</a></code> | What went wrong. | 0.3.0 |
### Type Aliases ### Type Aliases
@ -1141,10 +2040,39 @@ iOS App Tracking Transparency status. `unavailable` on Android, on the web and o
#### AdFormat #### AdFormat
Full-screen ad formats supported by this plugin. Banners and native ads are intentionally not exposed. 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.
<code>'rewarded' | 'interstitial'</code> <code>'rewarded' | 'interstitial'</code>
#### NativeAdTemplate
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.
<code>'small' | 'medium'</code>
#### BannerSize
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()`.
<code>'BANNER' | 'LARGE' | 'MEDIUM_RECTANGLE' | 'LEADERBOARD' | 'ADAPTIVE'</code>
</docgen-api> </docgen-api>
## Contributing ## Contributing

2249
dist/docs.json vendored

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

22
dist/esm/web.d.ts vendored
View file

@ -1,8 +1,12 @@
import { WebPlugin } from '@capacitor/core'; import { WebPlugin } from '@capacitor/core';
import type { AdUnitOptions, ConsentOptions, InitOptions, InitResult, IsReadyResult, LevelPlayPlugin, MetaDataOptions, ShowResult, TrackingResult } from './definitions'; import type { AdUnitOptions, BannerIdOptions, BannerResult, Capabilities, ConsentOptions, CreateBannerOptions, DynamicUserIdOptions, DynamicUserIdResult, GetRewardOptions, InitOptions, InitResult, IsReadyResult, LevelPlayPlugin, LoadNativeAdOptions, MetaDataOptions, NativeAdIdOptions, NativeAdRectOptions, PlacementCappedOptions, PlacementCappedResult, Reward, SegmentOptions, SetBannerLayoutOptions, ShowResult, TrackingResult } from './definitions';
/** /**
* Web stub. LevelPlay has no web SDK: init rejects with `unimplemented`, ads are never ready and every show resolves * Web stub. LevelPlay has no web SDK: init rejects with `unimplemented`, ads are never ready and every show resolves
* as "not shown" so callers can treat the web like a no-fill platform without special casing. * as "not shown" so callers can treat the web like a no-fill platform without special casing.
*
* 0.3.0: `getCapabilities()` reports nothing supported. Setters, loads of things that cannot exist, hide and destroy
* are no-ops; calls that would have to return a native view (`createBanner`, `showBanner`, `setBannerLayout`,
* `loadNativeAd`, `showNativeAd`) reject as unimplemented, like `initialize`.
*/ */
export declare class LevelPlayWeb extends WebPlugin implements LevelPlayPlugin { export declare class LevelPlayWeb extends WebPlugin implements LevelPlayPlugin {
private static readonly NO_FILL; private static readonly NO_FILL;
@ -19,4 +23,20 @@ export declare class LevelPlayWeb extends WebPlugin implements LevelPlayPlugin {
isReady(): Promise<IsReadyResult>; isReady(): Promise<IsReadyResult>;
launchTestSuite(): Promise<void>; launchTestSuite(): Promise<void>;
validateIntegration(): Promise<void>; validateIntegration(): Promise<void>;
getCapabilities(): Promise<Capabilities>;
setSegment(_options: SegmentOptions): Promise<void>;
setDynamicUserId(_options: DynamicUserIdOptions): Promise<DynamicUserIdResult>;
isPlacementCapped(_options: PlacementCappedOptions): Promise<PlacementCappedResult>;
getReward(_options: GetRewardOptions): Promise<Reward>;
createBanner(_options: CreateBannerOptions): Promise<BannerResult>;
loadBanner(_options: BannerIdOptions): Promise<void>;
showBanner(_options: BannerIdOptions): Promise<BannerResult>;
hideBanner(_options: BannerIdOptions): Promise<void>;
setBannerLayout(_options: SetBannerLayoutOptions): Promise<BannerResult>;
destroyBanner(_options: BannerIdOptions): Promise<void>;
loadNativeAd(_options: LoadNativeAdOptions): Promise<void>;
showNativeAd(_options: NativeAdRectOptions): Promise<void>;
setNativeAdRect(_options: NativeAdRectOptions): Promise<void>;
hideNativeAd(_options: NativeAdIdOptions): Promise<void>;
destroyNativeAd(_options: NativeAdIdOptions): Promise<void>;
} }

52
dist/esm/web.js vendored
View file

@ -2,6 +2,10 @@ import { WebPlugin } from '@capacitor/core';
/** /**
* Web stub. LevelPlay has no web SDK: init rejects with `unimplemented`, ads are never ready and every show resolves * Web stub. LevelPlay has no web SDK: init rejects with `unimplemented`, ads are never ready and every show resolves
* as "not shown" so callers can treat the web like a no-fill platform without special casing. * as "not shown" so callers can treat the web like a no-fill platform without special casing.
*
* 0.3.0: `getCapabilities()` reports nothing supported. Setters, loads of things that cannot exist, hide and destroy
* are no-ops; calls that would have to return a native view (`createBanner`, `showBanner`, `setBannerLayout`,
* `loadNativeAd`, `showNativeAd`) reject as unimplemented, like `initialize`.
*/ */
export class LevelPlayWeb extends WebPlugin { export class LevelPlayWeb extends WebPlugin {
async initialize(_options) { async initialize(_options) {
@ -43,6 +47,54 @@ export class LevelPlayWeb extends WebPlugin {
async validateIntegration() { async validateIntegration() {
/* nothing to validate */ /* nothing to validate */
} }
async getCapabilities() {
return { banner: false, nativeAd: false, nativeAdTemplates: [], impressionData: false, adInfoChanged: false };
}
async setSegment(_options) {
/* nothing to forward */
}
async setDynamicUserId(_options) {
return { valid: false };
}
async isPlacementCapped(_options) {
return { capped: false };
}
async getReward(_options) {
return { name: '', amount: 0 };
}
async createBanner(_options) {
throw this.unimplemented('LevelPlay banners are not available on the web.');
}
async loadBanner(_options) {
/* never fills */
}
async showBanner(_options) {
throw this.unimplemented('LevelPlay banners are not available on the web.');
}
async hideBanner(_options) {
/* nothing shown */
}
async setBannerLayout(_options) {
throw this.unimplemented('LevelPlay banners are not available on the web.');
}
async destroyBanner(_options) {
/* nothing to destroy */
}
async loadNativeAd(_options) {
throw this.unimplemented('LevelPlay native ads are not available on the web.');
}
async showNativeAd(_options) {
throw this.unimplemented('LevelPlay native ads are not available on the web.');
}
async setNativeAdRect(_options) {
/* nothing shown */
}
async hideNativeAd(_options) {
/* nothing shown */
}
async destroyNativeAd(_options) {
/* nothing to destroy */
}
} }
LevelPlayWeb.NO_FILL = { LevelPlayWeb.NO_FILL = {
shown: false, shown: false,

2
dist/esm/web.js.map vendored

File diff suppressed because one or more lines are too long

52
dist/plugin.cjs.js vendored
View file

@ -28,6 +28,10 @@ const LevelPlay = core.registerPlugin('LevelPlay', {
/** /**
* Web stub. LevelPlay has no web SDK: init rejects with `unimplemented`, ads are never ready and every show resolves * Web stub. LevelPlay has no web SDK: init rejects with `unimplemented`, ads are never ready and every show resolves
* as "not shown" so callers can treat the web like a no-fill platform without special casing. * as "not shown" so callers can treat the web like a no-fill platform without special casing.
*
* 0.3.0: `getCapabilities()` reports nothing supported. Setters, loads of things that cannot exist, hide and destroy
* are no-ops; calls that would have to return a native view (`createBanner`, `showBanner`, `setBannerLayout`,
* `loadNativeAd`, `showNativeAd`) reject as unimplemented, like `initialize`.
*/ */
class LevelPlayWeb extends core.WebPlugin { class LevelPlayWeb extends core.WebPlugin {
async initialize(_options) { async initialize(_options) {
@ -69,6 +73,54 @@ class LevelPlayWeb extends core.WebPlugin {
async validateIntegration() { async validateIntegration() {
/* nothing to validate */ /* nothing to validate */
} }
async getCapabilities() {
return { banner: false, nativeAd: false, nativeAdTemplates: [], impressionData: false, adInfoChanged: false };
}
async setSegment(_options) {
/* nothing to forward */
}
async setDynamicUserId(_options) {
return { valid: false };
}
async isPlacementCapped(_options) {
return { capped: false };
}
async getReward(_options) {
return { name: '', amount: 0 };
}
async createBanner(_options) {
throw this.unimplemented('LevelPlay banners are not available on the web.');
}
async loadBanner(_options) {
/* never fills */
}
async showBanner(_options) {
throw this.unimplemented('LevelPlay banners are not available on the web.');
}
async hideBanner(_options) {
/* nothing shown */
}
async setBannerLayout(_options) {
throw this.unimplemented('LevelPlay banners are not available on the web.');
}
async destroyBanner(_options) {
/* nothing to destroy */
}
async loadNativeAd(_options) {
throw this.unimplemented('LevelPlay native ads are not available on the web.');
}
async showNativeAd(_options) {
throw this.unimplemented('LevelPlay native ads are not available on the web.');
}
async setNativeAdRect(_options) {
/* nothing shown */
}
async hideNativeAd(_options) {
/* nothing shown */
}
async destroyNativeAd(_options) {
/* nothing to destroy */
}
} }
LevelPlayWeb.NO_FILL = { LevelPlayWeb.NO_FILL = {
shown: false, shown: false,

File diff suppressed because one or more lines are too long

52
dist/plugin.js vendored
View file

@ -27,6 +27,10 @@ var capacitorLevelPlay = (function (exports, core) {
/** /**
* Web stub. LevelPlay has no web SDK: init rejects with `unimplemented`, ads are never ready and every show resolves * Web stub. LevelPlay has no web SDK: init rejects with `unimplemented`, ads are never ready and every show resolves
* as "not shown" so callers can treat the web like a no-fill platform without special casing. * as "not shown" so callers can treat the web like a no-fill platform without special casing.
*
* 0.3.0: `getCapabilities()` reports nothing supported. Setters, loads of things that cannot exist, hide and destroy
* are no-ops; calls that would have to return a native view (`createBanner`, `showBanner`, `setBannerLayout`,
* `loadNativeAd`, `showNativeAd`) reject as unimplemented, like `initialize`.
*/ */
class LevelPlayWeb extends core.WebPlugin { class LevelPlayWeb extends core.WebPlugin {
async initialize(_options) { async initialize(_options) {
@ -68,6 +72,54 @@ var capacitorLevelPlay = (function (exports, core) {
async validateIntegration() { async validateIntegration() {
/* nothing to validate */ /* nothing to validate */
} }
async getCapabilities() {
return { banner: false, nativeAd: false, nativeAdTemplates: [], impressionData: false, adInfoChanged: false };
}
async setSegment(_options) {
/* nothing to forward */
}
async setDynamicUserId(_options) {
return { valid: false };
}
async isPlacementCapped(_options) {
return { capped: false };
}
async getReward(_options) {
return { name: '', amount: 0 };
}
async createBanner(_options) {
throw this.unimplemented('LevelPlay banners are not available on the web.');
}
async loadBanner(_options) {
/* never fills */
}
async showBanner(_options) {
throw this.unimplemented('LevelPlay banners are not available on the web.');
}
async hideBanner(_options) {
/* nothing shown */
}
async setBannerLayout(_options) {
throw this.unimplemented('LevelPlay banners are not available on the web.');
}
async destroyBanner(_options) {
/* nothing to destroy */
}
async loadNativeAd(_options) {
throw this.unimplemented('LevelPlay native ads are not available on the web.');
}
async showNativeAd(_options) {
throw this.unimplemented('LevelPlay native ads are not available on the web.');
}
async setNativeAdRect(_options) {
/* nothing shown */
}
async hideNativeAd(_options) {
/* nothing shown */
}
async destroyNativeAd(_options) {
/* nothing to destroy */
}
} }
LevelPlayWeb.NO_FILL = { LevelPlayWeb.NO_FILL = {
shown: false, shown: false,

2
dist/plugin.js.map vendored

File diff suppressed because one or more lines are too long

446
docs/design-0.3.md Normal file
View file

@ -0,0 +1,446 @@
# capacitor-levelplay 0.3.0 · API design
Status: phase 1 (API design). `src/definitions.ts` and `src/web.ts` carry the new API; Android and iOS bridges are
not implemented yet. Until they are, calling a new method on a device rejects with Capacitor's `UNIMPLEMENTED`.
Scope (owner approved): banners, native ads (template overlay), impression-level revenue, `adInfoChanged`, placement
capping and reward lookup, segments, dynamic user id, full backwards compatibility with 0.2.x, and a Capacitor 7
compatibility study.
## 0. Sources and method
Every native name below was read from the SDK binaries of **LevelPlay 9.6.1**, not only from the docs:
- **Android**: `com.unity3d.ads-mediation:mediation-sdk:9.6.1` AAR from Maven Central, `classes.jar` listed with
`javap -public` (JDK 21). The AAR manifest declares `minSdkVersion="19"`.
- **iOS**: `IronSource.xcframework` (`CFBundleShortVersionString` 9.6.1, `MinimumOSVersion` 12.0) from the
`LevelPlay-Swift-Package` SPM checkout, `ios-arm64/IronSource.framework/Headers/*.h`. `IronSource.h` defines
`MEDIATION_SDK_VERSION = @"9.6.1"`. The framework ships no `.swiftinterface`; Swift names come from
`NS_SWIFT_NAME` annotations and the ObjC importer.
- Unity docs (behaviour, not names): `docs.unity.com/en-us/grow/levelplay/sdk/{android,ios}/banner-integration`,
`.../android/native-ads-integration`, `.../flutter/native-ads-integration`.
- Capacitor: `@capacitor/android` and `@capacitor/ios` 7.6.9 and 8.5.3 npm tarballs, diffed.
Notation: `A:` Android (package `com.unity3d.mediation` unless a full name is given), `I:` iOS (header file name).
## 1. Compatibility rules for 0.3.0
- No existing method, option, event or type is renamed or removed. `AdFormat` stays `'rewarded' | 'interstitial'`
(widening it would break exhaustive `switch` statements in 0.2.x code), so banners and native ads get their own
methods and their own event names (`banner*`, `nativeAd*`) instead of reusing `loaded`, `clicked` ...
- `AdInfo` only gains optional fields. `LevelPlayEventName` only gains members.
- Existing events keep their payloads; `adInfoChanged` and `impressionData` are new names.
- Reject codes reuse the existing string style (`INVALID_ARGUMENT`, `NO_VIEW_CONTROLLER`).
## 2. Capabilities
`getCapabilities(): Promise<Capabilities>` → `{ banner, nativeAd, nativeAdTemplates, impressionData, adInfoChanged }`.
| | Android | iOS | Web |
|---|---|---|---|
| `banner` | true | true | false |
| `nativeAd` | true | true | false |
| `nativeAdTemplates` | `['small','medium']` | `['small','medium']` | `[]` |
| `impressionData` | true | true | false |
| `adInfoChanged` | true | true | false |
It is the honest switch the owner asked for: if a platform implementation ever has to drop a feature (for example
templates do not pass review on one OS), the flag goes `false` and the methods reject `UNSUPPORTED`, without an API
change.
## 3. Banners
### 3.1 TS API
```ts
createBanner({ adUnitId, bannerId?, size?: 'BANNER'|'LARGE'|'MEDIUM_RECTANGLE'|'LEADERBOARD'|'ADAPTIVE',
adaptiveWidth?, placementName?, bidFloor?, position?: 'top'|'bottom'|'center',
offsetX?, offsetY?, respectSafeArea? }): Promise<BannerResult>
loadBanner({ bannerId }): Promise<void>
showBanner({ bannerId }): Promise<BannerResult>
hideBanner({ bannerId }): Promise<void>
setBannerLayout({ bannerId, position?, offsetX?, offsetY?, respectSafeArea? }): Promise<BannerResult>
destroyBanner({ bannerId }): Promise<void>
// BannerResult = { bannerId, adSize: { width, height, description?, isAdaptive? }, frame: Rect, visible }
```
Defaults: `bannerId = adUnitId`, `size = 'ADAPTIVE'`, `position = 'bottom'`, offsets 0, `respectSafeArea = true`.
Several banners can exist at once, keyed by `bannerId` (one ad unit may back several banners).
Typical flow: `createBanner` → `loadBanner` → `showBanner` (immediately, or on `bannerLoaded`) → `hideBanner` during
gameplay → `showBanner` → `destroyBanner` when leaving the screen.
### 3.2 Native mapping
| Plugin | Android (`com.unity3d.mediation.banner`) | iOS |
|---|---|---|
| view class | `LevelPlayBannerAdView extends FrameLayout`, ctor `(Context, String adUnitId, LevelPlayBannerAdView.Config)` | `LPMBannerAdView : UIView`, `initWithAdUnitId:config:` (LPMBannerAdView.h) |
| config | `LevelPlayBannerAdView.Config.Builder().setAdSize(LevelPlayAdSize).setBidFloor(double).setPlacementName(String).build()` | `LPMBannerAdViewConfigBuilder` `set(adSize:)`, `set(bidFloor:)` (NSNumber), `set(placementName:)`, `build()` |
| `BANNER` | `LevelPlayAdSize.BANNER` | `LPMAdSize.bannerSize()` |
| `LARGE` | `LevelPlayAdSize.LARGE` | `LPMAdSize.largeSize()` |
| `MEDIUM_RECTANGLE` | `LevelPlayAdSize.MEDIUM_RECTANGLE` | `LPMAdSize.mediumRectangleSize()` |
| `LEADERBOARD` | `LevelPlayAdSize.LEADERBOARD` | `LPMAdSize.leaderBoardSize()` |
| `ADAPTIVE` | `LevelPlayAdSize.createAdaptiveAdSize(Context, Integer width)` | `LPMAdSize.createAdaptiveAdSize(withWidth: CGFloat)` (nullable: `nil` before init) |
| size readout | `getWidth()`, `getHeight()`, `getDescription()`, `isAdaptive()` | `width`, `height`, `sizeDescription`, `isAdaptive` |
| listener | `setBannerListener(LevelPlayBannerAdViewListener)` | `setDelegate(LPMBannerAdViewDelegate)` |
| impression data | `setImpressionDataListener(LevelPlayImpressionDataListener)` | `setImpressionDataDelegate:` |
| load | `loadAd()` (Activity context from the ctor) | `loadAdWithViewController:` (`bridge.viewController`) |
| show / hide | `setVisibility(VISIBLE/GONE)` + `resumeAutoRefresh()` / `pauseAutoRefresh()` | `isHidden` + `resumeAutoRefresh` / `pauseAutoRefresh` |
| destroy | `destroy()` then remove from parent | `destroy` then `removeFromSuperview` |
The SDK has no show / hide API; visibility is the host view's job. Unity's docs say pause / resume only matter when a
refresh interval is set on the dashboard, and that a resumed banner completes the remaining refresh time. Android's
`IronSourceError.ERROR_BN_RELOAD_SKIP_INVISIBLE` shows the SDK itself skips refreshes of invisible banners; pausing
explicitly makes that deterministic on both platforms.
Adaptive width units: the plugin passes CSS px. On Android 1 CSS px = 1 dp in a Capacitor WebView at default zoom;
the `Integer` width is treated as dp (to be confirmed in the phase-2 test; see §14 Q3). On iOS 1 CSS px = 1 pt.
Both factories need a finished init (iOS returns `nil` before init, documented in LPMAdSize.h), so `createBanner`
rejects `NOT_INITIALIZED` before `initialize()` resolved. Unity's docs also say to create banners only after init
succeeded.
### 3.3 Banner events
| Event | Android `LevelPlayBannerAdViewListener` | iOS `LPMBannerAdViewDelegate` |
|---|---|---|
| `bannerLoaded` | `onAdLoaded(LevelPlayAdInfo)` | `didLoadAdWithAdInfo:` (required) |
| `bannerLoadFailed` | `onAdLoadFailed(LevelPlayAdError)` | `didFailToLoadAdWithAdUnitId:error:` (required) |
| `bannerDisplayed` | `onAdDisplayed` (default method) | `didDisplayAdWithAdInfo:` (optional) |
| `bannerDisplayFailed` | `onAdDisplayFailed(LevelPlayAdInfo, LevelPlayAdError)` | `didFailToDisplayAdWithAdInfo:error:` |
| `bannerClicked` | `onAdClicked` | `didClickAdWithAdInfo:` |
| `bannerExpanded` | `onAdExpanded` | `didExpandAdWithAdInfo:` |
| `bannerCollapsed` | `onAdCollapsed` | `didCollapseAdWithAdInfo:` |
| `bannerLeftApplication` | `onAdLeftApplication` | `didLeaveAppWithAdInfo:` |
Payload: `BannerEvent { bannerId, adUnitId, adInfo?, frame? }`, plus `error` for the two failure events. All eight
callbacks exist on both platforms in 9.6.1. There is **no** `adInfoChanged` callback for banners on either platform.
## 4. Native ads
### 4.1 What 9.6.1 has
- Android: `com.ironsource.mediationsdk.ads.nativead.LevelPlayNativeAd`, built with
`new LevelPlayNativeAd.Builder().withPlacementName(String).withListener(LevelPlayNativeAdListener).withActivity(Activity).build()`;
`loadAd()`, `destroyAd()`, asset getters `getTitle()`, `getAdvertiser()`, `getBody()`, `getCallToAction()`,
`getIcon()` (`NativeAdDataInterface.Image`). Views: `NativeAdLayout extends FrameLayout` with `setTitleView`,
`setAdvertiserView`, `setBodyView`, `setIconView`, `setCallToActionView`, `setMediaView(LevelPlayMediaView)`,
`registerNativeAdViews(LevelPlayNativeAd)`. Listener (`LevelPlayNativeAdListener` = `NativeAdLoadListener` +
`NativeAdInteractionListener`): `onAdLoaded(ad, AdInfo)`, `onAdLoadFailed(ad, IronSourceError)`,
`onAdImpression(ad, AdInfo)`, `onAdClicked(ad, AdInfo)`. `AdInfo` is `com.ironsource.mediationsdk.adunit.adapter.utility.AdInfo`.
- iOS: `LevelPlayNativeAd` (`initWithBuilder:`, `loadAd`, `destroyAd`, `setDelegate:`, asset properties `title`,
`advertiser`, `body`, `callToAction`, `icon` (`ISNativeAdDataImage` with `image` / `url`)), `LevelPlayNativeAdBuilder`
(`withViewController:`, `withPlacementName:`, `withDelegate:`, `build`), view `ISNativeAdView : UIView` with outlets
`adAppIcon`, `adTitleView`, `adAdvertiserView`, `adBodyView`, `adMediaView` (`LevelPlayMediaView`),
`adCallToActionView` and `registerNativeAdViews:`. Delegate `LevelPlayNativeAdDelegate` =
`ISNativeAdLoadDelegate` (`didLoad:withAdInfo:`, `didFailToLoad:withError:`) + `ISNativeAdInteractionDelegate`
(`didRecordImpression:withAdInfo:`, `didClick:withAdInfo:`), with `ISAdInfo`.
Findings that shape the API:
1. **No template views in the SDK on either platform.** There is no `LevelPlayNativeAdTemplate`, template type or
template layout resource in the AAR (its `res/` has only `values/`) or in the iOS headers. Unity's Flutter and
React Native wrappers ship their own XML (Android) and XIB (iOS) templates (`LevelPlayTemplateType.SMALL` /
`MEDIUM`). This plugin does the same: it owns two programmatic layouts per platform, `small` (no media view) and
`medium` (with `LevelPlayMediaView`). `nativeAdSupported` is therefore `true` on both platforms, with the
rendering being the plugin's code.
2. **Native ads have no ad unit id in 9.6.1.** Both builders take a placement name only. The API exposes
`placementName`, not `adUnitId`, and says so.
3. **One ad object per load.** Unity: "destroy the ad object and create a new one for every new load". So
`loadNativeAd` replaces the slot's previous ad.
4. **Native ad info is the old `AdInfo` / `ISAdInfo`** (auction id, network, instance, country, revenue, precision,
ab, segment, encrypted CPM; iOS adds `conversion_value`). No ad unit, ad id or placement in it. Hence a separate
`NativeAdInfo` type instead of reusing `AdInfo` (whose `adUnitId` is required).
5. **No per-ad impression-data listener for native ads** (only banners, interstitials and rewarded have
`setImpressionDataListener` / `setImpressionDataDelegate:`). See §5 for how `impressionData` still covers them.
6. Policy from Unity's guide: the ad must be marked as an ad, and the privacy / AdChoices icon belongs in the bottom
left. Both templates draw an "Ad" badge and leave the bottom-left corner free.
### 4.2 TS API
```ts
loadNativeAd({ nativeAdId, placementName?, template?: 'small'|'medium', style?: NativeAdTemplateStyle }): Promise<void>
showNativeAd({ nativeAdId, rect: { x, y, width, height } }): Promise<void>
setNativeAdRect({ nativeAdId, rect }): Promise<void>
hideNativeAd({ nativeAdId }): Promise<void>
destroyNativeAd({ nativeAdId }): Promise<void>
// events: nativeAdLoaded, nativeAdLoadFailed, nativeAdImpression, nativeAdClicked (NativeAdEvent / NativeAdErrorEvent)
```
`style`: `backgroundColor`, `titleColor`, `bodyColor`, `callToActionBackgroundColor`, `callToActionTextColor`
(`#RRGGBB[AA]`), `cornerRadius` (CSS px). Text uses the system font; the CTA is a native button so the SDK can
register it.
Flow: `loadNativeAd` → `nativeAdLoaded` → measure a placeholder element (`getBoundingClientRect()`) →
`showNativeAd({ rect })` → on layout change `setNativeAdRect` → `destroyNativeAd`, or `loadNativeAd` again for a new
creative.
Mapping: build → `loadAd`; on show, inflate the template into a `NativeAdLayout` / `ISNativeAdView`, fill the
asset views from the getters, call the `set*View` setters (Android) / assign the outlets (iOS) and
`registerNativeAdViews`, then place it in the overlay (§6). `destroyNativeAd` → `destroyAd()` + remove view.
## 5. Impression-level revenue: `impressionData`
### 5.1 API
`addListener('impressionData', (d: ImpressionData) => ...)`. Payload fields map 1:1 to the SDK data classes:
| `ImpressionData` | Android `LevelPlayImpressionData` | iOS `LPMImpressionData` |
|---|---|---|
| `auctionId` | `getAuctionId()` | `auctionId` |
| `adUnitId` | `getMediationAdUnitId()` | `mediationAdUnitId` |
| `adUnitName` | `getMediationAdUnitName()` | `mediationAdUnitName` |
| `adFormat` | `getAdFormat()` | `adFormat` |
| `adNetwork` | `getAdNetwork()` | `adNetwork` |
| `instanceName` | `getInstanceName()` | `instanceName` |
| `instanceId` | `getInstanceId()` | `instanceId` |
| `country` | `getCountry()` | `country` |
| `placement` | `getPlacement()` | `placement` |
| `revenue` | `getRevenue()` (`Double`, nullable) | `revenue` (`NSNumber`) |
| `precision` | `getPrecision()` | `precision` |
| `ab` | `getAb()` | `ab` |
| `segmentName` | `getSegmentName()` | `segmentName` |
| `encryptedCPM` | `getEncryptedCPM()` | `encryptedCpm` |
| `creativeId` | `getCreativeId()` | `creativeId` |
| `conversionValue` | not in the class | `conversionValue` (`NSNumber`) |
| `allData` | `getAllData()` (`JSONObject`) | `allData` (`NSDictionary`) |
**Not available: `lifetimeRevenue`.** It is not a property of either 9.6.1 class, not one of the Android
`IMPRESSION_DATA_KEY_*` constants (auctionId, adFormat, mediationAdUnitName, mediationAdUnitId, country, ab,
segmentName, placement, adNetwork, instanceName, instanceId, revenue, precision, encryptedCPM, creativeId), and the
string does not occur in the iOS binary. Apps that need lifetime revenue sum `revenue` themselves. If the server
sends it anyway it shows up in `allData`.
### 5.2 Registration
9.6.1 deprecates the global listener for publishers:
- A: `LevelPlay.addImpressionDataListener` / `removeImpressionDataListener` carry `@kotlin.Deprecated("Publishers:
use setImpressionDataListener() on each LevelPlayBannerAdView, LevelPlayInterstitialAd, or LevelPlayRewardedAd ...")`.
- I: `+[LevelPlay addImpressionDataDelegate:]` is `DEPRECATED_MSG_ATTRIBUTE` with the same advice
(`setImpressionDataDelegate:` on each `LPMBannerAdView`, `LPMInterstitialAd`, `LPMRewardedAd`).
- `addImpressionLevelRevenueListener(listener, subscriberId)` is for approved third-party SDKs only (needs a
subscriber id from Unity), not for apps.
Design (recommended, see Q1): the plugin attaches its own impression listener to **every** rewarded, interstitial
and banner object it creates (the holders already exist per ad unit). The JS side can add the listener at any time,
including before `initialize()`, because events go through `notifyListeners`; nothing can be emitted before the
first ad object exists. Native ads have no per-ad listener, so on `onAdImpression` / `didRecordImpression:` the plugin
emits an `impressionData` built from the native `AdInfo` (`adFormat: 'nativead'`, no ad unit / placement /
creative fields). This avoids deprecated APIs and still covers every format.
Events are sent with `retainUntilConsumed = false` (as today). Q2 asks whether to retain.
## 6. Overlay positioning (banners and native ads)
### 6.1 Coordinate space
All public geometry is in **CSS px relative to the WebView viewport** (the space of `getBoundingClientRect()` on a
non-scrolled page). Capacitor WebViews render at 1 CSS px = 1 dp (Android, default zoom / `initial-scale=1`) and
1 CSS px = 1 pt (iOS). Pages that change the viewport scale break this; documented as unsupported.
### 6.2 Host view
- **Android**: a plugin-owned `FrameLayout` "overlay host" added to the WebView's parent (`(ViewGroup)
bridge.getWebView().getParent()`, the Capacitor `CoordinatorLayout`) right after the WebView, so it draws above it.
It is kept equal to the WebView's bounds with an `OnLayoutChangeListener` on the WebView. The host is not clickable
and has no touch listener, so touches outside ad views fall through to the WebView below (Android dispatches to
siblings in reverse z-order until one consumes). Ad views inside it consume their own touches.
- **iOS**: a plugin-owned `UIView` subclass added to `bridge.viewController.view` above `bridge.webView`, frame and
`autoresizingMask` following the WebView. Its `hitTest(_:with:)` returns `nil` when the hit view is itself, so only
ad subviews receive touches.
- Full-screen ads (rewarded / interstitial / expanded banners / test suite) are presented as Activities / modal view
controllers and therefore always cover the overlay.
### 6.3 Safe area
`safeRect = webViewRect ∩ (window bounds − system insets)`, converted into WebView-local CSS px.
- Android: insets from `ViewCompat.getRootWindowInsets(webView)` with
`WindowInsetsCompat.Type.systemBars() | Type.displayCutout()`. Intersecting with the WebView's on-screen rect
(`getLocationInWindow`) makes this correct in every Capacitor mode: Capacitor 7 `android.adjustMarginsForEdgeToEdge`
(margins on the WebView), Capacitor 8 `SystemBars` `insetsHandling: 'native'` (padding on the WebView parent) or
`'css'` (WebView edge to edge, insets only in CSS). Insets are re-read in the host's layout pass and via
`ViewCompat.setOnApplyWindowInsetsListener` on the host (the host returns the insets unconsumed so it never steals
them from Capacitor's own listener on the WebView).
- iOS: `overlayHost.safeAreaInsets` (same frame as the WebView), updated in `safeAreaInsetsDidChange` /
`layoutSubviews`.
`respectSafeArea: false` uses the raw WebView rect. Native ad rects are taken literally (the page already laid them
out against `env(safe-area-inset-*)`), only clamped to the WebView rect.
### 6.4 Placement maths (banner)
```
x = safe.x + (safe.width − bannerWidth) / 2 + offsetX
y = top: safe.y + offsetY
bottom: safe.y + safe.height − bannerHeight + offsetY
center: safe.y + (safe.height − bannerHeight) / 2 + offsetY
```
Recomputed on every host layout pass (rotation, split screen, multi-window, keyboard resizing the WebView, foldables).
Adaptive banners keep the size they were created with; after a rotation the app may destroy and recreate them with a
new width (Q4).
### 6.5 WebView scroll and z-order
Overlays are fixed to the viewport; they do not scroll with page content. Games normally have no page scroll. For
scrolling pages the app calls `setNativeAdRect` on scroll / resize (documented). Z-order inside the host: creation
order; a later `showBanner` / `showNativeAd` brings that view to the front.
### 6.6 Lifecycle
On `handleOnDestroy` (Android) / plugin deinit the plugin destroys every banner and native ad. On app pause the SDK
manages refresh itself; the plugin does not pause banners on `handleOnPause`.
## 7. `adInfoChanged`
`addListener('adInfoChanged', (e: AdEvent) => ...)`, same payload as `loaded`. Sources: A
`LevelPlayRewardedAdListener.onAdInfoChanged` / `LevelPlayInterstitialAdListener.onAdInfoChanged` (default methods);
I `LPMRewardedAdDelegate` / `LPMInterstitialAdDelegate` `didChangeAdInfo(_:)` (optional). The 0.2.x holders already
implement these as empty bodies; phase 2 only emits. Banner listener / delegate have no such callback in 9.6.1;
native ads neither.
## 8. Placements, capping and rewards
| Plugin | Android | iOS |
|---|---|---|
| `isPlacementCapped({ format: 'rewarded', placementName })` | `LevelPlayRewardedAd.isPlacementCapped(String)` (static) | `+[LPMRewardedAd isPlacementCapped:]` |
| `isPlacementCapped({ format: 'interstitial', ... })` | `LevelPlayInterstitialAd.isPlacementCapped(String)` (static) | `+[LPMInterstitialAd isPlacementCapped:]` |
| `getReward({ adUnitId, placementName? })` | `LevelPlayRewardedAd.getReward(String)` / `getReward()` (instance) | `-[LPMRewardedAd getRewardWithPlacementName:]` (`getReward(placementName:)`) |
`getReward` uses the plugin's per-ad-unit `LevelPlayRewardedAd` holder (created on demand, as `loadRewarded` does).
iOS documents "an empty reward on failures (`name: ""` and `amount: 0`)"; the plugin returns the same shape on both
platforms and the web.
Not in 9.6.1: the 7.x/8.x `IronSource.getRewardedVideoPlacementInfo` / `Placement` class (absent from
`com.ironsource.mediationsdk.IronSource` and `IronSource.h`, which now only hold demand-only and ad-revenue APIs), and
any capping API for banners or native ads. `ShowOptions.placementName` (0.1.0) already covers show-time placements.
## 9. Segments and dynamic user id
`setSegment(options)`:
| Field | Android `com.unity3d.mediation.segment.LevelPlaySegment` | iOS `LPMSegment` |
|---|---|---|
| `segmentName` | `setSegmentName(String)` | `segmentName` |
| `level` | `setLevel(int)` | `level` (`int`) |
| `isPaying` | `setPaying(boolean)` | `paying` |
| `userCreationDate` (ms epoch) | `setUserCreationDate(long)` | `userCreationDate` (`NSDate`, `Date(timeIntervalSince1970: ms / 1000)`) |
| `iapTotal` | `setIapTotal(double)` | `iapTotal` |
| `customParameters` | `setCustom(String, String)` per pair | `setCustomValue:forKey:` per pair |
| apply | `LevelPlay.setSegment(LevelPlaySegment)` | `+[LevelPlay setSegment:]` |
Custom-parameter limits read from the Android bytecode of `setCustom`: key and value must match `^[a-zA-Z0-9]*$`
and be 1-32 characters; at most 5 pairs, the oldest is silently evicted on the 6th. The plugin validates the same
rules on both platforms and rejects `INVALID_ARGUMENT` rather than dropping data silently. (The iOS header does not state the
limits; phase 2 confirms iOS behaves the same.)
`setDynamicUserId({ userId })` → `{ valid }`: A `LevelPlay.setDynamicUserId(String): boolean`, I
`+[LevelPlay setDynamicUserId:]` returning `BOOL`. There is no `IronSource.setDynamicUserId` in 9.6.1; the LevelPlay
class is the only entry point.
## 10. Errors
Promise rejections (plugin codes, strings):
| Code | When |
|---|---|
| `INVALID_ARGUMENT` | missing / empty ids, bad size or position, bad segment custom parameters, negative rect size |
| `NOT_INITIALIZED` | `createBanner`, `loadNativeAd` before `initialize()` resolved |
| `ALREADY_EXISTS` | `createBanner` with a `bannerId` in use |
| `NOT_FOUND` | `loadBanner`, `showBanner`, `setBannerLayout`, `showNativeAd`, `setNativeAdRect`, `hideNativeAd` with an unknown id (`hideBanner`, `destroy*` resolve instead) |
| `NOT_LOADED` | `showNativeAd` before `nativeAdLoaded` |
| `UNSUPPORTED` | capability is `false`, or a template not in `nativeAdTemplates` |
| `NO_VIEW_CONTROLLER` (iOS) / `NO_ACTIVITY` (Android) | no host to attach or load into |
| `UNIMPLEMENTED` | web stubs (Capacitor's `unimplemented()`), and any 0.3.0 method on a native build of phase 1 |
Ad errors in events (`AdError { code, message }`) pass the SDK code through: A `LevelPlayAdError.getErrorCode()` /
`IronSourceError.getErrorCode()` (native), I `NSError.code`. Notable codes: 509 no fill; banner-specific Android
constants `ERROR_BN_LOAD_NO_FILL`, `ERROR_BN_UNSUPPORTED_SIZE`, `ERROR_BN_RELOAD_SKIP_INVISIBLE`; native
`ERROR_NT_LOAD_NO_FILL`, `ERROR_NT_LOAD_PLACEMENT_CAPPED`.
## 11. Web
`getCapabilities` all false; `setSegment` no-op; `setDynamicUserId` → `{ valid: false }`; `isPlacementCapped` →
`{ capped: false }`; `getReward` → `{ name: '', amount: 0 }`; `loadBanner`, `hideBanner`, `destroyBanner`,
`setNativeAdRect`, `hideNativeAd`, `destroyNativeAd` no-ops; `createBanner`, `showBanner`, `setBannerLayout`,
`loadNativeAd`, `showNativeAd` reject `unimplemented` (they would have to return a frame or show a view; same rule as
`initialize`).
## 12. Capacitor 7 compatibility (findings only; `peerDependencies` unchanged)
Plugin-facing Java and Swift API is identical between 7.6.9 and 8.5.3 for everything this plugin uses:
- Android: the public members of `Plugin`, `PluginCall`, `Bridge` and `JSObject` diff to zero.
`notifyListeners(String, JSObject, boolean)` exists in both.
- iOS: `CAPPluginCall` (`.swift`, `.h`) identical; `CAPBridgeProtocol` in 8 only adds deprecations (`presentVC` /
`dismissVC` → `bridge.viewController.present/dismiss`, which the plugin already uses); `CAPPlugin` in 8 adds
`handleWKWebViewURLAuthenticationChallenge` (not used). `CAPBridgedPlugin` exists in both.
What must change to support `>=7.0.0` (phase 2 or later, not done now):
| Item | Today (Cap 8) | Needed for Cap 7 |
|---|---|---|
| `package.json` peer | `@capacitor/core >=8.0.0` | `>=7.0.0` |
| `Package.swift` | `capacitor-swift-pm` `from: "8.0.0"` | `"7.0.0"..<"9.0.0"` (tags 7.0.0 ... 7.6.9 and 8.x exist) |
| iOS deployment target | `.iOS(.v15)`, podspec `15.0` | `.v14` / `14.0` (Cap 7 default; `Capacitor.podspec` 7 = 14.0, 8 = 15.0). LevelPlay 9.6.1 needs 12.0, so 14 is fine. SPM refuses a package whose platform is higher than the app target. |
| Android `minSdkVersion` default | 24 | 23 (Cap 7 default; LevelPlay AAR needs 19). Only the fallback; apps override from `variables.gradle`. |
| Android `compileSdk` / `targetSdk` defaults | 36 | 35 in Cap 7 projects; overridden by the app, so no code change. |
| AGP in plugin `buildscript` | `8.13.0` | Cap 7 apps use AGP 8.7.2. The plugin's `buildscript` classpath is only used by the standalone `verify:android` build, but a mismatched AGP in a subproject `buildscript` can trigger "multiple AGP versions"; phase 2 tests it in a Cap 7 app and, if needed, drops the plugin's `buildscript` classpath or keys it off `rootProject`. |
| Java | 21 | 21 (same). |
| Node / CLI | engines `>=22` | Cap 7 CLI runs on Node 20+; `engines` is advisory, can stay. |
| SPM | default in Cap 8 projects | supported in Cap 7 (CapApp-SPM since Cap 6); CocoaPods podspec unchanged. |
| LevelPlay SPM package | swift-tools 6.0 | needs Xcode 16+, which Cap 7 already requires. |
Behavioural difference that matters for overlays: edge-to-edge handling. Cap 7 uses
`android.adjustMarginsForEdgeToEdge` (`CapConfig`, margins on `CapacitorWebView`; removed in 8). Cap 8 uses the core
`SystemBars` plugin (`insetsHandling: 'css' | 'native' | 'disable'`, padding on the WebView's parent or CSS
variables). The overlay design (§6.3) measures the WebView's real on-screen rect and intersects with window insets, so
it is correct under every combination without reading either config.
## 13. Test plan
Automated (CI-able):
- `bun run typecheck`, `bun run build` (docgen + rollup), `verify:ios`, `verify:android` on every change.
- Android unit tests (JUnit, no device): pure helpers for placement maths (§6.4), safe-rect intersection, size
preset parsing, segment validation, `ImpressionData` → `JSObject` mapping (constructed from a JSON fixture with
`new LevelPlayImpressionData(JSONObject)`).
- iOS: same helpers as plain Swift functions with XCTest (`swift test` cannot link the binary SDK on macOS; keep the
helpers SDK-free).
Manual on devices (Unity demo app keys from `LEVELPLAY_DEMO` + test suite), Android 8 / 14 / 15 (edge to edge) and
iOS 15 / 18 / 26, phone and tablet, portrait and landscape:
1. Banner: every preset + adaptive; top / bottom / center with offsets; frame in `BannerResult` matches
`document.elementFromPoint` checks; notch and home indicator respected; rotate while shown; hide during gameplay
(no `bannerDisplayed` while hidden, refresh paused); two banners at once; destroy and recreate; click → `bannerClicked`
and `bannerLeftApplication`; expanded creative → `bannerExpanded` / `bannerCollapsed`.
2. Touch passthrough: game input works everywhere outside ad views, ads clickable inside; with keyboard open.
3. Native: small and medium templates at several rects; "Ad" badge and AdChoices corner; impression only once visible;
`setNativeAdRect` while shown; reload replaces the creative; destroy on screen change; no leaks across 50 loads
(Android Studio profiler / Instruments).
4. `impressionData` for rewarded, interstitial, banner, native; listener added before `initialize`; values match
`adInfo.revenue`; `conversionValue` present on iOS only.
5. `adInfoChanged` fires (needs a network that reloads; verify with test suite or logs).
6. `isPlacementCapped` with a dashboard placement capped to 1 per session; `getReward` per placement vs ad unit.
7. `setSegment` before init, segment name appears in `adInfo.segmentName` / `impressionData.segmentName`; invalid
custom parameters reject.
8. `setDynamicUserId` value reaches the S2S callback URL.
9. Backwards compatibility: the 0.2.1 README quick start and CUT BLAST's integration run unchanged.
10. Capacitor 7: a fresh Cap 7 app (SPM and CocoaPods; Android with `adjustMarginsForEdgeToEdge: 'auto'`) after the
§12 changes.
## 14. Open questions for the owner
- **Q1 Impression data source.** Recommended: per-ad listeners (non-deprecated) + native impressions synthesised from
native `AdInfo`. Alternative: the deprecated global `LevelPlay.addImpressionDataListener` /
`addImpressionDataDelegate:` (one registration, true SDK impression data for native too, but deprecated and may
vanish in 9.x/10). Both at once would duplicate events.
- **Q2 Retain impressions?** Send `impressionData` with `retainUntilConsumed = true` so impressions fired before a
listener exists are queued? Risk: unbounded queue if the app never listens. Default proposed: no.
- **Q3 Android adaptive width unit.** `LevelPlayAdSize.createAdaptiveAdSize(Context, Integer)` does not document the
unit; plan treats it as dp and verifies on device.
- **Q4 Adaptive banners and rotation.** Auto-recreate adaptive banners on width change (simpler for apps, costs a
reload) or leave it to the app (proposed)?
- **Q5 Custom banner sizes.** Both SDKs have custom sizes (`LevelPlayAdSize.createCustomSize`,
`LPMAdSize.customSizeWithWidth:height:`); left out of 0.3.0 because few networks fill them. Add?
- **Q6 Native template styling depth.** Colours + corner radius only (proposed), or fonts / sizes too?
- **Q7 Capacitor 7.** Ship the §12 changes in 0.3.0 or a later 0.3.x after a Cap 7 app test?

File diff suppressed because it is too large Load diff

View file

@ -2,12 +2,27 @@ import { WebPlugin } from '@capacitor/core';
import type { import type {
AdUnitOptions, AdUnitOptions,
BannerIdOptions,
BannerResult,
Capabilities,
ConsentOptions, ConsentOptions,
CreateBannerOptions,
DynamicUserIdOptions,
DynamicUserIdResult,
GetRewardOptions,
InitOptions, InitOptions,
InitResult, InitResult,
IsReadyResult, IsReadyResult,
LevelPlayPlugin, LevelPlayPlugin,
LoadNativeAdOptions,
MetaDataOptions, MetaDataOptions,
NativeAdIdOptions,
NativeAdRectOptions,
PlacementCappedOptions,
PlacementCappedResult,
Reward,
SegmentOptions,
SetBannerLayoutOptions,
ShowResult, ShowResult,
TrackingResult, TrackingResult,
} from './definitions'; } from './definitions';
@ -15,6 +30,10 @@ import type {
/** /**
* Web stub. LevelPlay has no web SDK: init rejects with `unimplemented`, ads are never ready and every show resolves * Web stub. LevelPlay has no web SDK: init rejects with `unimplemented`, ads are never ready and every show resolves
* as "not shown" so callers can treat the web like a no-fill platform without special casing. * as "not shown" so callers can treat the web like a no-fill platform without special casing.
*
* 0.3.0: `getCapabilities()` reports nothing supported. Setters, loads of things that cannot exist, hide and destroy
* are no-ops; calls that would have to return a native view (`createBanner`, `showBanner`, `setBannerLayout`,
* `loadNativeAd`, `showNativeAd`) reject as unimplemented, like `initialize`.
*/ */
export class LevelPlayWeb extends WebPlugin implements LevelPlayPlugin { export class LevelPlayWeb extends WebPlugin implements LevelPlayPlugin {
private static readonly NO_FILL: ShowResult = { private static readonly NO_FILL: ShowResult = {
@ -74,4 +93,68 @@ export class LevelPlayWeb extends WebPlugin implements LevelPlayPlugin {
async validateIntegration(): Promise<void> { async validateIntegration(): Promise<void> {
/* nothing to validate */ /* nothing to validate */
} }
async getCapabilities(): Promise<Capabilities> {
return { banner: false, nativeAd: false, nativeAdTemplates: [], impressionData: false, adInfoChanged: false };
}
async setSegment(_options: SegmentOptions): Promise<void> {
/* nothing to forward */
}
async setDynamicUserId(_options: DynamicUserIdOptions): Promise<DynamicUserIdResult> {
return { valid: false };
}
async isPlacementCapped(_options: PlacementCappedOptions): Promise<PlacementCappedResult> {
return { capped: false };
}
async getReward(_options: GetRewardOptions): Promise<Reward> {
return { name: '', amount: 0 };
}
async createBanner(_options: CreateBannerOptions): Promise<BannerResult> {
throw this.unimplemented('LevelPlay banners are not available on the web.');
}
async loadBanner(_options: BannerIdOptions): Promise<void> {
/* never fills */
}
async showBanner(_options: BannerIdOptions): Promise<BannerResult> {
throw this.unimplemented('LevelPlay banners are not available on the web.');
}
async hideBanner(_options: BannerIdOptions): Promise<void> {
/* nothing shown */
}
async setBannerLayout(_options: SetBannerLayoutOptions): Promise<BannerResult> {
throw this.unimplemented('LevelPlay banners are not available on the web.');
}
async destroyBanner(_options: BannerIdOptions): Promise<void> {
/* nothing to destroy */
}
async loadNativeAd(_options: LoadNativeAdOptions): Promise<void> {
throw this.unimplemented('LevelPlay native ads are not available on the web.');
}
async showNativeAd(_options: NativeAdRectOptions): Promise<void> {
throw this.unimplemented('LevelPlay native ads are not available on the web.');
}
async setNativeAdRect(_options: NativeAdRectOptions): Promise<void> {
/* nothing shown */
}
async hideNativeAd(_options: NativeAdIdOptions): Promise<void> {
/* nothing shown */
}
async destroyNativeAd(_options: NativeAdIdOptions): Promise<void> {
/* nothing to destroy */
}
} }