@playcraft/adsdk 1.0.7 → 1.0.9

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/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- type EventName = 'init' | 'boot' | 'ready' | 'start' | 'interaction' | 'resize' | 'pause' | 'resume' | 'volume' | 'retry' | 'finish' | 'install';
1
+ type EventName = 'init' | 'ready' | 'start' | 'interactive' | 'interaction' | 'success' | 'resize' | 'pause' | 'resume' | 'volume' | 'retry' | 'finish' | 'install';
2
2
 
3
3
  type InitCallbackType = (maxWidth: number, maxHeight: number) => void;
4
4
  /**
@@ -24,13 +24,23 @@ declare class sdk {
24
24
  static isFinished: boolean;
25
25
  /** Current volume level (0-1) */
26
26
  static volume: number;
27
- /** Number of user interactions with the playable ad */
27
+ /** Number of user interactions with the playable ad (auto-incremented on each touch/click) */
28
28
  static interactions: number;
29
+ /** Number of successful game actions (e.g., successful matches, level clears).
30
+ * Controlled by calling sdk.recordSuccessCount(), NOT auto-incremented.
31
+ */
32
+ static successCount: number;
29
33
  /**
30
34
  * Initializes the SDK and sets up protocol-specific handlers.
31
35
  * This must be called as earlier as possible.
32
36
  *
33
37
  * @param callback Optional function called when ad container is ready
38
+ * @param options Optional configuration options
39
+ * @param options.totalSuccessCount Total number of successful actions expected for progress tracking.
40
+ * When set, the SDK will track success progress as a percentage and trigger
41
+ * channel-specific milestone events (e.g., AppLovin: CHALLENGE_PASS_25/50/75, CHALLENGE_SOLVED).
42
+ * Different channels monitor different percentage thresholds independently.
43
+ * Set to 0 or omit to disable progress tracking.
34
44
  * @example
35
45
  * // Basic initialization
36
46
  * sdk.init();
@@ -40,11 +50,17 @@ declare class sdk {
40
50
  * new App(width, height)
41
51
  * });
42
52
  *
43
- * @fires init When initialization starts
44
- * @fires boot When the ad begins booting
45
- * @fires ready When Ad Network is ready and playable ad can be initialized
53
+ * // Initialization with success count progress tracking
54
+ * sdk.init((width, height) => {
55
+ * new App(width, height)
56
+ * }, { totalSuccessCount: 20 });
57
+ *
58
+ * @fires loading When SDK initialization starts
59
+ * @fires loaded When game instance is created and ready to load resources
46
60
  */
47
- static init(callback?: InitCallbackType): void;
61
+ static init(callback?: InitCallbackType, options?: {
62
+ totalSuccessCount?: number;
63
+ }): void;
48
64
  /**
49
65
  * Starts the playable ad experience.
50
66
  * Should be called after all resources are loaded and first frame is rendered.
@@ -57,6 +73,20 @@ declare class sdk {
57
73
  * @fires resize When the ad container is initially sized
58
74
  */
59
75
  static start(): void;
76
+ /**
77
+ * Marks the main scene as fully loaded and ready for user interaction.
78
+ * Should be called at the end of your main game scene's create() method.
79
+ *
80
+ * @example
81
+ * // In Phaser MainScene.create()
82
+ * create() {
83
+ * // ... all initialization code ...
84
+ * sdk.interactive();
85
+ * }
86
+ *
87
+ * @fires interactive When the main scene is ready for user interaction
88
+ */
89
+ static interactive(): void;
60
90
  /**
61
91
  * Marks the playable ad as finished.
62
92
  * This triggers network-specific completion handlers.
@@ -104,6 +134,53 @@ declare class sdk {
104
134
  * @fires resize With current maxWidth and maxHeight
105
135
  */
106
136
  static resize(): void;
