@playcraft/adsdk 1.0.13 → 1.0.15

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' | 'ready' | 'start' | 'interactive' | 'interaction' | 'success' | 'resize' | 'pause' | 'resume' | 'volume' | 'retry' | 'finish' | 'install';
1
+ type EventName = 'playcraftInit' | 'playcraftReady' | 'playcraftStart' | 'playcraftInteractive' | 'playcraftInteraction' | 'playcraftChallengeStart' | 'playcraftChallengeProgress' | 'playcraftChallengeSuccess' | 'playcraftChallengeFailed' | 'playcraftResize' | 'playcraftPause' | 'playcraftResume' | 'playcraftVolume' | 'playcraftRetry' | 'playcraftFinish' | 'playcraftInstall';
2
2
 
3
3
  type InitCallbackType = (maxWidth: number, maxHeight: number) => void;
4
4
  /**
@@ -26,135 +26,114 @@ declare class sdk {
26
26
  static volume: number;
27
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;
33
29
  /**
34
30
  * Initializes the SDK and sets up protocol-specific handlers.
35
31
  * This must be called as earlier as possible.
36
32
  *
37
33
  * @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.
44
34
  * @example
45
35
  * // Basic initialization
46
- * sdk.init();
36
+ * sdk.playcraftInit();
47
37
  *
48
38
  * // Initialization with callback
49
- * sdk.init((width, height) => {
39
+ * sdk.playcraftInit((width, height) => {
50
40
  * new App(width, height)
51
41
  * });
52
42
  *
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
43
+ * @fires playcraftInit When SDK initialization starts
44
+ * @fires playcraftReady When game instance is created and ready to load resources
60
45
  */
61
- static init(callback?: InitCallbackType, options?: {
62
- totalSuccessCount?: number;
63
- }): void;
46
+ static playcraftInit(callback?: InitCallbackType): void;
64
47
  /**
65
48
  * Starts the playable ad experience.
66
49
  * Should be called after all resources are loaded and first frame is rendered.
67
50
  *
68
51
  * @example
69
- * // Call just after all resources are preloaded and first frame is rendered
70
- * sdk.start();
52
+ * sdk.playcraftStart();
71
53
  *
72
- * @fires start When the playable ad starts
73
- * @fires resize When the ad container is initially sized
54
+ * @fires playcraftStart When the playable ad starts
55
+ * @fires playcraftResize When the ad container is initially sized
74
56
  */
75
- static start(): void;
57
+ static playcraftStart(): void;
76
58
  /**
77
59
  * Marks the main scene as fully loaded and ready for user interaction.
78
60
  * Should be called at the end of your main game scene's create() method.
79
61
  *
80
62
  * @example
81
- * // In Phaser MainScene.create()
82
63
  * create() {
83
64
  * // ... all initialization code ...
84
- * sdk.interactive();
65
+ * sdk.playcraftInteractive();
85
66
  * }
86
67
  *
87
- * @fires interactive When the main scene is ready for user interaction
68
+ * @fires playcraftInteractive When the main scene is ready for user interaction
88
69
  */
89
- static interactive(): void;
70
+ static playcraftInteractive(): void;
71
+ /**
72
+ * Marks the challenge as started.
73
+ * Should be called by business logic when the user actually starts playing.
74
+ *
75
+ * @example
76
+ * onFirstClick() {
77
+ * sdk.playcraftChallengeStart();
78
+ * }
79
+ *
80
+ * @fires playcraftChallengeStart When the challenge starts
81
+ */
82
+ static playcraftChallengeStart(): void;
90
83
  /**
91
84
  * Marks the playable ad as finished.
92
- * This triggers network-specific completion handlers.
93
85
  *
94
86
  * @example
95
- * // Call when game/experience is complete
96
- * sdk.finish();
87
+ * sdk.playcraftFinish();
97
88
  *
98
- * @fires finish When the playable ad is marked as finished
89
+ * @fires playcraftFinish When the playable ad is marked as finished
99
90
  */
