@@ -93,47 +93,48 @@ Read more about Apple's ATT and user privacy guideline [here](https://developer.
93
93
94
94
### Implement Listeners
95
95
96
- #### LevelPlayRewardedVideoListener
96
+ #### LevelPlayRewardedAdListener
97
97
``` dart
98
- class LevelPlayRewardedVideoListenerClass with LevelPlayRewardedVideoListener {
98
+ class LevelPlayRewardedAdVideoListenerClass with LevelPlayRewardedVideoListener {
99
99
@override
100
- void onAdAvailable(IronSourceAdInfo? adInfo) {
101
- // Indicates that there's an available ad.
100
+ void onAdLoaded(LevelPlayAdInfo adInfo) {
101
+ // Provided when the ad is successfully loaded
102
102
}
103
103
104
104
@override
105
- void onAdUnavailable( ) {
106
- // Indicates that no ads are available to be displayed
105
+ void onAdLoadFailed(LevelPlayAdError error ) {
106
+ // Provided when the ad fails to load. Ad Unit information is included
107
107
}
108
108
109
109
@override
110
- void onAdOpened(IronSourceAdInfo? adInfo) {
111
- // The Rewarded Video ad view has opened. Your activity will loose focus
110
+ void onAdDisplayed(LevelPlayAdInfo adInfo) {
111
+ // Provided when the ad is displayed. This is equivalent to an impression
112
112
}
113
-
113
+
114
114
@override
115
- void onAdClosed(IronSourceAdInfo? adInfo) {
116
- // The Rewarded Video ad view is about to be closed. Your activity will regain its focus
115
+ void onAdDisplayFailed(LevelPlayAdError error, LevelPlayAdInfo adInfo) {
116
+ // Provided when the ad fails to be displayed
117
117
}
118
118
119
+ @override
120
+ void onAdClicked(LevelPlayAdInfo adInfo) {
121
+ // Provided when the user clicks on the ad
122
+ }
119
123
120
124
@override
121
- void onAdRewarded(IronSourceRewardedVideoPlacement? placement, IronSourceAdInfo? adInfo) {
122
- // The user completed to watch the video, and should be rewarded.
123
- // The placement parameter will include the reward data.
124
- // When using server-to-server callbacks, you may ignore this event and wait for the ironSource server callback
125
+ void onAdClosed(LevelPlayAdInfo adInfo) {
126
+ // Provided when the ad is closed
125
127
}
126
128
127
129
@override
128
- void onAdShowFailed(IronSourceError? error, IronSourceAdInfo? adInfo) {
129
- // The rewarded video ad was failed to show
130
+ void onAdInfoChanged(LevelPlayAdInfo adInfo) {
131
+ // Provided when the ad info is updated. Available when another ad has loaded, and includes a higher CPM/Rate
130
132
}
131
133
132
134
@override
133
- void onAdClicked(IronSourceRewardedVideoPlacement? placement, IronSourceAdInfo? adInfo) {
134
- // Invoked when the video ad was clicked.
135
- // This callback is not supported by all networks, and we recommend using it
136
- // only if it's supported by all networks you included in your build
135
+ void onAdRewarded(LevelPlayReward reward, LevelPlayAdInfo adInfo) {
136
+ // The user completed to watch the video, and should be rewarded.
137
+ // The reward parameter will include the reward data.
137
138
}
138
139
}
139
140
```
@@ -253,9 +254,13 @@ class LevelPlayNativeAdListenerClass with LevelPlayNativeAdListener {
253
254
``` dart
254
255
Future<void> init() async {
255
256
final appKey = '[YOUR_APP_KEY]';
257
+ final userId = '[YOUR_USER_ID]';
256
258
try {
257
259
List<AdFormat> legacyAdFormats = [AdFormat.BANNER, AdFormat.REWARDED, AdFormat.INTERSTITIAL, AdFormat.NATIVE_AD];
258
- final initRequest = LevelPlayInitRequest(appKey: appKey, legacyAdFormats: legacyAdFormats);
260
+ final initRequest = LevelPlayInitRequest.builder(configState.appKey)
261
+ .withLegacyAdFormats(legacyAdFormats)
262
+ .withUserId(userId)
263
+ .build();
259
264
await LevelPlay.init(initRequest: initRequest, initListener: this);
260
265
} on PlatformException catch (e) {
261
266
print(e);
@@ -267,118 +272,110 @@ Future<void> init() async {
267
272
268
273
#### LevelPlayRewardedVideo
269
274
``` dart
270
- Future<void> _showRewardedVideoOnClick() async {
271
- if (await IronSource.isRewardedVideoAvailable()) {
272
- IronSource.showRewardedVideo();
275
+ final LevelPlayRewardedAd _rewardedAd = LevelPlayRewardedAd(adUnitId: [YOUR_AD_UNIT]);
276
+
277
+ @override
278
+ void initState() {
279
+ super.initState();
280
+ _rewardedAd.setListener([YOUR_LISTENER]);
281
+ }
282
+
283
+ void _loadRewarded() {
284
+ _rewardedAd.loadAd();
285
+ }
286
+
287
+ Future<void> _showRewarded() async {
288
+ if (await _rewardedAd.isAdReady()) {
289
+ _rewardedAd.showAd(placement: [YOUR_PLACEMENT]);
273
290
}
274
291
}
292
+
293
+ // Rest of the class
275
294
```
276
295
277
296
#### LevelPlayInterstitial
278
297
279
298
``` dart
280
- LevelPlayInterstitialAd? _interstitialAd;
299
+ final LevelPlayInterstitialAd _interstitialAd = LevelPlayInterstitialAd(adUnitId: [YOUR_AD_UNIT]) ;
281
300
282
301
@override
283
302
void initState() {
284
303
super.initState();
285
- _createInterstitialAd();
286
- }
287
-
288
- void _createInterstitialAd() {
289
- _intersitialAd = LevelPlayInterstitialAd(adUnitId: [YOUR_AD_UNIT]);
290
- _interstitialAd!.setListener([YOUR_LISTENER]);
304
+ _interstitialAd.setListener([YOUR_LISTENER]);
291
305
}
292
306
293
307
void _loadInterstitial() {
294
- _interstitialAd? .loadAd();
308
+ _interstitialAd.loadAd();
295
309
}
296
310
297
311
Future<void> _showInterstitial() async {
298
- if (await __interstitialAd? .isAdReady()) {
299
- _interstitialAd? .showAd(placement: [YOUR_PLACEMENT]);
312
+ if (await _interstitialAd .isAdReady()) {
313
+ _interstitialAd.showAd(placement: [YOUR_PLACEMENT]);
300
314
}
301
315
}
316
+
317
+ // Rest of the class
302
318
```
303
319
304
320
#### LevelPlayBanner
305
321
306
322
``` dart
307
- LevelPlayBannerAdView? _bannerAdView;
308
-
309
- @override
310
- void initState() {
311
- super.initState();
312
- _createBannerAdView();
323
+ final _bannerKey = GlobalKey<LevelPlayBannerAdViewState>();
324
+ final _adSize = LevelPlayAdSize.BANNER;
325
+ final _adUnitId = 'YOUR_AD_UNIT_ID';
326
+ final _placementName = 'YOUR_PLACEMENT';
327
+
328
+ void _loadAd() {
329
+ _bannerKey.currentState?.loadAd();
330
+ // or store LevelPlayBannerAdView in variable and call '_bannerAdView.loadAd();'
313
331
}
314
332
315
- void _createBannerAdView() {
316
- final _bannerkey = GlobalKey<LevelPlayBannerAdViewState>();
317
- _bannerAdView = LevelPlayBannerAdView(
333
+ @override
334
+ Widget build(BuildContext context) {
335
+ return
336
+ LevelPlayBannerAdView(
318
337
key: _bannerKey,
319
- adUnitId: [YOUR_AD_UNIT_ID],
320
- adSize:[YOUR_AD_SIZE],
321
- listener: [YOUR_LISTENER],
322
- placementName: [YOUR_PLACEMENT],
323
- onPlatformViewCreated: _loadBanner
324
- );
325
- }
326
-
327
- void _loadBanner() {
328
- _bannerAdView?.loadAd();
329
- // or store and use key - _bannerKey.currentState?.loadAd();
338
+ adUnitId: _adUnitId,
339
+ adSize: _adSize,
340
+ listener: this,
341
+ placementName: _placementName,
342
+ onPlatformViewCreated: () {
343
+ _loadAd();
344
+ },
345
+ );
330
346
}
331
347
```
332
348
333
349
#### LevelPlayNativeAd
334
350
``` dart
335
- class _LevelPlayNativeAdsSection extends State<LevelPlayNativeAdsSection> with LevelPlayNativeAdListener {
336
- LevelPlayNativeAd? _nativeAd;
337
- LevelPlayNativeAdView? _nativeAdView;
351
+ LevelPlayNativeAd? _nativeAd;
338
352
339
- @override
340
- void initState() {
341
- super.initState();
342
- _createNativeAd();
343
- _createNativeAdView();
344
- }
353
+ @override
354
+ void initState() {
355
+ super.initState();
356
+ _nativeAd = LevelPlayNativeAd.builder()
357
+ .withPlacementName(_placementName)
358
+ .withListener(this)
359
+ .build();
360
+ }
345
361
346
- /// Initialize native ad object
347
- void _createNativeAd() {
348
- _nativeAd = LevelPlayNativeAd.builder()
349
- .withPlacementName('YOUR_PLACEMENT_NAME') // Your placement name string
350
- .withListener(LevelPlayNativeAdListenerClass()) // Your level play native ad listener
351
- .build();
352
- }
362
+ /// Load native ad
363
+ void _loadAd() {
364
+ _nativeAd?.loadAd();
365
+ }
353
366
354
- /// Initialize native ad view widget with native ad
355
- void _createNativeAdView() {
356
- _nativeAdView = LevelPlayNativeAdView(
357
- key: GlobalKey(),
358
- // Unique key to force recreation of widget
359
- height: 150,
360
- // Your chosen height
361
- width: double.infinity,
362
- // Your chosen width
367
+ @override
368
+ Widget build(BuildContext context) {
369
+ return
370
+ LevelPlayNativeAdView(
371
+ height: _height,
372
+ width: _width,
363
373
nativeAd: _nativeAd,
364
- // Native ad object
365
- templateType: LevelPlayTemplateType.SMALL,
366
- // Built-in native ad template(not required when implementing custom template)
367
- templateStyle: LevelPlayNativeAdTemplateStyle( // Level play native ad styling(optional)
368
- callToActionStyle: LevelPlayNativeAdElementStyle(
369
- backgroundColor: Colors.white,
370
- textColor: Colors.lightBlue
371
- )
372
- ),
374
+ templateType: _templateType,
375
+ onPlatformViewCreated: () {
376
+ _loadAd();
377
+ },
373
378
);
374
- }
375
-
376
- /// Load native ad
377
- void _loadAd() {
378
- _nativeAd?.loadAd();
379
- }
380
-
381
- // Rest of the class
382
379
}
383
380
```
384
381
@@ -389,8 +386,8 @@ Note:
389
386
- Make sure to read the official documents at [ ironSource Knowledge Center] (TODO: replace with the real KC link) for proper usage.
390
387
- Some configurations must be done before initialization.
391
388
- LevelPlayBannerListener is deprecated - Please use LevelPlayBannerAdViewListener with LevelPlayBannerAdView instead.
392
-
393
-
389
+ - LevelPlayInterstitialListener is deprecated - Please use LevelPlayInterstitialAdListener with LevelPlayInterstitialAd instead.
390
+ -
394
391
# Mediation
395
392
396
393
- You can use the ironSource LevelPlay's mediation feature by adding adapters/SDKs to your project.
0 commit comments