137
+ /**
138
+ * Records successful game actions (e.g., successful match, level clear).
139
+ * This should be called by game logic when a meaningful success occurs.
140
+ * This count is used for progress tracking (e.g., AppLovin milestone events).
141
+ *
142
+ * @param count Optional success count to add (default: 1)
143
+ *
144
+ * @example
145
+ * // Record single success when match completes
146
+ * onMatchSuccess() {
147
+ * sdk.recordSuccessCount();
148
+ * }
149
+ *
150
+ * // Record multiple successes at once
151
+ * onComboMatch(comboCount) {
152
+ * sdk.recordSuccessCount(comboCount);
153
+ * }
154
+ *
155
+ * @fires success With updated success count (triggers progress tracking)
156
+ */
157
+ static recordSuccessCount(count?: number): void;
158
+ /**
159
+ * Records a game success/completion event.
160
+ * Sends platform-specific success tracking events:
161
+ * - AppLovin: CHALLENGE_SOLVED
162
+ * - Bigabid: complete
163
+ * - InMobi: Gameplay_Complete
164
+ *
165
+ * @example
166
+ * // When player completes the level
167
+ * onLevelComplete() {
168
+ * sdk.recordSuccess();
169
+ * }
170
+ */
171
+ static recordSuccess(): void;
172
+ /**
173
+ * Records a game failure event.
174
+ * Sends platform-specific failure tracking events:
175
+ * - AppLovin: CHALLENGE_FAILED
176
+ *
177
+ * @example
178
+ * // When player fails the level
179
+ * onLevelFailed() {
180
+ * sdk.recordFailed();
181
+ * }
182
+ */
183
+ static recordFailed(): void;
107
184
  /**
108
185
  * Forces the playable ad into a paused state.
109
186
  *
@@ -179,6 +256,10 @@ declare class sdk {
179
256
  * @returns 当前渠道
180
257
  */
181
258
  static getCurChannel(): "applovin" | "ironsource" | "unity" | "mintegral" | "preview" | "google" | "facebook" | "moloco" | "vungle" | "adcolony" | "tapjoy" | "snapchat" | "tiktok" | "appreciate" | "chartboost" | "pangle" | "mytarget" | "liftoff" | "smadex" | "adikteev" | "bigabid" | "inmobi" | "bigoads";
259
+ /**
260
+ * 判断是否是 Google
261
+ */
262
+ static isGoogle(): boolean;
182
263
  }
183
264
 
184
265
  /**
@@ -198,4 +279,138 @@ declare function hideWechatGuide(): void;
198
279
  */
199
280
  declare function removeWechatGuide(): void;
200
281
 
