@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/LICENSE +21 -21
- package/defines.d.ts +130 -130
- package/dist/esm/index.js +100 -392
- package/dist/iife/index.js +149 -204
- package/dist/index.d.mts +61 -234
- package/dist/index.d.ts +61 -234
- package/dist/index.js +101 -394
- package/package.json +56 -52
package/dist/iife/index.js
CHANGED
|
@@ -159,7 +159,7 @@
|
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
//
|
|
162
|
+
// node_modules/@playcraft/ads-tracking/dist/esm/index.js
|
|
163
163
|
function getCurrentAdNetwork(adNetwork) {
|
|
164
164
|
const network = adNetwork || (typeof AD_NETWORK !== "undefined" ? AD_NETWORK : "");
|
|
165
165
|
const supportedNetworks = ["bigabid", "inmobi", "applovin"];
|
|
@@ -175,19 +175,19 @@
|
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
177
|
function trackBigabidEvent(event) {
|
|
178
|
-
console.log("
|
|
178
|
+
console.log("trackBigabidEvent", event);
|
|
179
179
|
if (window.BIGABID_BIDTIMEMACROS && window.BIGABID_BIDTIMEMACROS[event]) {
|
|
180
180
|
trackURL(window.BIGABID_BIDTIMEMACROS[event]);
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
function trackInMobiEvent(event) {
|
|
184
|
-
console.log("
|
|
184
|
+
console.log("trackInMobiEvent", event);
|
|
185
185
|
if (window.INMOBI_DSPMACROS && window.INMOBI_DSPMACROS[event]) {
|
|
186
186
|
trackURL(window.INMOBI_DSPMACROS[event]);
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
function trackApplovinEvent(event) {
|
|
190
|
-
console.log("
|
|
190
|
+
console.log("trackApplovinEvent", event);
|
|
191
191
|
if (typeof window.ALPlayableAnalytics !== "undefined") {
|
|
192
192
|
window.ALPlayableAnalytics.trackEvent(event);
|
|
193
193
|
}
|
|
@@ -213,13 +213,8 @@
|
|
|
213
213
|
}
|
|
214
214
|
inmobiTimers = [];
|
|
215
215
|
}
|
|
216
|
-
var totalInteractions = 0;
|
|
217
216
|
var progressMilestones = [];
|
|
218
|
-
function setTotalInteractions(total) {
|
|
219
|
-
totalInteractions = total;
|
|
220
|
-
}
|
|
221
217
|
function initProgressMilestones(adNetwork) {
|
|
222
|
-
if (totalInteractions <= 0) return;
|
|
223
218
|
const network = getCurrentAdNetwork(adNetwork);
|
|
224
219
|
if (!network) return;
|
|
225
220
|
if (network === "applovin") {
|
|
@@ -227,25 +222,25 @@
|
|
|
227
222
|
{ percent: 25, triggered: false, callback: () => trackApplovinEvent("CHALLENGE_PASS_25") },
|
|
228
223
|
{ percent: 50, triggered: false, callback: () => trackApplovinEvent("CHALLENGE_PASS_50") },
|
|
229
224
|
{ percent: 75, triggered: false, callback: () => trackApplovinEvent("CHALLENGE_PASS_75") },
|
|
230
|
-
{ percent: 100, triggered: false, callback: () =>
|
|
225
|
+
{ percent: 100, triggered: false, callback: () => onPlaycraftChallengeSuccess(adNetwork) }
|
|
231
226
|
];
|
|
232
227
|
} else if (network === "bigabid") {
|
|
233
228
|
progressMilestones = [
|
|
234
|
-
{ percent: 100, triggered: false, callback: () =>
|
|
229
|
+
{ percent: 100, triggered: false, callback: () => onPlaycraftChallengeSuccess(adNetwork) }
|
|
235
230
|
];
|
|
236
231
|
}
|
|
237
232
|
}
|
|
238
|
-
function
|
|
239
|
-
if (
|
|
240
|
-
const
|
|
233
|
+
function onPlaycraftChallengeProgress(percent) {
|
|
234
|
+
if (progressMilestones.length === 0) return;
|
|
235
|
+
const clampedPercent = Math.min(100, Math.max(0, percent));
|
|
241
236
|
for (const milestone of progressMilestones) {
|
|
242
|
-
if (!milestone.triggered &&
|
|
237
|
+
if (!milestone.triggered && clampedPercent >= milestone.percent) {
|
|
243
238
|
milestone.triggered = true;
|
|
244
239
|
milestone.callback();
|
|
245
240
|
}
|
|
246
241
|
}
|
|
247
242
|
}
|
|
248
|
-
function
|
|
243
|
+
function onPlaycraftTrackingInit(adNetwork) {
|
|
249
244
|
initProgressMilestones(adNetwork);
|
|
250
245
|
const network = getCurrentAdNetwork(adNetwork);
|
|
251
246
|
if (!network) return;
|
|
@@ -259,7 +254,7 @@
|
|
|
259
254
|
trackApplovinEvent("LOADING");
|
|
260
255
|
}
|
|
261
256
|
}
|
|
262
|
-
function
|
|
257
|
+
function onPlaycraftTrackingLoading(adNetwork) {
|
|
263
258
|
const network = getCurrentAdNetwork(adNetwork);
|
|
264
259
|
if (!network) return;
|
|
265
260
|
if (network === "bigabid") {
|
|
@@ -273,14 +268,14 @@
|
|
|
273
268
|
trackApplovinEvent("LOADED");
|
|
274
269
|
}
|
|
275
270
|
}
|
|
276
|
-
function
|
|
271
|
+
function onPlaycraftTrackingLoaded(adNetwork) {
|
|
277
272
|
const network = getCurrentAdNetwork(adNetwork);
|
|
278
273
|
if (!network) return;
|
|
279
274
|
if (network === "applovin") {
|
|
280
275
|
trackApplovinEvent("DISPLAYED");
|
|
281
276
|
}
|
|
282
277
|
}
|
|
283
|
-
function
|
|
278
|
+
function onPlaycraftChallengeStart(adNetwork) {
|
|
284
279
|
const network = getCurrentAdNetwork(adNetwork);
|
|
285
280
|
if (!network) return;
|
|
286
281
|
if (network === "bigabid") {
|
|
@@ -293,10 +288,20 @@
|
|
|
293
288
|
trackApplovinEvent("CHALLENGE_STARTED");
|
|
294
289
|
}
|
|
295
290
|
}
|
|
296
|
-
function
|
|
297
|
-
|
|
291
|
+
function onPlaycraftChallengeSuccess(adNetwork) {
|
|
292
|
+
const network = getCurrentAdNetwork(adNetwork);
|
|
293
|
+
if (!network) return;
|
|
294
|
+
if (network === "applovin") {
|
|
295
|
+
trackApplovinEvent("CHALLENGE_SOLVED");
|
|
296
|
+
}
|
|
297
|
+
if (network === "bigabid") {
|
|
298
|
+
trackBigabidComplete();
|
|
299
|
+
}
|
|
300
|
+
if (network === "inmobi") {
|
|
301
|
+
trackInMobiEvent("Gameplay_Complete");
|
|
302
|
+
}
|
|
298
303
|
}
|
|
299
|
-
function
|
|
304
|
+
function onPlaycraftChallengeFinish(adNetwork) {
|
|
300
305
|
const network = getCurrentAdNetwork(adNetwork);
|
|
301
306
|
if (!network) return;
|
|
302
307
|
if (network === "bigabid") {
|
|
@@ -310,7 +315,7 @@
|
|
|
310
315
|
trackApplovinEvent("ENDCARD_SHOWN");
|
|
311
316
|
}
|
|
312
317
|
}
|
|
313
|
-
function
|
|
318
|
+
function onPlaycraftInstall(adNetwork) {
|
|
314
319
|
const network = getCurrentAdNetwork(adNetwork);
|
|
315
320
|
if (!network) return;
|
|
316
321
|
if (network === "bigabid") {
|
|
@@ -324,27 +329,14 @@
|
|
|
324
329
|
trackApplovinEvent("CTA_CLICKED");
|
|
325
330
|
}
|
|
326
331
|
}
|
|
327
|
-
function
|
|
332
|
+
function onPlaycraftRetry(adNetwork) {
|
|
328
333
|
const network = getCurrentAdNetwork(adNetwork);
|
|
329
334
|
if (!network) return;
|
|
330
335
|
if (network === "applovin") {
|
|
331
336
|
trackApplovinEvent("CHALLENGE_RETRY");
|
|
332
337
|
}
|
|
333
338
|
}
|
|
334
|
-
function
|
|
335
|
-
const network = getCurrentAdNetwork(adNetwork);
|
|
336
|
-
if (!network) return;
|
|
337
|
-
if (network === "applovin") {
|
|
338
|
-
trackApplovinEvent("CHALLENGE_SOLVED");
|
|
339
|
-
}
|
|
340
|
-
if (network === "bigabid") {
|
|
341
|
-
trackBigabidComplete();
|
|
342
|
-
}
|
|
343
|
-
if (network === "inmobi") {
|
|
344
|
-
trackInMobiEvent("Gameplay_Complete");
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
function _trackChallengeFailed(adNetwork) {
|
|
339
|
+
function onPlaycraftChallengeFailed(adNetwork) {
|
|
348
340
|
const network = getCurrentAdNetwork(adNetwork);
|
|
349
341
|
if (!network) return;
|
|
350
342
|
if (network === "applovin") {
|
|
@@ -353,65 +345,55 @@
|
|
|
353
345
|
}
|
|
354
346
|
var tracking = {
|
|
355
347
|
/**
|
|
356
|
-
* SDK
|
|
348
|
+
* SDK 初始化开始,同时初始化进度里程碑
|
|
357
349
|
* @param adNetwork - 可选的广告渠道名称
|
|
358
350
|
*/
|
|
359
|
-
|
|
351
|
+
onPlaycraftTrackingInit,
|
|
360
352
|
/**
|
|
361
|
-
*
|
|
353
|
+
* 游戏资源加载中
|
|
362
354
|
* @param adNetwork - 可选的广告渠道名称
|
|
363
355
|
*/
|
|
364
|
-
|
|
356
|
+
onPlaycraftTrackingLoading,
|
|
365
357
|
/**
|
|
366
|
-
*
|
|
358
|
+
* 游戏资源加载完成、主场景就绪
|
|
367
359
|
* @param adNetwork - 可选的广告渠道名称
|
|
368
360
|
*/
|
|
369
|
-
|
|
361
|
+
onPlaycraftTrackingLoaded,
|
|
370
362
|
/**
|
|
371
|
-
*
|
|
363
|
+
* 游戏挑战开始(首次用户交互)
|
|
372
364
|
* @param adNetwork - 可选的广告渠道名称
|
|
373
365
|
*/
|
|
374
|
-
|
|
366
|
+
onPlaycraftChallengeStart,
|
|
375
367
|
/**
|
|
376
|
-
*
|
|
377
|
-
* @param
|
|
368
|
+
* 上报游戏挑战进度(0-100),内部自动触发对应里程碑,不重复上报
|
|
369
|
+
* @param percent - 当前进度百分比(0-100)
|
|
378
370
|
*/
|
|
379
|
-
|
|
371
|
+
onPlaycraftChallengeProgress,
|
|
380
372
|
/**
|
|
381
|
-
*
|
|
373
|
+
* 游戏挑战成功
|
|
382
374
|
* @param adNetwork - 可选的广告渠道名称
|
|
383
375
|
*/
|
|
384
|
-
|
|
376
|
+
onPlaycraftChallengeSuccess,
|
|
385
377
|
/**
|
|
386
|
-
*
|
|
378
|
+
* 游戏结束
|
|
387
379
|
* @param adNetwork - 可选的广告渠道名称
|
|
388
380
|
*/
|
|
389
|
-
|
|
381
|
+
onPlaycraftChallengeFinish,
|
|
390
382
|
/**
|
|
391
|
-
*
|
|
383
|
+
* 点击安装
|
|
392
384
|
* @param adNetwork - 可选的广告渠道名称
|
|
393
385
|
*/
|
|
394
|
-
|
|
395
|
-
/**
|
|
396
|
-
* 设置交互总数(用于进度百分比计算)
|
|
397
|
-
* @param total - 交互总数
|
|
398
|
-
*/
|
|
399
|
-
setTotalInteractions,
|
|
386
|
+
onPlaycraftInstall,
|
|
400
387
|
/**
|
|
401
|
-
*
|
|
402
|
-
* @param currentInteractions - 当前交互次数
|
|
403
|
-
*/
|
|
404
|
-
checkInteractionProgress,
|
|
405
|
-
/**
|
|
406
|
-
* 触发游戏成功事件
|
|
388
|
+
* 重试游戏
|
|
407
389
|
* @param adNetwork - 可选的广告渠道名称
|
|
408
390
|
*/
|
|
409
|
-
|
|
391
|
+
onPlaycraftRetry,
|
|
410
392
|
/**
|
|
411
|
-
*
|
|
393
|
+
* 游戏挑战失败
|
|
412
394
|
* @param adNetwork - 可选的广告渠道名称
|
|
413
395
|
*/
|
|
414
|
-
|
|
396
|
+
onPlaycraftChallengeFailed
|
|
415
397
|
};
|
|
416
398
|
|
|
417
399
|
// src/tracking-init.ts
|
|
@@ -420,14 +402,16 @@
|
|
|
420
402
|
if (!supportedNetworks.includes(AD_NETWORK)) {
|
|
421
403
|
return;
|
|
422
404
|
}
|
|
423
|
-
sdk.once("
|
|
424
|
-
sdk.once("
|
|
425
|
-
sdk.once("
|
|
426
|
-
sdk.
|
|
427
|
-
sdk.on("
|
|
428
|
-
sdk.once("
|
|
429
|
-
sdk.on("
|
|
430
|
-
sdk.once("
|
|
405
|
+
sdk.once("playcraftInit", tracking.onPlaycraftTrackingInit);
|
|
406
|
+
sdk.once("playcraftStart", tracking.onPlaycraftTrackingLoading);
|
|
407
|
+
sdk.once("playcraftInteractive", tracking.onPlaycraftTrackingLoaded);
|
|
408
|
+
sdk.on("playcraftChallengeStart", tracking.onPlaycraftChallengeStart);
|
|
409
|
+
sdk.on("playcraftChallengeProgress", tracking.onPlaycraftChallengeProgress);
|
|
410
|
+
sdk.once("playcraftFinish", tracking.onPlaycraftChallengeFinish);
|
|
411
|
+
sdk.on("playcraftInstall", tracking.onPlaycraftInstall);
|
|
412
|
+
sdk.once("playcraftRetry", tracking.onPlaycraftRetry);
|
|
413
|
+
sdk.on("playcraftChallengeSuccess", tracking.onPlaycraftChallengeSuccess);
|
|
414
|
+
sdk.on("playcraftChallengeFailed", tracking.onPlaycraftChallengeFailed);
|
|
431
415
|
}
|
|
432
416
|
|
|
433
417
|
// src/assets/images.ts
|
|
@@ -773,16 +757,16 @@
|
|
|
773
757
|
};
|
|
774
758
|
function bootAd() {
|
|
775
759
|
if (sdk.isReady) return;
|
|
776
|
-
emitEvent("
|
|
760
|
+
emitEvent("playcraftInit");
|
|
777
761
|
document.body.oncontextmenu = function() {
|
|
778
762
|
return false;
|
|
779
763
|
};
|
|
780
764
|
initCallback(sdk.maxWidth, sdk.maxHeight);
|
|
781
|
-
emitEvent("
|
|
765
|
+
emitEvent("playcraftReady");
|
|
782
766
|
sdk.isReady = true;
|
|
783
767
|
}
|
|
784
768
|
function fireVolumeChange(value) {
|
|
785
|
-
emitEvent("
|
|
769
|
+
emitEvent("playcraftVolume", value);
|
|
786
770
|
}
|
|
787
771
|
function changeVolume(value) {
|
|
788
772
|
sdk.volume = value;
|
|
@@ -795,13 +779,13 @@
|
|
|
795
779
|
function handlePause() {
|
|
796
780
|
changeVolume(0);
|
|
797
781
|
sdk.isPaused = true;
|
|
798
|
-
emitEvent("
|
|
782
|
+
emitEvent("playcraftPause");
|
|
799
783
|
}
|
|
800
784
|
function handleResume() {
|
|
801
785
|
if (isForcePaused) return;
|
|
802
786
|
changeVolume(actualVolume);
|
|
803
787
|
sdk.isPaused = false;
|
|
804
|
-
emitEvent("
|
|
788
|
+
emitEvent("playcraftResume");
|
|
805
789
|
}
|
|
806
790
|
function fireResizeEvent(width, height) {
|
|
807
791
|
handleResize(width, height);
|
|
@@ -984,7 +968,7 @@
|
|
|
984
968
|
const tapjoyApi = {
|
|
985
969
|
skipAd: function() {
|
|
986
970
|
try {
|
|
987
|
-
sdk.
|
|
971
|
+
sdk.playcraftFinish();
|
|
988
972
|
} catch (e) {
|
|
989
973
|
console.warn("Could not skip ad! | " + e);
|
|
990
974
|
}
|
|
@@ -1003,7 +987,7 @@
|
|
|
1003
987
|
sdk.maxWidth = Math.floor(width || window.innerWidth);
|
|
1004
988
|
sdk.maxHeight = Math.floor(height || window.innerHeight);
|
|
1005
989
|
sdk.isLandscape = sdk.maxWidth > sdk.maxHeight;
|
|
1006
|
-
emitEvent("
|
|
990
|
+
emitEvent("playcraftResize", sdk.maxWidth, sdk.maxHeight);
|
|
1007
991
|
}
|
|
1008
992
|
var isListeningToTouchEvents = false;
|
|
1009
993
|
var isTouchEventRegistered = false;
|
|
@@ -1013,7 +997,7 @@
|
|
|
1013
997
|
}
|
|
1014
998
|
if (isListeningToTouchEvents && event instanceof MouseEvent) return;
|
|
1015
999
|
sdk.interactions += 1;
|
|
1016
|
-
emitEvent("
|
|
1000
|
+
emitEvent("playcraftInteraction", sdk.interactions);
|
|
1017
1001
|
}
|
|
1018
1002
|
function registerTouchHandlers() {
|
|
1019
1003
|
if (!isTouchEventRegistered) {
|
|
@@ -1097,35 +1081,21 @@
|
|
|
1097
1081
|
* This must be called as earlier as possible.
|
|
1098
1082
|
*
|
|
1099
1083
|
* @param callback Optional function called when ad container is ready
|
|
1100
|
-
* @param options Optional configuration options
|
|
1101
|
-
* @param options.totalSuccessCount Total number of successful actions expected for progress tracking.
|
|
1102
|
-
* When set, the SDK will track success progress as a percentage and trigger
|
|
1103
|
-
* channel-specific milestone events (e.g., AppLovin: CHALLENGE_PASS_25/50/75, CHALLENGE_SOLVED).
|
|
1104
|
-
* Different channels monitor different percentage thresholds independently.
|
|
1105
|
-
* Set to 0 or omit to disable progress tracking.
|
|
1106
1084
|
* @example
|
|
1107
1085
|
* // Basic initialization
|
|
1108
|
-
* sdk.
|
|
1086
|
+
* sdk.playcraftInit();
|
|
1109
1087
|
*
|
|
1110
1088
|
* // Initialization with callback
|
|
1111
|
-
* sdk.
|
|
1089
|
+
* sdk.playcraftInit((width, height) => {
|
|
1112
1090
|
* new App(width, height)
|
|
1113
1091
|
* });
|
|
1114
1092
|
*
|
|
1115
|
-
*
|
|
1116
|
-
*
|
|
1117
|
-
* new App(width, height)
|
|
1118
|
-
* }, { totalSuccessCount: 20 });
|
|
1119
|
-
*
|
|
1120
|
-
* @fires loading When SDK initialization starts
|
|
1121
|
-
* @fires loaded When game instance is created and ready to load resources
|
|
1093
|
+
* @fires playcraftInit When SDK initialization starts
|
|
1094
|
+
* @fires playcraftReady When game instance is created and ready to load resources
|
|
1122
1095
|
*/
|
|
1123
|
-
static
|
|
1096
|
+
static playcraftInit(callback) {
|
|
1124
1097
|
if (isSDKInitialized) return;
|
|
1125
1098
|
if (callback) initCallback = callback;
|
|
1126
|
-
if ((options == null ? void 0 : options.totalSuccessCount) && options.totalSuccessCount > 0) {
|
|
1127
|
-
tracking.setTotalInteractions(options.totalSuccessCount);
|
|
1128
|
-
}
|
|
1129
1099
|
initTrackingProtocols();
|
|
1130
1100
|
document.readyState === "loading" ? window.addEventListener("DOMContentLoaded", initSDK) : initSDK();
|
|
1131
1101
|
isSDKInitialized = true;
|
|
@@ -1135,25 +1105,24 @@
|
|
|
1135
1105
|
* Should be called after all resources are loaded and first frame is rendered.
|
|
1136
1106
|
*
|
|
1137
1107
|
* @example
|
|
1138
|
-
*
|
|
1139
|
-
* sdk.start();
|
|
1108
|
+
* sdk.playcraftStart();
|
|
1140
1109
|
*
|
|
1141
|
-
* @fires
|
|
1142
|
-
* @fires
|
|
1110
|
+
* @fires playcraftStart When the playable ad starts
|
|
1111
|
+
* @fires playcraftResize When the ad container is initially sized
|
|
1143
1112
|
*/
|
|
1144
|
-
static
|
|
1113
|
+
static playcraftStart() {
|
|
1145
1114
|
if (_sdk.isStarted) return;
|
|
1146
1115
|
_sdk.isStarted = true;
|
|
1147
|
-
emitEvent("
|
|
1116
|
+
emitEvent("playcraftStart");
|
|
1148
1117
|
registerTouchHandlers();
|
|
1149
1118
|
if ("mintegral" === AD_NETWORK && isMintegral()) {
|
|
1150
|
-
_sdk.
|
|
1119
|
+
_sdk.playcraftResize();
|
|
1151
1120
|
handlePause();
|
|
1152
1121
|
window.gameReady && window.gameReady();
|
|
1153
1122
|
} else if ("bigoads" === AD_NETWORK && isBigoAds()) {
|
|
1154
1123
|
window.BGY_MRAID && window.BGY_MRAID.gameReady && window.BGY_MRAID.gameReady();
|
|
1155
1124
|
fireVolumeChange(_sdk.volume);
|
|
1156
|
-
_sdk.
|
|
1125
|
+
_sdk.playcraftResize();
|
|
1157
1126
|
} else {
|
|
1158
1127
|
if ("tapjoy" === AD_NETWORK && isTapjoy()) {
|
|
1159
1128
|
window.TJ_API.setPlayableBuild({
|
|
@@ -1162,7 +1131,7 @@
|
|
|
1162
1131
|
});
|
|
1163
1132
|
}
|
|
1164
1133
|
fireVolumeChange(_sdk.volume);
|
|
1165
|
-
_sdk.
|
|
1134
|
+
_sdk.playcraftResize();
|
|
1166
1135
|
}
|
|
1167
1136
|
}
|
|
1168
1137
|
/**
|
|
@@ -1170,28 +1139,39 @@
|
|
|
1170
1139
|
* Should be called at the end of your main game scene's create() method.
|
|
1171
1140
|
*
|
|
1172
1141
|
* @example
|
|
1173
|
-
* // In Phaser MainScene.create()
|
|
1174
1142
|
* create() {
|
|
1175
1143
|
* // ... all initialization code ...
|
|
1176
|
-
* sdk.
|
|
1144
|
+
* sdk.playcraftInteractive();
|
|
1177
1145
|
* }
|
|
1178
1146
|
*
|
|
1179
|
-
* @fires
|
|
1147
|
+
* @fires playcraftInteractive When the main scene is ready for user interaction
|
|
1180
1148
|
*/
|
|
1181
|
-
static
|
|
1182
|
-
emitEvent("
|
|
1149
|
+
static playcraftInteractive() {
|
|
1150
|
+
emitEvent("playcraftInteractive");
|
|
1151
|
+
}
|
|
1152
|
+
/**
|
|
1153
|
+
* Marks the challenge as started.
|
|
1154
|
+
* Should be called by business logic when the user actually starts playing.
|
|
1155
|
+
*
|
|
1156
|
+
* @example
|
|
1157
|
+
* onFirstClick() {
|
|
1158
|
+
* sdk.playcraftChallengeStart();
|
|
1159
|
+
* }
|
|
1160
|
+
*
|
|
1161
|
+
* @fires playcraftChallengeStart When the challenge starts
|
|
1162
|
+
*/
|
|
1163
|
+
static playcraftChallengeStart() {
|
|
1164
|
+
emitEvent("playcraftChallengeStart");
|
|
1183
1165
|
}
|
|
1184
1166
|
/**
|
|
1185
1167
|
* Marks the playable ad as finished.
|
|
1186
|
-
* This triggers network-specific completion handlers.
|
|
1187
1168
|
*
|
|
1188
1169
|
* @example
|
|
1189
|
-
*
|
|
1190
|
-
* sdk.finish();
|
|
1170
|
+
* sdk.playcraftFinish();
|
|
1191
1171
|
*
|
|
1192
|
-
* @fires
|
|
1172
|
+
* @fires playcraftFinish When the playable ad is marked as finished
|
|
1193
1173
|
*/
|
|
1194
|
-
static
|
|
1174
|
+
static playcraftFinish() {
|
|
1195
1175
|
_sdk.isFinished = true;
|
|
1196
1176
|
if ("tapjoy" === AD_NETWORK && isTapjoy()) {
|
|
1197
1177
|
finishTapjoy();
|
|
@@ -1211,38 +1191,34 @@
|
|
|
1211
1191
|
console.warn("Could not call mraid.close():", e);
|
|
1212
1192
|
}
|
|
1213
1193
|
}
|
|
1214
|
-
emitEvent("
|
|
1194
|
+
emitEvent("playcraftFinish");
|
|
1215
1195
|
}
|
|
1216
1196
|
/**
|
|
1217
1197
|
* Triggers a retry/restart of the playable ad.
|
|
1218
|
-
* Behavior varies by ad network.
|
|
1219
1198
|
*
|
|
1220
1199
|
* @example
|
|
1221
|
-
*
|
|
1222
|
-
* retryButton.onclick = () => sdk.retry();
|
|
1200
|
+
* retryButton.onclick = () => sdk.playcraftRetry();
|
|
1223
1201
|
*
|
|
1224
|
-
* @fires
|
|
1202
|
+
* @fires playcraftRetry When a retry is triggered
|
|
1225
1203
|
*/
|
|
1226
|
-
static
|
|
1204
|
+
static playcraftRetry() {
|
|
1227
1205
|
if ("mintegral" === AD_NETWORK && isMintegral()) {
|
|
1228
1206
|
} else if ("nucleo" === AD_PROTOCOL && isNucleo()) {
|
|
1229
1207
|
NUC.trigger.tryAgain();
|
|
1230
1208
|
}
|
|
1231
|
-
emitEvent("
|
|
1209
|
+
emitEvent("playcraftRetry");
|
|
1232
1210
|
}
|
|
1233
1211
|
/**
|
|
1234
1212
|
* Triggers the install/download action for the advertised app.
|
|
1235
|
-
* Handles different store opening methods across ad networks.
|
|
1236
1213
|
*
|
|
1237
1214
|
* @example
|
|
1238
|
-
*
|
|
1239
|
-
* installButton.onclick = () => sdk.install();
|
|
1215
|
+
* installButton.onclick = () => sdk.playcraftInstall();
|
|
1240
1216
|
*
|
|
1241
|
-
* @fires
|
|
1242
|
-
* @fires
|
|
1217
|
+
* @fires playcraftFinish If the ad hasn't been marked as finished
|
|
1218
|
+
* @fires playcraftInstall When the install action is triggered
|
|
1243
1219
|
*/
|
|
1244
|
-
static
|
|
1245
|
-
console.log("[SDK]
|
|
1220
|
+
static playcraftInstall(params) {
|
|
1221
|
+
console.log("[SDK] playcraftInstall() called, interactions:", _sdk.interactions, "isFinished:", _sdk.isFinished, "isInstallClicked:", isInstallClicked);
|
|
1246
1222
|
if (_sdk.interactions < 1 && isDisableFirstClickToOpenApp()) {
|
|
1247
1223
|
console.log("[SDK] \u9996\u6B21\u70B9\u51FB\u4FDD\u62A4\uFF0C\u76F4\u63A5\u8FD4\u56DE");
|
|
1248
1224
|
return;
|
|
@@ -1252,23 +1228,23 @@
|
|
|
1252
1228
|
return;
|
|
1253
1229
|
}
|
|
1254
1230
|
const timeout = setTimeout(function() {
|
|
1255
|
-
_sdk.
|
|
1231
|
+
_sdk.playcraftInstall();
|
|
1256
1232
|
clearTimeout(timeout);
|
|
1257
1233
|
}, params.timeout || 3e3);
|
|
1258
1234
|
return;
|
|
1259
1235
|
}
|
|
1260
1236
|
if (!_sdk.isFinished) {
|
|
1261
|
-
console.log("[SDK] \u9996\u6B21\u6267\u884C
|
|
1237
|
+
console.log("[SDK] \u9996\u6B21\u6267\u884C playcraftInstall\uFF0C\u89E6\u53D1 playcraftFinish \u4E8B\u4EF6");
|
|
1262
1238
|
_sdk.isFinished = true;
|
|
1263
1239
|
let timeout = 0;
|
|
1264
1240
|
if ("tapjoy" === AD_NETWORK && isTapjoy()) {
|
|
1265
1241
|
finishTapjoy();
|
|
1266
1242
|
timeout = 300;
|
|
1267
1243
|
}
|
|
1268
|
-
emitEvent("
|
|
1244
|
+
emitEvent("playcraftFinish");
|
|
1269
1245
|
setTimeout(function() {
|
|
1270
|
-
console.log("[SDK] \u5F02\u6B65\u9012\u5F52\u8C03\u7528
|
|
1271
|
-
_sdk.
|
|
1246
|
+
console.log("[SDK] \u5F02\u6B65\u9012\u5F52\u8C03\u7528 playcraftInstall()");
|
|
1247
|
+
_sdk.playcraftInstall();
|
|
1272
1248
|
}, timeout);
|
|
1273
1249
|
return;
|
|
1274
1250
|
}
|
|
@@ -1281,7 +1257,7 @@
|
|
|
1281
1257
|
isInstallClicked = false;
|
|
1282
1258
|
console.log("[SDK] \u9632\u6296\u89E3\u9501");
|
|
1283
1259
|
}, 500);
|
|
1284
|
-
emitEvent("
|
|
1260
|
+
emitEvent("playcraftInstall");
|
|
1285
1261
|
console.log("Ad_Protocal: ", AD_PROTOCOL);
|
|
1286
1262
|
if ("mraid" === AD_PROTOCOL && isMraid()) {
|
|
1287
1263
|
try {
|
|
@@ -1345,39 +1321,30 @@
|
|
|
1345
1321
|
}
|
|
1346
1322
|
/**
|
|
1347
1323
|
* Trigger force resize event
|
|
1348
|
-
* Useful when container size changes need to be manually propagated.
|
|
1349
1324
|
*
|
|
1350
1325
|
* @example
|
|
1351
|
-
* sdk.
|
|
1326
|
+
* sdk.playcraftResize();
|
|
1352
1327
|
*
|
|
1353
|
-
* @fires
|
|
1328
|
+
* @fires playcraftResize With current maxWidth and maxHeight
|
|
1354
1329
|
*/
|
|
1355
|
-
static
|
|
1330
|
+
static playcraftResize() {
|
|
1356
1331
|
handleResize(_sdk.maxWidth, _sdk.maxHeight);
|
|
1357
1332
|
}
|
|
1358
1333
|
/**
|
|
1359
|
-
* Records
|
|
1360
|
-
*
|
|
1361
|
-
*
|
|
1334
|
+
* Records playable ad challenge progress (0-100).
|
|
1335
|
+
* Triggers channel-specific milestone events based on the progress value.
|
|
1336
|
+
* Milestones are not re-triggered once fired.
|
|
1337
|
+
*
|
|
1338
|
+
* @param percent Progress percentage (0-100)
|
|
1362
1339
|
*
|
|
1363
|
-
* @param count Optional success count to add (default: 1)
|
|
1364
|
-
*
|
|
1365
1340
|
* @example
|
|
1366
|
-
* //
|
|
1367
|
-
*
|
|
1368
|
-
* sdk.recordSuccessCount();
|
|
1369
|
-
* }
|
|
1370
|
-
*
|
|
1371
|
-
* // Record multiple successes at once
|
|
1372
|
-
* onComboMatch(comboCount) {
|
|
1373
|
-
* sdk.recordSuccessCount(comboCount);
|
|
1374
|
-
* }
|
|
1341
|
+
* // Report 50% progress
|
|
1342
|
+
* sdk.recordPlaycraftChallengeProgress(50);
|
|
1375
1343
|
*
|
|
1376
|
-
* @fires
|
|
1344
|
+
* @fires playcraftChallengeProgress With the progress percentage value
|
|
1377
1345
|
*/
|
|
1378
|
-
static
|
|
1379
|
-
|
|
1380
|
-
emitEvent("success", _sdk.successCount);
|
|
1346
|
+
static recordPlaycraftChallengeProgress(percent) {
|
|
1347
|
+
emitEvent("playcraftChallengeProgress", percent);
|
|
1381
1348
|
}
|
|
1382
1349
|
/**
|
|
1383
1350
|
* Records a game success/completion event.
|
|
@@ -1387,13 +1354,12 @@
|
|
|
1387
1354
|
* - InMobi: Gameplay_Complete
|
|
1388
1355
|
*
|
|
1389
1356
|
* @example
|
|
1390
|
-
* // When player completes the level
|
|
1391
1357
|
* onLevelComplete() {
|
|
1392
|
-
* sdk.
|
|
1358
|
+
* sdk.playcraftRecordSuccess();
|
|
1393
1359
|
* }
|
|
1394
1360
|
*/
|
|
1395
|
-
static
|
|
1396
|
-
|
|
1361
|
+
static playcraftRecordSuccess() {
|
|
1362
|
+
emitEvent("playcraftChallengeSuccess");
|
|
1397
1363
|
}
|
|
1398
1364
|
/**
|
|
1399
1365
|
* Records a game failure event.
|
|
@@ -1401,24 +1367,22 @@
|
|
|
1401
1367
|
* - AppLovin: CHALLENGE_FAILED
|
|
1402
1368
|
*
|
|
1403
1369
|
* @example
|
|
1404
|
-
* // When player fails the level
|
|
1405
1370
|
* onLevelFailed() {
|
|
1406
|
-
* sdk.
|
|
1371
|
+
* sdk.playcraftRecordFailed();
|
|
1407
1372
|
* }
|
|
1408
1373
|
*/
|
|
1409
|
-
static
|
|
1410
|
-
|
|
1374
|
+
static playcraftRecordFailed() {
|
|
1375
|
+
emitEvent("playcraftChallengeFailed");
|
|
1411
1376
|
}
|
|
1412
1377
|
/**
|
|
1413
1378
|
* Forces the playable ad into a paused state.
|
|
1414
1379
|
*
|
|
1415
1380
|
* @example
|
|
1416
|
-
*
|
|
1417
|
-
* pauseButton.onclick = () => sdk.pause();
|
|
1381
|
+
* pauseButton.onclick = () => sdk.playcraftPause();
|
|
1418
1382
|
*
|
|
1419
|
-
* @fires
|
|
1383
|
+
* @fires playcraftPause When the ad enters paused state
|
|
1420
1384
|
*/
|
|
1421
|
-
static
|
|
1385
|
+
static playcraftPause() {
|
|
1422
1386
|
if (!isForcePaused) {
|
|
1423
1387
|
isForcePaused = true;
|
|
1424
1388
|
handlePause();
|
|
@@ -1426,15 +1390,13 @@
|
|
|
1426
1390
|
}
|
|
1427
1391
|
/**
|
|
1428
1392
|
* Resumes the playable ad from a forced pause state.
|
|
1429
|
-
* Only works if the ad was paused via sdk.pause().
|
|
1430
1393
|
*
|
|
1431
1394
|
* @example
|
|
1432
|
-
*
|
|
1433
|
-
* resumeButton.onclick = () => sdk.resume();
|
|
1395
|
+
* resumeButton.onclick = () => sdk.playcraftResume();
|
|
1434
1396
|
*
|
|
1435
|
-
* @fires
|
|
1397
|
+
* @fires playcraftResume When the ad resumes from pause
|
|
1436
1398
|
*/
|
|
1437
|
-
static
|
|
1399
|
+
static playcraftResume() {
|
|
1438
1400
|
if (isForcePaused) {
|
|
1439
1401
|
isForcePaused = false;
|
|
1440
1402
|
handleResume();
|
|
@@ -1448,15 +1410,9 @@
|
|
|
1448
1410
|
* @param context Optional 'this' context for the callback
|
|
1449
1411
|
*
|
|
1450
1412
|
* @example
|
|
1451
|
-
*
|
|
1452
|
-
* sdk.on('interaction', (count) => {
|
|
1413
|
+
* sdk.on('playcraftInteraction', (count) => {
|
|
1453
1414
|
* console.log(`User interaction #${count}`);
|
|
1454
1415
|
* });
|
|
1455
|
-
*
|
|
1456
|
-
* // Listen for resize with context
|
|
1457
|
-
* sdk.on('resize', function(width, height) {
|
|
1458
|
-
* this.updateLayout(width, height);
|
|
1459
|
-
* }, gameInstance);
|
|
1460
1416
|
*/
|
|
1461
1417
|
static on(event, fn, context) {
|
|
1462
1418
|
onEvent(event, fn, context);
|
|
@@ -1469,8 +1425,7 @@
|
|
|
1469
1425
|
* @param context Optional 'this' context for the callback
|
|
1470
1426
|
*
|
|
1471
1427
|
* @example
|
|
1472
|
-
*
|
|
1473
|
-
* sdk.once('interaction', () => {
|
|
1428
|
+
* sdk.once('playcraftInteraction', () => {
|
|
1474
1429
|
* console.log('First user interaction occurred!');
|
|
1475
1430
|
* });
|
|
1476
1431
|
*/
|
|
@@ -1481,22 +1436,16 @@
|
|
|
1481
1436
|
* Removes an event listener.
|
|
1482
1437
|
*
|
|
1483
1438
|
* @param event Name of the event to stop listening for
|
|
1484
|
-
* @param fn Optional callback function to remove
|
|
1439
|
+
* @param fn Optional callback function to remove
|
|
1485
1440
|
* @param context Optional 'this' context to match when removing
|
|
1486
1441
|
*
|
|
1487
1442
|
* @example
|
|
1488
|
-
*
|
|
1489
|
-
* const handler = () => console.log('Interaction');
|
|
1490
|
-
* sdk.off('interaction', handler);
|
|
1491
|
-
*
|
|
1492
|
-
* // Remove all listeners for an event
|
|
1493
|
-
* sdk.off('interaction');
|
|
1443
|
+
* sdk.off('playcraftInteraction', handler);
|
|
1494
1444
|
*/
|
|
1495
1445
|
static off(event, fn, context) {
|
|
1496
1446
|
offEvent(event, fn, context);
|
|
1497
1447
|
}
|
|
1498
1448
|
/**
|
|
1499
|
-
*
|
|
1500
1449
|
* @returns 当前渠道
|
|
1501
1450
|
*/
|
|
1502
1451
|
static getCurChannel() {
|
|
@@ -1544,7 +1493,7 @@
|
|
|
1544
1493
|
}
|
|
1545
1494
|
};
|
|
1546
1495
|
/** Current version of the SDK */
|
|
1547
|
-
_sdk.version = "1.0.
|
|
1496
|
+
_sdk.version = "1.0.15";
|
|
1548
1497
|
/** Current maximum width of the playable ad container in pixels */
|
|
1549
1498
|
_sdk.maxWidth = Math.floor(window.innerWidth);
|
|
1550
1499
|
/** Current maximum height of the playable ad container in pixels */
|
|
@@ -1563,10 +1512,6 @@
|
|
|
1563
1512
|
_sdk.volume = actualVolume;
|
|
1564
1513
|
/** Number of user interactions with the playable ad (auto-incremented on each touch/click) */
|
|
1565
1514
|
_sdk.interactions = 0;
|
|
1566
|
-
/** Number of successful game actions (e.g., successful matches, level clears).
|
|
1567
|
-
* Controlled by calling sdk.recordSuccessCount(), NOT auto-incremented.
|
|
1568
|
-
*/
|
|
1569
|
-
_sdk.successCount = 0;
|
|
1570
1515
|
var sdk = _sdk;
|
|
1571
1516
|
window["console"].log(
|
|
1572
1517
|
`%c @playcraft/adsdk %c v${sdk.version} `,
|