100
- static finish(): void;
91
+ static playcraftFinish(): void;
101
92
  /**
102
93
  * Triggers a retry/restart of the playable ad.
103
- * Behavior varies by ad network.
104
94
  *
105
95
  * @example
106
- * // Allow user to try again
107
- * retryButton.onclick = () => sdk.retry();
96
+ * retryButton.onclick = () => sdk.playcraftRetry();
108
97
  *
109
- * @fires retry When a retry is triggered
98
+ * @fires playcraftRetry When a retry is triggered
110
99
  */
111
- static retry(): void;
100
+ static playcraftRetry(): void;
112
101
  /**
113
102
  * Triggers the install/download action for the advertised app.
114
- * Handles different store opening methods across ad networks.
115
103
  *
116
104
  * @example
117
- * // Call when user wants to install
118
- * installButton.onclick = () => sdk.install();
105
+ * installButton.onclick = () => sdk.playcraftInstall();
119
106
  *
120
- * @fires finish If the ad hasn't been marked as finished
121
- * @fires install When the install action is triggered
107
+ * @fires playcraftFinish If the ad hasn't been marked as finished
108
+ * @fires playcraftInstall When the install action is triggered
122
109
  */
123
- static install(params?: {
110
+ static playcraftInstall(params?: {
124
111
  action_type: 'auto' | 'click';
125
112
  timeout: number;
126
113
  }): void;
127
114
  /**
128
115
  * Trigger force resize event
129
- * Useful when container size changes need to be manually propagated.
130
116
  *
131
117
  * @example
132
- * sdk.resize();
118
+ * sdk.playcraftResize();
133
119
  *
134
- * @fires resize With current maxWidth and maxHeight
120
+ * @fires playcraftResize With current maxWidth and maxHeight
135
121
  */
136
- static resize(): void;
122
+ static playcraftResize(): void;
137
123
  /**
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).
124
+ * Records playable ad challenge progress (0-100).
125
+ * Triggers channel-specific milestone events based on the progress value.
126
+ * Milestones are not re-triggered once fired.
141
127
  *
142
- * @param count Optional success count to add (default: 1)
128
+ * @param percent Progress percentage (0-100)
143
129
  *
144
130
  * @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
- * }
131
+ * // Report 50% progress
132
+ * sdk.recordPlaycraftChallengeProgress(50);
154
133
  *
155
- * @fires success With updated success count (triggers progress tracking)
134
+ * @fires playcraftChallengeProgress With the progress percentage value
156
135
  */
157
- static recordSuccessCount(count?: number): void;
136
+ static recordPlaycraftChallengeProgress(percent: number): void;
158
137
  /**
159
138
  * Records a game success/completion event.
160
139
  * Sends platform-specific success tracking events:
@@ -163,45 +142,40 @@ declare class sdk {
163
142
  * - InMobi: Gameplay_Complete
164
143
  *
165
144
  * @example
166
- * // When player completes the level
167
145
  * onLevelComplete() {
168
- * sdk.recordSuccess();
146
+ * sdk.playcraftRecordSuccess();
169
147
  * }
170
148
  */
171
- static recordSuccess(): void;
149
+ static playcraftRecordSuccess(): void;
172
150
  /**
173
151
  * Records a game failure event.
174
152
  * Sends platform-specific failure tracking events:
175
153
  * - AppLovin: CHALLENGE_FAILED
176
154
  *
177
155
  * @example
178
- * // When player fails the level
179
156
  * onLevelFailed() {
180
- * sdk.recordFailed();
157
+ * sdk.playcraftRecordFailed();
181
158
  * }
182
159
  */
183
- static recordFailed(): void;
160
+ static playcraftRecordFailed(): void;
184
161
  /**
185
162
  * Forces the playable ad into a paused state.
186
163
  *
187
164
  * @example
188
- * // Pause the experience
189
- * pauseButton.onclick = () => sdk.pause();
165
+ * pauseButton.onclick = () => sdk.playcraftPause();
190
166
  *
191
- * @fires pause When the ad enters paused state
167
+ * @fires playcraftPause When the ad enters paused state
192
168
  */
193
- static pause(): void;
169
+ static playcraftPause(): void;
194
170
  /**
195
171
  * Resumes the playable ad from a forced pause state.
196
- * Only works if the ad was paused via sdk.pause().
197
172
  *
198
173
  * @example
199
- * // Resume from pause
200
- * resumeButton.onclick = () => sdk.resume();
174
+ * resumeButton.onclick = () => sdk.playcraftResume();
201
175
  *
202
- * @fires resume When the ad resumes from pause
176
+ * @fires playcraftResume When the ad resumes from pause
203
177
  */
204
- static resume(): void;
178
+ static playcraftResume(): void;
205
179
  /**
206
180
  * Registers an event listener.
207
181
  *
@@ -210,15 +184,9 @@ declare class sdk {
210
184
  * @param context Optional 'this' context for the callback
211
185
  *
212
186
  * @example
213
- * // Listen for user interactions
214
- * sdk.on('interaction', (count) => {
187
+ * sdk.on('playcraftInteraction', (count) => {
215
188
  * console.log(`User interaction #${count}`);
216
189
  * });
217
- *
218
- * // Listen for resize with context
219
- * sdk.on('resize', function(width, height) {
220
- * this.updateLayout(width, height);
221
- * }, gameInstance);
222
190
  */
223
191
  static on(event: EventName, fn: Function, context?: any): void;
224
192
  /**
@@ -229,8 +197,7 @@ declare class sdk {
229
197
  * @param context Optional 'this' context for the callback
230
198
  *
231
199
  * @example
232
- * // Listen for first interaction only
233
- * sdk.once('interaction', () => {
200
+ * sdk.once('playcraftInteraction', () => {
234
201
  * console.log('First user interaction occurred!');
235
202
  * });
236
203
  */
@@ -239,20 +206,14 @@ declare class sdk {
239
206
  * Removes an event listener.
240
207
  *
241
208
  * @param event Name of the event to stop listening for
242
- * @param fn Optional callback function to remove (if not provided, removes all listeners for the event)
209
+ * @param fn Optional callback function to remove
243
210
  * @param context Optional 'this' context to match when removing
244
211
  *
245
212
  * @example
246
- * // Remove specific listener
247
- * const handler = () => console.log('Interaction');
248
- * sdk.off('interaction', handler);
249
- *
250
- * // Remove all listeners for an event
251
- * sdk.off('interaction');
213
+ * sdk.off('playcraftInteraction', handler);
252
214
  */
253
215
  static off(event: EventName, fn?: Function, context?: any): void;
254
216
  /**
255
- *
256
217
  * @returns 当前渠道
257
218
  */
258
219
  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";
@@ -309,138 +270,4 @@ declare function hideWechatGuide(): void;
309
270
  */
310
271
  declare function removeWechatGuide(): void;
311
272
 
312
- /**
313
- * 设置交互总数
314
- */
315
- declare function setTotalInteractions(total: number): void;
316
- /**
317
- * 检查交互进度,触发对应里程碑
318
- */
319
- declare function checkInteractionProgress(currentInteractions: number): void;
320
- /**
321
- * init 事件:SDK 初始化开始
322
- * 渠道埋点: Bigabid:mraid_viewable | InMobi:Ad_Load_Start | AppLovin:LOADING
323
- * 同时初始化进度里程碑
324
- * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
325
- */
326
- declare function _onInit(adNetwork?: string): void;
327
- /**
328
- * start 事件:游戏资源加载完成
329
- * 渠道埋点: Bigabid:game_viewable | InMobi:Ad_Viewable | AppLovin:LOADED
330
- * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
331
- */
332
- declare function _onStart(adNetwork?: string): void;
333
- /**
334
- * interactive 事件:主场景就绪,用户可交互
335
- * 渠道埋点: AppLovin:DISPLAYED
336
- * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
337
- */
338
- declare function _onInteractive(adNetwork?: string): void;
339
- /**
340
- * interaction 事件:首次交互
341
- * 渠道埋点: Bigabid:engagement | InMobi:First_Engagement | AppLovin:CHALLENGE_STARTED
342
- * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
343
- */
344
- declare function _onInteraction(adNetwork?: string): void;
345
- /**
346
- * success 事件:成功计数(用于进度百分比追踪)
347
- */
348
- declare function _onSuccess(successCount: number): void;
349
- /**
350
- * finish 事件:游戏结束
351
- * 渠道埋点: Bigabid:complete | InMobi:Gameplay_Complete | AppLovin:ENDCARD_SHOWN
352
- * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
353
- */
354
- declare function _onFinish(adNetwork?: string): void;
355
- /**
356
- * install 事件:点击安装
357
- * 渠道埋点: Bigabid:click | InMobi:DSP_Click | AppLovin:CTA_CLICKED
358
- * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
359
- */
360
- declare function _onInstall(adNetwork?: string): void;
361
- /**
362
- * retry 事件:重试游戏
363
- * 渠道埋点: AppLovin:CHALLENGE_RETRY
364
- * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
365
- */
366
- declare function _onRetry(adNetwork?: string): void;
367
- /**
368
- * 触发游戏成功事件
369
- * 不同渠道发送对应的成功埋点
370
- * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
371
- */
372
- declare function _trackChallengeSuccess(adNetwork?: string): void;
373
- /**
374
- * 触发游戏失败事件
375
- * 不同渠道发送对应的失败埋点
376
- * @param adNetwork - 可选的广告渠道名称,不传则使用全局 AD_NETWORK
377
- */
378
- declare function _trackChallengeFailed(adNetwork?: string): void;
379
- /**
380
- * 统一的埋点追踪对象
381
- * 包含所有 SDK 事件的埋点方法
382
- */
383
- declare const tracking: {
384
- /**
385
- * SDK 初始化开始
386
- * @param adNetwork - 可选的广告渠道名称
387
- */
388
- onInit: typeof _onInit;
389
- /**
390
- * 游戏资源加载完成
391
- * @param adNetwork - 可选的广告渠道名称
392
- */
393
- onStart: typeof _onStart;
394
- /**
395
- * 主场景就绪,用户可交互
396
- * @param adNetwork - 可选的广告渠道名称
397
- */
398
- onInteractive: typeof _onInteractive;
399
- /**
400
- * 首次交互
401
- * @param adNetwork - 可选的广告渠道名称
402
- */
403
- onInteraction: typeof _onInteraction;
404
- /**
405
- * 成功计数(用于进度百分比追踪)
406
- * @param successCount - 当前成功次数
407
- */
408
- onSuccess: typeof _onSuccess;
409
- /**
410
- * 游戏结束
411
- * @param adNetwork - 可选的广告渠道名称
412
- */
413
- onFinish: typeof _onFinish;
414
- /**
415
- * 点击安装
416
- * @param adNetwork - 可选的广告渠道名称
417
- */
418
- onInstall: typeof _onInstall;
419
- /**
420
- * 重试游戏
421
- * @param adNetwork - 可选的广告渠道名称
422
- */
423
- onRetry: typeof _onRetry;
424
- /**
425
- * 设置交互总数(用于进度百分比计算)
426
- * @param total - 交互总数
427
- */
428
- setTotalInteractions: typeof setTotalInteractions;
429
- /**
430
- * 检查交互进度
431
- * @param currentInteractions - 当前交互次数
432
- */
433
- checkInteractionProgress: typeof checkInteractionProgress;
434
- /**
435
- * 触发游戏成功事件
436
- * @param adNetwork - 可选的广告渠道名称
437
- */
438
- trackChallengeSuccess: typeof _trackChallengeSuccess;
439
- /**
440
- * 触发游戏失败事件
441
- * @param adNetwork - 可选的广告渠道名称
442
- */
443
- trackChallengeFailed: typeof _trackChallengeFailed;
444
- };
445
-
446
- export { sdk as default, hideWechatGuide, removeWechatGuide, sdk, showWechatGuide, tracking };
273
+ export { sdk as default, hideWechatGuide, removeWechatGuide, sdk, showWechatGuide };