201
- export { sdk as default, hideWechatGuide, removeWechatGuide, sdk, showWechatGuide };
282
+ /**
283
+ * 设置交互总数
284
+ */
285
+ declare function setTotalInteractions(total: number): void;
286
+ /**
287
+ * 检查交互进度,触发对应里程碑
288
+ */
289
+ declare function checkInteractionProgress(currentInteractions: number): void;
290
+ /**
291
+ * init 事件:SDK 初始化开始
292
+ * 渠道埋点: Bigabid:mraid_viewable | InMobi:Ad_Load_Start | AppLovin:LOADING
293
+ * 同时初始化进度里程碑
294
+ * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
295
+ */
296
+ declare function _onInit(adNetwork?: string): void;
297
+ /**
298
+ * start 事件:游戏资源加载完成
299
+ * 渠道埋点: Bigabid:game_viewable | InMobi:Ad_Viewable | AppLovin:LOADED
300
+ * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
301
+ */
302
+ declare function _onStart(adNetwork?: string): void;
303
+ /**
304
+ * interactive 事件:主场景就绪,用户可交互
305
+ * 渠道埋点: AppLovin:DISPLAYED
306
+ * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
307
+ */
308
+ declare function _onInteractive(adNetwork?: string): void;
309
+ /**
310
+ * interaction 事件:首次交互
311
+ * 渠道埋点: Bigabid:engagement | InMobi:First_Engagement | AppLovin:CHALLENGE_STARTED
312
+ * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
313
+ */
314
+ declare function _onInteraction(adNetwork?: string): void;
315
+ /**
316
+ * success 事件:成功计数(用于进度百分比追踪)
317
+ */
318
+ declare function _onSuccess(successCount: number): void;
319
+ /**
320
+ * finish 事件:游戏结束
321
+ * 渠道埋点: Bigabid:complete | InMobi:Gameplay_Complete | AppLovin:ENDCARD_SHOWN
322
+ * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
323
+ */
324
+ declare function _onFinish(adNetwork?: string): void;
325
+ /**
326
+ * install 事件:点击安装
327
+ * 渠道埋点: Bigabid:click | InMobi:DSP_Click | AppLovin:CTA_CLICKED
328
+ * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
329
+ */
330
+ declare function _onInstall(adNetwork?: string): void;
331
+ /**
332
+ * retry 事件:重试游戏
333
+ * 渠道埋点: AppLovin:CHALLENGE_RETRY
334
+ * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
335
+ */
336
+ declare function _onRetry(adNetwork?: string): void;
337
+ /**
338
+ * 触发游戏成功事件
339
+ * 不同渠道发送对应的成功埋点
340
+ * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
341
+ */
342
+ declare function _trackChallengeSuccess(adNetwork?: string): void;
343
+ /**
344
+ * 触发游戏失败事件
345
+ * 不同渠道发送对应的失败埋点
346
+ * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
347
+ */
348
+ declare function _trackChallengeFailed(adNetwork?: string): void;
349
+ /**
350
+ * 统一的埋点追踪对象
351
+ * 包含所有 SDK 事件的埋点方法
352
+ */
353
+ declare const tracking: {
354
+ /**
355
+ * SDK 初始化开始
356
+ * @param adNetwork - 可选的广告渠道名称
357
+ */
358
+ onInit: typeof _onInit;
359
+ /**
360
+ * 游戏资源加载完成
361
+ * @param adNetwork - 可选的广告渠道名称
362
+ */
363
+ onStart: typeof _onStart;
364
+ /**
365
+ * 主场景就绪,用户可交互
366
+ * @param adNetwork - 可选的广告渠道名称
367
+ */
368
+ onInteractive: typeof _onInteractive;
369
+ /**
370
+ * 首次交互
371
+ * @param adNetwork - 可选的广告渠道名称
372
+ */
373
+ onInteraction: typeof _onInteraction;
374
+ /**
375
+ * 成功计数(用于进度百分比追踪)
376
+ * @param successCount - 当前成功次数
377
+ */
378
+ onSuccess: typeof _onSuccess;
379
+ /**
380
+ * 游戏结束
381
+ * @param adNetwork - 可选的广告渠道名称
382
+ */
383
+ onFinish: typeof _onFinish;
384
+ /**
385
+ * 点击安装
386
+ * @param adNetwork - 可选的广告渠道名称
387
+ */
388
+ onInstall: typeof _onInstall;
389
+ /**
390
+ * 重试游戏
391
+ * @param adNetwork - 可选的广告渠道名称
392
+ */
393
+ onRetry: typeof _onRetry;
394
+ /**
395
+ * 设置交互总数(用于进度百分比计算)
396
+ * @param total - 交互总数
397
+ */
398
+ setTotalInteractions: typeof setTotalInteractions;
399
+ /**
400
+ * 检查交互进度
401
+ * @param currentInteractions - 当前交互次数
402
+ */
403
+ checkInteractionProgress: typeof checkInteractionProgress;
404
+ /**
405
+ * 触发游戏成功事件
406
+ * @param adNetwork - 可选的广告渠道名称
407
+ */
408
+ trackChallengeSuccess: typeof _trackChallengeSuccess;
409
+ /**
410
+ * 触发游戏失败事件
411
+ * @param adNetwork - 可选的广告渠道名称
412
+ */
413
+ trackChallengeFailed: typeof _trackChallengeFailed;
414
+ };
415
+
416
+ export { sdk as default, hideWechatGuide, removeWechatGuide, sdk, showWechatGuide, tracking };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- type EventName = 'init' | 'boot' | 'ready' | 'start' | 'interaction' | 'resize' | 'pause' | 'resume' | 'volume' | 'retry' | 'finish' | 'install';
1
+ type EventName = 'init' | 'ready' | 'start' | 'interactive' | 'interaction' | 'success' | 'resize' | 'pause' | 'resume' | 'volume' | 'retry' | 'finish' | 'install';
2
2
 
