@ad-execute-manager/ad 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +379 -379
- package/dist/index.cjs +1 -2
- package/dist/index.d.ts +2 -4
- package/dist/index.js +1 -2
- package/package.json +7 -3
- package/dist/InterstitialAdFather.d.ts +0 -163
- package/dist/InterstitialAdNovel.d.ts +0 -461
- package/dist/RewardAdFather.d.ts +0 -181
- package/dist/RewardAdNovel.d.ts +0 -553
- package/dist/const/const.d.ts +0 -20
- package/dist/typings/ad.d.ts +0 -208
- package/dist/typings/common.d.ts +0 -14
- package/dist/typings/create-interstitial-ad.d.ts +0 -42
- package/dist/typings/create-rewarded-video-ad.d.ts +0 -42
- package/dist/typings/tracker.d.ts +0 -1
- package/dist/utils/functional.d.ts +0 -13
package/README.md
CHANGED
|
@@ -1,380 +1,380 @@
|
|
|
1
|
-
# @ad-execute-manager/ad
|
|
2
|
-
|
|
3
|
-
Ad-related classes including InterstitialAdFather, InterstitialAdNovel, RewardAdFather, and RewardAdNovel for ad management.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @ad-execute-manager/ad
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Features
|
|
12
|
-
|
|
13
|
-
- **InterstitialAdFather**: Base class for interstitial ads with common functionality
|
|
14
|
-
- **InterstitialAdNovel**: Novel-specific interstitial ad implementation with enhanced features
|
|
15
|
-
- **RewardAdFather**: Base class for reward ads with common functionality
|
|
16
|
-
- **RewardAdNovel**: Novel-specific reward ad implementation with enhanced features
|
|
17
|
-
|
|
18
|
-
## Usage
|
|
19
|
-
|
|
20
|
-
### InterstitialAdNovel
|
|
21
|
-
|
|
22
|
-
```javascript
|
|
23
|
-
import { InterstitialAdNovel } from '@ad-execute-manager/ad';
|
|
24
|
-
|
|
25
|
-
const interstitialAd = InterstitialAdNovel.new({
|
|
26
|
-
sign: 'novel_interstitial',
|
|
27
|
-
preserveOnEnd: false,
|
|
28
|
-
needEndOnTimeout: true,
|
|
29
|
-
collection: {
|
|
30
|
-
onHalfway: (args) => {
|
|
31
|
-
console.log('Ad halfway:', args);
|
|
32
|
-
},
|
|
33
|
-
onShow: (args) => {
|
|
34
|
-
console.log('Ad shown:', args);
|
|
35
|
-
},
|
|
36
|
-
onFinish: (args) => {
|
|
37
|
-
console.log('Ad finished:', args);
|
|
38
|
-
},
|
|
39
|
-
onAlways: (args) => {
|
|
40
|
-
console.log('Ad always:', args);
|
|
41
|
-
},
|
|
42
|
-
onError: (error) => {
|
|
43
|
-
console.error('Ad error:', error);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
// Initialize ad
|
|
49
|
-
interstitialAd.initialize({
|
|
50
|
-
adUnitId: 'your-ad-unit-id',
|
|
51
|
-
retry: 3
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// Show ad
|
|
55
|
-
const result = await interstitialAd.addExecuteManager({
|
|
56
|
-
options: {
|
|
57
|
-
scene: 1
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
console.log('Ad result:', result);
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### RewardAdNovel
|
|
65
|
-
|
|
66
|
-
```javascript
|
|
67
|
-
import { RewardAdNovel } from '@ad-execute-manager/ad';
|
|
68
|
-
|
|
69
|
-
const rewardAd = RewardAdNovel.new({
|
|
70
|
-
sign: 'novel_reward',
|
|
71
|
-
preserveOnEnd: false,
|
|
72
|
-
needEndOnTimeout: true,
|
|
73
|
-
collection: {
|
|
74
|
-
onHalfway: (args) => {
|
|
75
|
-
console.log('Ad halfway:', args);
|
|
76
|
-
},
|
|
77
|
-
onShow: (args) => {
|
|
78
|
-
console.log('Ad shown:', args);
|
|
79
|
-
},
|
|
80
|
-
onFinish: (args) => {
|
|
81
|
-
console.log('Ad finished:', args);
|
|
82
|
-
},
|
|
83
|
-
onAlways: (args) => {
|
|
84
|
-
console.log('Ad always:', args);
|
|
85
|
-
},
|
|
86
|
-
onError: (error) => {
|
|
87
|
-
console.error('Ad error:', error);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
// Initialize ad
|
|
93
|
-
rewardAd.initialize({
|
|
94
|
-
adUnitId: 'your-ad-unit-id',
|
|
95
|
-
retry: 3
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
// Show ad
|
|
99
|
-
const result = await rewardAd.addExecuteManager({
|
|
100
|
-
options: {
|
|
101
|
-
scene: 2,
|
|
102
|
-
timeout: 10000
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
console.log('Ad result:', result);
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
## API
|
|
110
|
-
|
|
111
|
-
### InterstitialAdFather
|
|
112
|
-
|
|
113
|
-
Base class for interstitial ads with common functionality.
|
|
114
|
-
|
|
115
|
-
### InterstitialAdNovel
|
|
116
|
-
|
|
117
|
-
```typescript
|
|
118
|
-
class InterstitialAdNovel extends InterstitialAdFather {
|
|
119
|
-
/**
|
|
120
|
-
* Builds and returns an instance of InterstitialAdNovel
|
|
121
|
-
* @param args Construction arguments
|
|
122
|
-
* @returns Instance of InterstitialAdNovel
|
|
123
|
-
*/
|
|
124
|
-
static build(args: IConstructArgs): InterstitialAdNovel;
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Gets the singleton instance of InterstitialAdNovel
|
|
128
|
-
* @returns Singleton instance of InterstitialAdNovel
|
|
129
|
-
*/
|
|
130
|
-
static getInstance(): InterstitialAdNovel;
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Creates a new instance of InterstitialAdNovel
|
|
134
|
-
* @param args Construction arguments
|
|
135
|
-
* @returns New instance of InterstitialAdNovel
|
|
136
|
-
*/
|
|
137
|
-
static new(args: IConstructArgs): InterstitialAdNovel;
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Initializes the ad with configuration
|
|
141
|
-
* @param params Ad configuration parameters
|
|
142
|
-
* @param callback Optional callback function
|
|
143
|
-
* @returns Current instance for method chaining
|
|
144
|
-
*/
|
|
145
|
-
initialize(params: IRewordAdConfig, callback?: (v: IRewardedVideoAd) => void): this;
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Adds execute manager and runs the ad
|
|
149
|
-
* @param ctx Context object with options
|
|
150
|
-
* @returns Promise with ad execution result
|
|
151
|
-
*/
|
|
152
|
-
addExecuteManager(ctx: any): Promise<any>;
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Clears the ad instance
|
|
156
|
-
*/
|
|
157
|
-
clear(): void;
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Shifts the ad instance
|
|
161
|
-
*/
|
|
162
|
-
shift(): void;
|
|
163
|
-
}
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
### RewardAdFather
|
|
167
|
-
|
|
168
|
-
Base class for reward ads with common functionality.
|
|
169
|
-
|
|
170
|
-
### RewardAdNovel
|
|
171
|
-
|
|
172
|
-
```typescript
|
|
173
|
-
class RewardAdNovel extends RewardAdFather {
|
|
174
|
-
/**
|
|
175
|
-
* Builds and returns an instance of RewardAdNovel
|
|
176
|
-
* @param args Construction arguments
|
|
177
|
-
* @returns Instance of RewardAdNovel
|
|
178
|
-
*/
|
|
179
|
-
static build(args: IConstructArgs): RewardAdNovel;
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Gets the singleton instance of RewardAdNovel
|
|
183
|
-
* @returns Singleton instance of RewardAdNovel
|
|
184
|
-
*/
|
|
185
|
-
static getInstance(): RewardAdNovel;
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Creates a new instance of RewardAdNovel
|
|
189
|
-
* @param args Construction arguments
|
|
190
|
-
* @returns New instance of RewardAdNovel
|
|
191
|
-
*/
|
|
192
|
-
static new(args: IConstructArgs): RewardAdNovel;
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Initializes the ad with configuration
|
|
196
|
-
* @param params Ad configuration parameters
|
|
197
|
-
* @param callback Optional callback function
|
|
198
|
-
* @returns Current instance for method chaining
|
|
199
|
-
*/
|
|
200
|
-
initialize(params: IRewordAdConfig, callback?: (v: IRewardedVideoAd) => void): this;
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Adds execute manager and runs the ad
|
|
204
|
-
* @param ctx Context object with options
|
|
205
|
-
* @returns Promise with ad execution result
|
|
206
|
-
*/
|
|
207
|
-
addExecuteManager(ctx: any): Promise<any>;
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Clears the ad instance
|
|
211
|
-
*/
|
|
212
|
-
clear(): void;
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Shifts the ad instance
|
|
216
|
-
*/
|
|
217
|
-
shift(): void;
|
|
218
|
-
}
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
## Configuration
|
|
222
|
-
|
|
223
|
-
### Construction Arguments
|
|
224
|
-
|
|
225
|
-
When creating an ad instance, you can pass the following configuration options:
|
|
226
|
-
|
|
227
|
-
- **sign**: Unique identifier for the ad instance
|
|
228
|
-
- **preserveOnEnd**: Whether to preserve the instance after ad ends
|
|
229
|
-
- **needEndOnTimeout**: Whether to end the ad on timeout
|
|
230
|
-
- **collection**: Event collection object with callback functions
|
|
231
|
-
- **onHalfway**: Called when ad reaches halfway point
|
|
232
|
-
- **onShow**: Called when ad is shown
|
|
233
|
-
- **onFinish**: Called when ad finishes
|
|
234
|
-
- **onAlways**: Called always after ad operation
|
|
235
|
-
- **onError**: Called when ad encounters error
|
|
236
|
-
|
|
237
|
-
### Initialize Parameters
|
|
238
|
-
|
|
239
|
-
When initializing an ad, you can pass the following parameters:
|
|
240
|
-
|
|
241
|
-
- **adUnitId**: Unique identifier for the ad unit
|
|
242
|
-
- **retry**: Number of retry attempts on ad error
|
|
243
|
-
|
|
244
|
-
## Examples
|
|
245
|
-
|
|
246
|
-
### Example 1: Basic Interstitial Ad Usage
|
|
247
|
-
|
|
248
|
-
```javascript
|
|
249
|
-
import { InterstitialAdNovel } from '@ad-execute-manager/ad';
|
|
250
|
-
|
|
251
|
-
// Create ad instance
|
|
252
|
-
const interstitialAd = InterstitialAdNovel.new({
|
|
253
|
-
sign: 'chapter_end_interstitial',
|
|
254
|
-
preserveOnEnd: false,
|
|
255
|
-
needEndOnTimeout: true,
|
|
256
|
-
collection: {
|
|
257
|
-
onFinish: () => {
|
|
258
|
-
console.log('Interstitial ad finished, proceeding to next chapter');
|
|
259
|
-
// Proceed to next chapter logic here
|
|
260
|
-
},
|
|
261
|
-
onError: (error) => {
|
|
262
|
-
console.error('Interstitial ad error:', error);
|
|
263
|
-
// Handle error gracefully, maybe skip ad
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
// Initialize and show ad
|
|
269
|
-
interstitialAd.initialize({ adUnitId: 'ca-app-pub-xxx/xxx', retry: 2 });
|
|
270
|
-
|
|
271
|
-
// Show ad at chapter end
|
|
272
|
-
async function showAdAtChapterEnd() {
|
|
273
|
-
try {
|
|
274
|
-
const result = await interstitialAd.addExecuteManager({ options: { scene: 1 } });
|
|
275
|
-
console.log('Ad result:', result);
|
|
276
|
-
} catch (error) {
|
|
277
|
-
console.error('Ad execution error:', error);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// Usage
|
|
282
|
-
// showAdAtChapterEnd();
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
### Example 2: Reward Ad for Premium Content
|
|
286
|
-
|
|
287
|
-
```javascript
|
|
288
|
-
import { RewardAdNovel } from '@ad-execute-manager/ad';
|
|
289
|
-
|
|
290
|
-
// Create reward ad instance
|
|
291
|
-
const rewardAd = RewardAdNovel.new({
|
|
292
|
-
sign: 'premium_content_reward',
|
|
293
|
-
preserveOnEnd: true,
|
|
294
|
-
needEndOnTimeout: true,
|
|
295
|
-
collection: {
|
|
296
|
-
onFinish: (args) => {
|
|
297
|
-
console.log('Reward ad finished, unlocking premium content');
|
|
298
|
-
// Unlock premium content logic here
|
|
299
|
-
unlockPremiumContent();
|
|
300
|
-
},
|
|
301
|
-
onError: (error) => {
|
|
302
|
-
console.error('Reward ad error:', error);
|
|
303
|
-
// Show error message to user
|
|
304
|
-
showErrorMessage('Failed to load ad. Please try again later.');
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
// Initialize ad
|
|
310
|
-
rewardAd.initialize({ adUnitId: 'ca-app-pub-xxx/xxx', retry: 3 });
|
|
311
|
-
|
|
312
|
-
// Function to unlock premium content
|
|
313
|
-
function unlockPremiumContent() {
|
|
314
|
-
// Logic to unlock premium content
|
|
315
|
-
console.log('Premium content unlocked!');
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
// Function to show error message
|
|
319
|
-
function showErrorMessage(message) {
|
|
320
|
-
// Logic to show error message
|
|
321
|
-
console.log('Error:', message);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
// Show reward ad to unlock premium content
|
|
325
|
-
async function showRewardAdForPremium() {
|
|
326
|
-
try {
|
|
327
|
-
const result = await rewardAd.addExecuteManager({
|
|
328
|
-
options: {
|
|
329
|
-
scene: 2,
|
|
330
|
-
timeout: 15000
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
console.log('Reward ad result:', result);
|
|
334
|
-
} catch (error) {
|
|
335
|
-
console.error('Reward ad execution error:', error);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
// Usage
|
|
340
|
-
// showRewardAdForPremium();
|
|
341
|
-
```
|
|
342
|
-
|
|
343
|
-
### Example 3: Ad Instance Management
|
|
344
|
-
|
|
345
|
-
```javascript
|
|
346
|
-
import { InterstitialAdNovel, RewardAdNovel } from '@ad-execute-manager/ad';
|
|
347
|
-
|
|
348
|
-
// Create ad instances
|
|
349
|
-
const interstitialAd = InterstitialAdNovel.new({ sign: 'interstitial' });
|
|
350
|
-
const rewardAd = RewardAdNovel.new({ sign: 'reward' });
|
|
351
|
-
|
|
352
|
-
// Initialize ads
|
|
353
|
-
interstitialAd.initialize({ adUnitId: 'ca-app-pub-xxx/xxx', retry: 2 });
|
|
354
|
-
rewardAd.initialize({ adUnitId: 'ca-app-pub-xxx/xxx', retry: 3 });
|
|
355
|
-
|
|
356
|
-
// Function to show appropriate ad based on user action
|
|
357
|
-
async function showAdBasedOnAction(action) {
|
|
358
|
-
try {
|
|
359
|
-
switch (action) {
|
|
360
|
-
case 'chapter_end':
|
|
361
|
-
return await interstitialAd.addExecuteManager({ options: { scene: 1 } });
|
|
362
|
-
case 'unlock_premium':
|
|
363
|
-
return await rewardAd.addExecuteManager({ options: { scene: 2 } });
|
|
364
|
-
default:
|
|
365
|
-
throw new Error('Invalid ad action');
|
|
366
|
-
}
|
|
367
|
-
} catch (error) {
|
|
368
|
-
console.error('Ad error:', error);
|
|
369
|
-
return { success: false, error: error.message };
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// Usage examples
|
|
374
|
-
// showAdBasedOnAction('chapter_end');
|
|
375
|
-
// showAdBasedOnAction('unlock_premium');
|
|
376
|
-
```
|
|
377
|
-
|
|
378
|
-
## License
|
|
379
|
-
|
|
1
|
+
# @ad-execute-manager/ad
|
|
2
|
+
|
|
3
|
+
Ad-related classes including InterstitialAdFather, InterstitialAdNovel, RewardAdFather, and RewardAdNovel for ad management.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @ad-execute-manager/ad
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **InterstitialAdFather**: Base class for interstitial ads with common functionality
|
|
14
|
+
- **InterstitialAdNovel**: Novel-specific interstitial ad implementation with enhanced features
|
|
15
|
+
- **RewardAdFather**: Base class for reward ads with common functionality
|
|
16
|
+
- **RewardAdNovel**: Novel-specific reward ad implementation with enhanced features
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### InterstitialAdNovel
|
|
21
|
+
|
|
22
|
+
```javascript
|
|
23
|
+
import { InterstitialAdNovel } from '@ad-execute-manager/ad';
|
|
24
|
+
|
|
25
|
+
const interstitialAd = InterstitialAdNovel.new({
|
|
26
|
+
sign: 'novel_interstitial',
|
|
27
|
+
preserveOnEnd: false,
|
|
28
|
+
needEndOnTimeout: true,
|
|
29
|
+
collection: {
|
|
30
|
+
onHalfway: (args) => {
|
|
31
|
+
console.log('Ad halfway:', args);
|
|
32
|
+
},
|
|
33
|
+
onShow: (args) => {
|
|
34
|
+
console.log('Ad shown:', args);
|
|
35
|
+
},
|
|
36
|
+
onFinish: (args) => {
|
|
37
|
+
console.log('Ad finished:', args);
|
|
38
|
+
},
|
|
39
|
+
onAlways: (args) => {
|
|
40
|
+
console.log('Ad always:', args);
|
|
41
|
+
},
|
|
42
|
+
onError: (error) => {
|
|
43
|
+
console.error('Ad error:', error);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Initialize ad
|
|
49
|
+
interstitialAd.initialize({
|
|
50
|
+
adUnitId: 'your-ad-unit-id',
|
|
51
|
+
retry: 3
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Show ad
|
|
55
|
+
const result = await interstitialAd.addExecuteManager({
|
|
56
|
+
options: {
|
|
57
|
+
scene: 1
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
console.log('Ad result:', result);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### RewardAdNovel
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
import { RewardAdNovel } from '@ad-execute-manager/ad';
|
|
68
|
+
|
|
69
|
+
const rewardAd = RewardAdNovel.new({
|
|
70
|
+
sign: 'novel_reward',
|
|
71
|
+
preserveOnEnd: false,
|
|
72
|
+
needEndOnTimeout: true,
|
|
73
|
+
collection: {
|
|
74
|
+
onHalfway: (args) => {
|
|
75
|
+
console.log('Ad halfway:', args);
|
|
76
|
+
},
|
|
77
|
+
onShow: (args) => {
|
|
78
|
+
console.log('Ad shown:', args);
|
|
79
|
+
},
|
|
80
|
+
onFinish: (args) => {
|
|
81
|
+
console.log('Ad finished:', args);
|
|
82
|
+
},
|
|
83
|
+
onAlways: (args) => {
|
|
84
|
+
console.log('Ad always:', args);
|
|
85
|
+
},
|
|
86
|
+
onError: (error) => {
|
|
87
|
+
console.error('Ad error:', error);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Initialize ad
|
|
93
|
+
rewardAd.initialize({
|
|
94
|
+
adUnitId: 'your-ad-unit-id',
|
|
95
|
+
retry: 3
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Show ad
|
|
99
|
+
const result = await rewardAd.addExecuteManager({
|
|
100
|
+
options: {
|
|
101
|
+
scene: 2,
|
|
102
|
+
timeout: 10000
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
console.log('Ad result:', result);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## API
|
|
110
|
+
|
|
111
|
+
### InterstitialAdFather
|
|
112
|
+
|
|
113
|
+
Base class for interstitial ads with common functionality.
|
|
114
|
+
|
|
115
|
+
### InterstitialAdNovel
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
class InterstitialAdNovel extends InterstitialAdFather {
|
|
119
|
+
/**
|
|
120
|
+
* Builds and returns an instance of InterstitialAdNovel
|
|
121
|
+
* @param args Construction arguments
|
|
122
|
+
* @returns Instance of InterstitialAdNovel
|
|
123
|
+
*/
|
|
124
|
+
static build(args: IConstructArgs): InterstitialAdNovel;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Gets the singleton instance of InterstitialAdNovel
|
|
128
|
+
* @returns Singleton instance of InterstitialAdNovel
|
|
129
|
+
*/
|
|
130
|
+
static getInstance(): InterstitialAdNovel;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Creates a new instance of InterstitialAdNovel
|
|
134
|
+
* @param args Construction arguments
|
|
135
|
+
* @returns New instance of InterstitialAdNovel
|
|
136
|
+
*/
|
|
137
|
+
static new(args: IConstructArgs): InterstitialAdNovel;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Initializes the ad with configuration
|
|
141
|
+
* @param params Ad configuration parameters
|
|
142
|
+
* @param callback Optional callback function
|
|
143
|
+
* @returns Current instance for method chaining
|
|
144
|
+
*/
|
|
145
|
+
initialize(params: IRewordAdConfig, callback?: (v: IRewardedVideoAd) => void): this;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Adds execute manager and runs the ad
|
|
149
|
+
* @param ctx Context object with options
|
|
150
|
+
* @returns Promise with ad execution result
|
|
151
|
+
*/
|
|
152
|
+
addExecuteManager(ctx: any): Promise<any>;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Clears the ad instance
|
|
156
|
+
*/
|
|
157
|
+
clear(): void;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Shifts the ad instance
|
|
161
|
+
*/
|
|
162
|
+
shift(): void;
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### RewardAdFather
|
|
167
|
+
|
|
168
|
+
Base class for reward ads with common functionality.
|
|
169
|
+
|
|
170
|
+
### RewardAdNovel
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
class RewardAdNovel extends RewardAdFather {
|
|
174
|
+
/**
|
|
175
|
+
* Builds and returns an instance of RewardAdNovel
|
|
176
|
+
* @param args Construction arguments
|
|
177
|
+
* @returns Instance of RewardAdNovel
|
|
178
|
+
*/
|
|
179
|
+
static build(args: IConstructArgs): RewardAdNovel;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Gets the singleton instance of RewardAdNovel
|
|
183
|
+
* @returns Singleton instance of RewardAdNovel
|
|
184
|
+
*/
|
|
185
|
+
static getInstance(): RewardAdNovel;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Creates a new instance of RewardAdNovel
|
|
189
|
+
* @param args Construction arguments
|
|
190
|
+
* @returns New instance of RewardAdNovel
|
|
191
|
+
*/
|
|
192
|
+
static new(args: IConstructArgs): RewardAdNovel;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Initializes the ad with configuration
|
|
196
|
+
* @param params Ad configuration parameters
|
|
197
|
+
* @param callback Optional callback function
|
|
198
|
+
* @returns Current instance for method chaining
|
|
199
|
+
*/
|
|
200
|
+
initialize(params: IRewordAdConfig, callback?: (v: IRewardedVideoAd) => void): this;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Adds execute manager and runs the ad
|
|
204
|
+
* @param ctx Context object with options
|
|
205
|
+
* @returns Promise with ad execution result
|
|
206
|
+
*/
|
|
207
|
+
addExecuteManager(ctx: any): Promise<any>;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Clears the ad instance
|
|
211
|
+
*/
|
|
212
|
+
clear(): void;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Shifts the ad instance
|
|
216
|
+
*/
|
|
217
|
+
shift(): void;
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Configuration
|
|
222
|
+
|
|
223
|
+
### Construction Arguments
|
|
224
|
+
|
|
225
|
+
When creating an ad instance, you can pass the following configuration options:
|
|
226
|
+
|
|
227
|
+
- **sign**: Unique identifier for the ad instance
|
|
228
|
+
- **preserveOnEnd**: Whether to preserve the instance after ad ends
|
|
229
|
+
- **needEndOnTimeout**: Whether to end the ad on timeout
|
|
230
|
+
- **collection**: Event collection object with callback functions
|
|
231
|
+
- **onHalfway**: Called when ad reaches halfway point
|
|
232
|
+
- **onShow**: Called when ad is shown
|
|
233
|
+
- **onFinish**: Called when ad finishes
|
|
234
|
+
- **onAlways**: Called always after ad operation
|
|
235
|
+
- **onError**: Called when ad encounters error
|
|
236
|
+
|
|
237
|
+
### Initialize Parameters
|
|
238
|
+
|
|
239
|
+
When initializing an ad, you can pass the following parameters:
|
|
240
|
+
|
|
241
|
+
- **adUnitId**: Unique identifier for the ad unit
|
|
242
|
+
- **retry**: Number of retry attempts on ad error
|
|
243
|
+
|
|
244
|
+
## Examples
|
|
245
|
+
|
|
246
|
+
### Example 1: Basic Interstitial Ad Usage
|
|
247
|
+
|
|
248
|
+
```javascript
|
|
249
|
+
import { InterstitialAdNovel } from '@ad-execute-manager/ad';
|
|
250
|
+
|
|
251
|
+
// Create ad instance
|
|
252
|
+
const interstitialAd = InterstitialAdNovel.new({
|
|
253
|
+
sign: 'chapter_end_interstitial',
|
|
254
|
+
preserveOnEnd: false,
|
|
255
|
+
needEndOnTimeout: true,
|
|
256
|
+
collection: {
|
|
257
|
+
onFinish: () => {
|
|
258
|
+
console.log('Interstitial ad finished, proceeding to next chapter');
|
|
259
|
+
// Proceed to next chapter logic here
|
|
260
|
+
},
|
|
261
|
+
onError: (error) => {
|
|
262
|
+
console.error('Interstitial ad error:', error);
|
|
263
|
+
// Handle error gracefully, maybe skip ad
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
// Initialize and show ad
|
|
269
|
+
interstitialAd.initialize({ adUnitId: 'ca-app-pub-xxx/xxx', retry: 2 });
|
|
270
|
+
|
|
271
|
+
// Show ad at chapter end
|
|
272
|
+
async function showAdAtChapterEnd() {
|
|
273
|
+
try {
|
|
274
|
+
const result = await interstitialAd.addExecuteManager({ options: { scene: 1 } });
|
|
275
|
+
console.log('Ad result:', result);
|
|
276
|
+
} catch (error) {
|
|
277
|
+
console.error('Ad execution error:', error);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Usage
|
|
282
|
+
// showAdAtChapterEnd();
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Example 2: Reward Ad for Premium Content
|
|
286
|
+
|
|
287
|
+
```javascript
|
|
288
|
+
import { RewardAdNovel } from '@ad-execute-manager/ad';
|
|
289
|
+
|
|
290
|
+
// Create reward ad instance
|
|
291
|
+
const rewardAd = RewardAdNovel.new({
|
|
292
|
+
sign: 'premium_content_reward',
|
|
293
|
+
preserveOnEnd: true,
|
|
294
|
+
needEndOnTimeout: true,
|
|
295
|
+
collection: {
|
|
296
|
+
onFinish: (args) => {
|
|
297
|
+
console.log('Reward ad finished, unlocking premium content');
|
|
298
|
+
// Unlock premium content logic here
|
|
299
|
+
unlockPremiumContent();
|
|
300
|
+
},
|
|
301
|
+
onError: (error) => {
|
|
302
|
+
console.error('Reward ad error:', error);
|
|
303
|
+
// Show error message to user
|
|
304
|
+
showErrorMessage('Failed to load ad. Please try again later.');
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// Initialize ad
|
|
310
|
+
rewardAd.initialize({ adUnitId: 'ca-app-pub-xxx/xxx', retry: 3 });
|
|
311
|
+
|
|
312
|
+
// Function to unlock premium content
|
|
313
|
+
function unlockPremiumContent() {
|
|
314
|
+
// Logic to unlock premium content
|
|
315
|
+
console.log('Premium content unlocked!');
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Function to show error message
|
|
319
|
+
function showErrorMessage(message) {
|
|
320
|
+
// Logic to show error message
|
|
321
|
+
console.log('Error:', message);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// Show reward ad to unlock premium content
|
|
325
|
+
async function showRewardAdForPremium() {
|
|
326
|
+
try {
|
|
327
|
+
const result = await rewardAd.addExecuteManager({
|
|
328
|
+
options: {
|
|
329
|
+
scene: 2,
|
|
330
|
+
timeout: 15000
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
console.log('Reward ad result:', result);
|
|
334
|
+
} catch (error) {
|
|
335
|
+
console.error('Reward ad execution error:', error);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Usage
|
|
340
|
+
// showRewardAdForPremium();
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
### Example 3: Ad Instance Management
|
|
344
|
+
|
|
345
|
+
```javascript
|
|
346
|
+
import { InterstitialAdNovel, RewardAdNovel } from '@ad-execute-manager/ad';
|
|
347
|
+
|
|
348
|
+
// Create ad instances
|
|
349
|
+
const interstitialAd = InterstitialAdNovel.new({ sign: 'interstitial' });
|
|
350
|
+
const rewardAd = RewardAdNovel.new({ sign: 'reward' });
|
|
351
|
+
|
|
352
|
+
// Initialize ads
|
|
353
|
+
interstitialAd.initialize({ adUnitId: 'ca-app-pub-xxx/xxx', retry: 2 });
|
|
354
|
+
rewardAd.initialize({ adUnitId: 'ca-app-pub-xxx/xxx', retry: 3 });
|
|
355
|
+
|
|
356
|
+
// Function to show appropriate ad based on user action
|
|
357
|
+
async function showAdBasedOnAction(action) {
|
|
358
|
+
try {
|
|
359
|
+
switch (action) {
|
|
360
|
+
case 'chapter_end':
|
|
361
|
+
return await interstitialAd.addExecuteManager({ options: { scene: 1 } });
|
|
362
|
+
case 'unlock_premium':
|
|
363
|
+
return await rewardAd.addExecuteManager({ options: { scene: 2 } });
|
|
364
|
+
default:
|
|
365
|
+
throw new Error('Invalid ad action');
|
|
366
|
+
}
|
|
367
|
+
} catch (error) {
|
|
368
|
+
console.error('Ad error:', error);
|
|
369
|
+
return { success: false, error: error.message };
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// Usage examples
|
|
374
|
+
// showAdBasedOnAction('chapter_end');
|
|
375
|
+
// showAdBasedOnAction('unlock_premium');
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
## License
|
|
379
|
+
|
|
380
380
|
MIT
|