3
3
  type InitCallbackType = (maxWidth: number, maxHeight: number) => void;
4
4
  /**
@@ -24,13 +24,23 @@ declare class sdk {
24
24
  static isFinished: boolean;
25
25
  /** Current volume level (0-1) */
26
26
  static volume: number;
27
- /** Number of user interactions with the playable ad */
27
+ /** Number of user interactions with the playable ad (auto-incremented on each touch/click) */
28
28
  static interactions: number;
29
+ /** Number of successful game actions (e.g., successful matches, level clears).
30
+ * Controlled by calling sdk.recordSuccessCount(), NOT auto-incremented.
31
+ */
32
+ static successCount: number;
29
33
  /**
30
34
  * Initializes the SDK and sets up protocol-specific handlers.
31
35
  * This must be called as earlier as possible.
32
36
  *
33
37
  * @param callback Optional function called when ad container is ready
38
+ * @param options Optional configuration options
39
+ * @param options.totalSuccessCount Total number of successful actions expected for progress tracking.
40
+ * When set, the SDK will track success progress as a percentage and trigger
41
+ * channel-specific milestone events (e.g., AppLovin: CHALLENGE_PASS_25/50/75, CHALLENGE_SOLVED).
42
+ * Different channels monitor different percentage thresholds independently.
43
+ * Set to 0 or omit to disable progress tracking.
34
44
  * @example
35
45
  * // Basic initialization
36
46
  * sdk.init();
@@ -40,11 +50,17 @@ declare class sdk {
40
50
  * new App(width, height)
41
51
  * });
42
52
  *
43
- * @fires init When initialization starts
44
- * @fires boot When the ad begins booting
45
- * @fires ready When Ad Network is ready and playable ad can be initialized
53
+ * // Initialization with success count progress tracking
54
+ * sdk.init((width, height) => {
55
+ * new App(width, height)
56
+ * }, { totalSuccessCount: 20 });
57
+ *
58
+ * @fires loading When SDK initialization starts
59
+ * @fires loaded When game instance is created and ready to load resources
46
60
  */
47
- static init(callback?: InitCallbackType): void;
61
+ static init(callback?: InitCallbackType, options?: {
62
+ totalSuccessCount?: number;
63
+ }): void;
48
64
  /**
49
65
  * Starts the playable ad experience.
50
66
  * Should be called after all resources are loaded and first frame is rendered.
@@ -57,6 +73,20 @@ declare class sdk {
57
73
  * @fires resize When the ad container is initially sized
58
74
  */
59
75
  static start(): void;
76
+ /**
77
+ * Marks the main scene as fully loaded and ready for user interaction.
78
+ * Should be called at the end of your main game scene's create() method.
79
+ *
80
+ * @example
81
+ * // In Phaser MainScene.create()
82
+ * create() {
83
+ * // ... all initialization code ...
84
+ * sdk.interactive();
85
+ * }
86
+ *
87
+ * @fires interactive When the main scene is ready for user interaction
88
+ */
89
+ static interactive(): void;
60
90
  /**
61
91
  * Marks the playable ad as finished.
62
92
  * This triggers network-specific completion handlers.
@@ -104,6 +134,53 @@ declare class sdk {
104
134
  * @fires resize With current maxWidth and maxHeight
105
135
  */
106
136
  static resize(): void;
137
+ /**
138
+ * Records successful game actions (e.g., successful match, level clear).
139
+ * This should be called by game logic when a meaningful success occurs.
140
+ * This count is used for progress tracking (e.g., AppLovin milestone events).
141
+ *
142
+ * @param count Optional success count to add (default: 1)
143
+ *
144
+ * @example
145
+ * // Record single success when match completes
146
+ * onMatchSuccess() {
147
+ * sdk.recordSuccessCount();
148
+ * }
149
+ *
150
+ * // Record multiple successes at once
151
+ * onComboMatch(comboCount) {
152
+ * sdk.recordSuccessCount(comboCount);
153
+ * }
154
+ *
155
+ * @fires success With updated success count (triggers progress tracking)
156
+ */
157
+ static recordSuccessCount(count?: number): void;
158
+ /**
159
+ * Records a game success/completion event.
160
+ * Sends platform-specific success tracking events:
161
+ * - AppLovin: CHALLENGE_SOLVED
162
+ * - Bigabid: complete
163
+ * - InMobi: Gameplay_Complete
164
+ *
165
+ * @example
166
+ * // When player completes the level
167
+ * onLevelComplete() {
168
+ * sdk.recordSuccess();
169
+ * }
170
+ */
171
+ static recordSuccess(): void;
172
+ /**
173
+ * Records a game failure event.
174
+ * Sends platform-specific failure tracking events:
175
+ * - AppLovin: CHALLENGE_FAILED
176
+ *
177
+ * @example
178
+ * // When player fails the level
179
+ * onLevelFailed() {
180
+ * sdk.recordFailed();
181
+ * }
182
+ */
183
+ static recordFailed(): void;
107
184
  /**
108
185
  * Forces the playable ad into a paused state.
109
186
  *
@@ -179,6 +256,10 @@ declare class sdk {
179
256
  * @returns 当前渠道
180
257
  */
181
258
  static getCurChannel(): "applovin" | "ironsource" | "unity" | "mintegral" | "preview" | "google" | "facebook" | "moloco" | "vungle" | "adcolony" | "tapjoy" | "snapchat" | "tiktok" | "appreciate" | "chartboost" | "pangle" | "mytarget" | "liftoff" | "smadex" | "adikteev" | "bigabid" | "inmobi" | "bigoads";
259
+ /**
260
+ * 判断是否是 Google
261
+ */
262
+ static isGoogle(): boolean;
182
263
  }
183
264
 
184
265
  /**
@@ -198,4 +279,138 @@ declare function hideWechatGuide(): void;
198
279
  */
199
280
  declare function removeWechatGuide(): void;
200
281
 
201
- export { sdk as default, hideWechatGuide, removeWechatGuide, sdk, showWechatGuide };
282
+ /**
283
+ * 设置交互总数
284
+ */
285
+ declare function setTotalInteractions(total: number): void;
286
+ /**
287
+ * 检查交互进度,触发对应里程碑
288
+ */
289
+ declare function checkInteractionProgress(currentInteractions: number): void;
290
+ /**
291
+ * init 事件:SDK 初始化开始
292
+ * 渠道埋点: Bigabid:mraid_viewable | InMobi:Ad_Load_Start | AppLovin:LOADING
293
+ * 同时初始化进度里程碑
294
+ * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
295
+ */
296
+ declare function _onInit(adNetwork?: string): void;
297
+ /**
298
+ * start 事件:游戏资源加载完成
299
+ * 渠道埋点: Bigabid:game_viewable | InMobi:Ad_Viewable | AppLovin:LOADED
300
+ * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
301
+ */
302
+ declare function _onStart(adNetwork?: string): void;
303
+ /**
304
+ * interactive 事件:主场景就绪,用户可交互
305
+ * 渠道埋点: AppLovin:DISPLAYED
306
+ * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
307
+ */
308
+ declare function _onInteractive(adNetwork?: string): void;
309
+ /**
310
+ * interaction 事件:首次交互
311
+ * 渠道埋点: Bigabid:engagement | InMobi:First_Engagement | AppLovin:CHALLENGE_STARTED
312
+ * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
313
+ */
314
+ declare function _onInteraction(adNetwork?: string): void;
315
+ /**
316
+ * success 事件:成功计数(用于进度百分比追踪)
317
+ */
318
+ declare function _onSuccess(successCount: number): void;
319
+ /**
320
+ * finish 事件:游戏结束
321
+ * 渠道埋点: Bigabid:complete | InMobi:Gameplay_Complete | AppLovin:ENDCARD_SHOWN
322
+ * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
323
+ */
324
+ declare function _onFinish(adNetwork?: string): void;
325
+ /**
326
+ * install 事件:点击安装
327
+ * 渠道埋点: Bigabid:click | InMobi:DSP_Click | AppLovin:CTA_CLICKED
328
+ * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
329
+ */
330
+ declare function _onInstall(adNetwork?: string): void;
331
+ /**
332
+ * retry 事件:重试游戏
333
+ * 渠道埋点: AppLovin:CHALLENGE_RETRY
334
+ * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
335
+ */
336
+ declare function _onRetry(adNetwork?: string): void;
337
+ /**
338
+ * 触发游戏成功事件
339
+ * 不同渠道发送对应的成功埋点
340
+ * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
341
+ */
342
+ declare function _trackChallengeSuccess(adNetwork?: string): void;
343
+ /**
344
+ * 触发游戏失败事件
345
+ * 不同渠道发送对应的失败埋点
346
+ * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
347
+ */
348
+ declare function _trackChallengeFailed(adNetwork?: string): void;
349
+ /**
350
+ * 统一的埋点追踪对象
351
+ * 包含所有 SDK 事件的埋点方法
352
+ */
353
+ declare const tracking: {
354
+ /**
355
+ * SDK 初始化开始
356
+ * @param adNetwork - 可选的广告渠道名称
357
+ */
358
+ onInit: typeof _onInit;
359
+ /**
360
+ * 游戏资源加载完成
361
+ * @param adNetwork - 可选的广告渠道名称
362
+ */
363
+ onStart: typeof _onStart;
364
+ /**
365
+ * 主场景就绪,用户可交互
366
+ * @param adNetwork - 可选的广告渠道名称
367
+ */
368
+ onInteractive: typeof _onInteractive;
369
+ /**
370
+ * 首次交互
371
+ * @param adNetwork - 可选的广告渠道名称
372
+ */
373
+ onInteraction: typeof _onInteraction;
374
+ /**
375
+ * 成功计数(用于进度百分比追踪)
376
+ * @param successCount - 当前成功次数
377
+ */
378
+ onSuccess: typeof _onSuccess;
379
+ /**
380
+ * 游戏结束
381
+ * @param adNetwork - 可选的广告渠道名称
382
+ */
383
+ onFinish: typeof _onFinish;
384
+ /**
385
+ * 点击安装
386
+ * @param adNetwork - 可选的广告渠道名称
387
+ */
388
+ onInstall: typeof _onInstall;
389
+ /**
390
+ * 重试游戏
391
+ * @param adNetwork - 可选的广告渠道名称
392
+ */
393
+ onRetry: typeof _onRetry;
394
+ /**
395
+ * 设置交互总数(用于进度百分比计算)
396
+ * @param total - 交互总数
397
+ */
398
+ setTotalInteractions: typeof setTotalInteractions;
399
+ /**
400
+ * 检查交互进度
401
+ * @param currentInteractions - 当前交互次数
402
+ */
403
+ checkInteractionProgress: typeof checkInteractionProgress;
404
+ /**
405
+ * 触发游戏成功事件
406
+ * @param adNetwork - 可选的广告渠道名称
407
+ */
408
+ trackChallengeSuccess: typeof _trackChallengeSuccess;
409
+ /**
410
+ * 触发游戏失败事件
411
+ * @param adNetwork - 可选的广告渠道名称
412
+ */
413
+ trackChallengeFailed: typeof _trackChallengeFailed;
414
+ };
415
+
416
+ export { sdk as default, hideWechatGuide, removeWechatGuide, sdk, showWechatGuide, tracking };