@playcraft/adsdk 1.0.8 → 1.0.10

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.js CHANGED
@@ -24,7 +24,8 @@ __export(index_exports, {
24
24
  hideWechatGuide: () => hideWechatGuide,
25
25
  removeWechatGuide: () => removeWechatGuide,
26
26
  sdk: () => sdk,
27
- showWechatGuide: () => showWechatGuide
27
+ showWechatGuide: () => showWechatGuide,
28
+ tracking: () => tracking
28
29
  });
29
30
  module.exports = __toCommonJS(index_exports);
30
31
 
@@ -188,6 +189,14 @@ function ensureProtocol() {
188
189
  }
189
190
 
190
191
  // src/tracking.ts
192
+ function getCurrentAdNetwork(adNetwork) {
193
+ const network = adNetwork || (typeof AD_NETWORK !== "undefined" ? AD_NETWORK : "");
194
+ const supportedNetworks = ["bigabid", "inmobi", "applovin"];
195
+ if (supportedNetworks.includes(network)) {
196
+ return network;
197
+ }
198
+ return null;
199
+ }
191
200
  function trackURL(url) {
192
201
  if (url) {
193
202
  const trackingPixel = new Image();
@@ -212,39 +221,46 @@ function trackApplovinEvent(event) {
212
221
  window.ALPlayableAnalytics.trackEvent(event);
213
222
  }
214
223
  }
215
- var totalInteractions = 0;
216
- var progressMilestones = [];
217
- function setTotalInteractions(total) {
218
- totalInteractions = total;
219
- }
220
- function trackChallengeSuccess() {
221
- if (AD_NETWORK === "applovin") {
222
- trackApplovinEvent("CHALLENGE_SOLVED");
223
- }
224
- if (AD_NETWORK === "bigabid") {
225
- trackBigabidComplete();
224
+ var bigabidCompleteTriggered = false;
225
+ function trackBigabidComplete() {
226
+ if (!bigabidCompleteTriggered) {
227
+ trackBigabidEvent("complete");
228
+ bigabidCompleteTriggered = true;
226
229
  }
227
- if (AD_NETWORK === "inmobi") {
228
- trackInMobiEvent("Gameplay_Complete");
230
+ }
231
+ var inmobiTimers = [];
232
+ function startInMobiDurationTracking() {
233
+ const durations = [5, 10, 15, 20, 25, 30];
234
+ for (const sec of durations) {
235
+ const timer = setTimeout(() => trackInMobiEvent(`Spent_${sec}_Seconds`), sec * 1e3);
236
+ inmobiTimers.push(timer);
229
237
  }
230
238
  }
231
- function trackChallengeFailed() {
232
- if (AD_NETWORK === "applovin") {
233
- trackApplovinEvent("CHALLENGE_FAILED");
239
+ function clearInMobiDurationTracking() {
240
+ for (const timer of inmobiTimers) {
241
+ clearTimeout(timer);
234
242
  }
243
+ inmobiTimers = [];
244
+ }
245
+ var totalInteractions = 0;
246
+ var progressMilestones = [];
247
+ function setTotalInteractions(total) {
248
+ totalInteractions = total;
235
249
  }
236
- function initProgressMilestones() {
250
+ function initProgressMilestones(adNetwork) {
237
251
  if (totalInteractions <= 0) return;
238
- if (AD_NETWORK === "applovin") {
252
+ const network = getCurrentAdNetwork(adNetwork);
253
+ if (!network) return;
254
+ if (network === "applovin") {
239
255
  progressMilestones = [
240
256
  { percent: 25, triggered: false, callback: () => trackApplovinEvent("CHALLENGE_PASS_25") },
241
257
  { percent: 50, triggered: false, callback: () => trackApplovinEvent("CHALLENGE_PASS_50") },
242
258
  { percent: 75, triggered: false, callback: () => trackApplovinEvent("CHALLENGE_PASS_75") },
243
- { percent: 100, triggered: false, callback: () => trackChallengeSuccess() }
259
+ { percent: 100, triggered: false, callback: () => _trackChallengeSuccess(adNetwork) }
244
260
  ];
245
- } else if (AD_NETWORK === "bigabid") {
261
+ } else if (network === "bigabid") {
246
262
  progressMilestones = [
247
- { percent: 100, triggered: false, callback: () => trackChallengeSuccess() }
263
+ { percent: 100, triggered: false, callback: () => _trackChallengeSuccess(adNetwork) }
248
264
  ];
249
265
  }
250
266
  }
@@ -258,104 +274,189 @@ function checkInteractionProgress(currentInteractions) {
258
274
  }
259
275
  }
260
276
  }
261
- var bigabidCompleteTriggered = false;
262
- function trackBigabidComplete() {
263
- if (!bigabidCompleteTriggered) {
264
- trackBigabidEvent("complete");
265
- bigabidCompleteTriggered = true;
277
+ function _onInit(adNetwork) {
278
+ initProgressMilestones(adNetwork);
279
+ const network = getCurrentAdNetwork(adNetwork);
280
+ if (!network) return;
281
+ if (network === "bigabid") {
282
+ trackBigabidEvent("mraid_viewable");
283
+ }
284
+ if (network === "inmobi") {
285
+ trackInMobiEvent("Ad_Load_Start");
286
+ }
287
+ if (network === "applovin") {
288
+ trackApplovinEvent("LOADING");
266
289
  }
267
290
  }
268
- var inmobiTimers = [];
269
- function startInMobiDurationTracking() {
270
- const durations = [5, 10, 15, 20, 25, 30];
271
- for (const sec of durations) {
272
- const timer = setTimeout(() => trackInMobiEvent(`Spent_${sec}_Seconds`), sec * 1e3);
273
- inmobiTimers.push(timer);
291
+ function _onStart(adNetwork) {
292
+ const network = getCurrentAdNetwork(adNetwork);
293
+ if (!network) return;
294
+ if (network === "bigabid") {
295
+ trackBigabidEvent("game_viewable");
296
+ }
297
+ if (network === "inmobi") {
298
+ trackInMobiEvent("Ad_Viewable");
299
+ startInMobiDurationTracking();
300
+ }
301
+ if (network === "applovin") {
302
+ trackApplovinEvent("LOADED");
274
303
  }
275
304
  }
276
- function clearInMobiDurationTracking() {
277
- for (const timer of inmobiTimers) {
278
- clearTimeout(timer);
305
+ function _onInteractive(adNetwork) {
306
+ const network = getCurrentAdNetwork(adNetwork);
307
+ if (!network) return;
308
+ if (network === "applovin") {
309
+ trackApplovinEvent("DISPLAYED");
279
310
  }
280
- inmobiTimers = [];
281
311
  }
312
+ function _onInteraction(adNetwork) {
313
+ const network = getCurrentAdNetwork(adNetwork);
314
+ if (!network) return;
315
+ if (network === "bigabid") {
316
+ trackBigabidEvent("engagement");
317
+ }
318
+ if (network === "inmobi") {
319
+ trackInMobiEvent("First_Engagement");
320
+ }
321
+ if (network === "applovin") {
322
+ trackApplovinEvent("CHALLENGE_STARTED");
323
+ }
324
+ }
325
+ function _onSuccess(successCount) {
326
+ checkInteractionProgress(successCount);
327
+ }
328
+ function _onFinish(adNetwork) {
329
+ const network = getCurrentAdNetwork(adNetwork);
330
+ if (!network) return;
331
+ if (network === "bigabid") {
332
+ trackBigabidComplete();
333
+ }
334
+ if (network === "inmobi") {
335
+ trackInMobiEvent("Gameplay_Complete");
336
+ clearInMobiDurationTracking();
337
+ }
338
+ if (network === "applovin") {
339
+ trackApplovinEvent("ENDCARD_SHOWN");
340
+ }
341
+ }
342
+ function _onInstall(adNetwork) {
343
+ const network = getCurrentAdNetwork(adNetwork);
344
+ if (!network) return;
345
+ if (network === "bigabid") {
346
+ trackBigabidEvent("click");
347
+ }
348
+ if (network === "inmobi") {
349
+ trackInMobiEvent("DSP_Click");
350
+ clearInMobiDurationTracking();
351
+ }
352
+ if (network === "applovin") {
353
+ trackApplovinEvent("CTA_CLICKED");
354
+ }
355
+ }
356
+ function _onRetry(adNetwork) {
357
+ const network = getCurrentAdNetwork(adNetwork);
358
+ if (!network) return;
359
+ if (network === "applovin") {
360
+ trackApplovinEvent("CHALLENGE_RETRY");
361
+ }
362
+ }
363
+ function _trackChallengeSuccess(adNetwork) {
364
+ const network = getCurrentAdNetwork(adNetwork);
365
+ if (!network) return;
366
+ if (network === "applovin") {
367
+ trackApplovinEvent("CHALLENGE_SOLVED");
368
+ }
369
+ if (network === "bigabid") {
370
+ trackBigabidComplete();
371
+ }
372
+ if (network === "inmobi") {
373
+ trackInMobiEvent("Gameplay_Complete");
374
+ }
375
+ }
376
+ function _trackChallengeFailed(adNetwork) {
377
+ const network = getCurrentAdNetwork(adNetwork);
378
+ if (!network) return;
379
+ if (network === "applovin") {
380
+ trackApplovinEvent("CHALLENGE_FAILED");
381
+ }
382
+ }
383
+ var tracking = {
384
+ /**
385
+ * SDK 初始化开始
386
+ * @param adNetwork - 可选的广告渠道名称
387
+ */
388
+ onInit: _onInit,
389
+ /**
390
+ * 游戏资源加载完成
391
+ * @param adNetwork - 可选的广告渠道名称
392
+ */
393
+ onStart: _onStart,
394
+ /**
395
+ * 主场景就绪,用户可交互
396
+ * @param adNetwork - 可选的广告渠道名称
397
+ */
398
+ onInteractive: _onInteractive,
399
+ /**
400
+ * 首次交互
401
+ * @param adNetwork - 可选的广告渠道名称
402
+ */
403
+ onInteraction: _onInteraction,
404
+ /**
405
+ * 成功计数(用于进度百分比追踪)
406
+ * @param successCount - 当前成功次数
407
+ */
408
+ onSuccess: _onSuccess,
409
+ /**
410
+ * 游戏结束
411
+ * @param adNetwork - 可选的广告渠道名称
412
+ */
413
+ onFinish: _onFinish,
414
+ /**
415
+ * 点击安装
416
+ * @param adNetwork - 可选的广告渠道名称
417
+ */
418
+ onInstall: _onInstall,
419
+ /**
420
+ * 重试游戏
421
+ * @param adNetwork - 可选的广告渠道名称
422
+ */
423
+ onRetry: _onRetry,
424
+ /**
425
+ * 设置交互总数(用于进度百分比计算)
426
+ * @param total - 交互总数
427
+ */
428
+ setTotalInteractions,
429
+ /**
430
+ * 检查交互进度
431
+ * @param currentInteractions - 当前交互次数
432
+ */
433
+ checkInteractionProgress,
434
+ /**
435
+ * 触发游戏成功事件
436
+ * @param adNetwork - 可选的广告渠道名称
437
+ */
438
+ trackChallengeSuccess: _trackChallengeSuccess,
439
+ /**
440
+ * 触发游戏失败事件
441
+ * @param adNetwork - 可选的广告渠道名称
442
+ */
443
+ trackChallengeFailed: _trackChallengeFailed
444
+ };
445
+
446
+ // src/tracking-init.ts
282
447
  function initTrackingProtocols() {
283
448
  const supportedNetworks = ["bigabid", "inmobi", "applovin"];
284
449
  if (!supportedNetworks.includes(AD_NETWORK)) {
285
450
  return;
286
451
  }
287
- initProgressMilestones();
288
- sdk.once("init", () => {
289
- if (AD_NETWORK === "bigabid") {
290
- trackBigabidEvent("mraid_viewable");
291
- }
292
- if (AD_NETWORK === "inmobi") {
293
- trackInMobiEvent("Ad_Load_Start");
294
- }
295
- if (AD_NETWORK === "applovin") {
296
- trackApplovinEvent("LOADING");
297
- }
298
- });
299
- sdk.once("start", () => {
300
- if (AD_NETWORK === "bigabid") {
301
- trackBigabidEvent("game_viewable");
302
- }
303
- if (AD_NETWORK === "inmobi") {
304
- trackInMobiEvent("Ad_Viewable");
305
- startInMobiDurationTracking();
306
- }
307
- if (AD_NETWORK === "applovin") {
308
- trackApplovinEvent("LOADED");
309
- }
310
- });
311
- sdk.once("interactive", () => {
312
- if (AD_NETWORK === "applovin") {
313
- trackApplovinEvent("DISPLAYED");
314
- }
315
- });
316
- sdk.once("interaction", () => {
317
- if (AD_NETWORK === "bigabid") {
318
- trackBigabidEvent("engagement");
319
- }
320
- if (AD_NETWORK === "inmobi") {
321
- trackInMobiEvent("First_Engagement");
322
- }
323
- if (AD_NETWORK === "applovin") {
324
- trackApplovinEvent("CHALLENGE_STARTED");
325
- }
326
- });
327
- sdk.on("success", (successCount) => {
328
- checkInteractionProgress(successCount);
329
- });
330
- sdk.once("finish", () => {
331
- if (AD_NETWORK === "bigabid") {
332
- trackBigabidComplete();
333
- }
334
- if (AD_NETWORK === "inmobi") {
335
- trackInMobiEvent("Gameplay_Complete");
336
- clearInMobiDurationTracking();
337
- }
338
- if (AD_NETWORK === "applovin") {
339
- trackApplovinEvent("ENDCARD_SHOWN");
340
- }
341
- });
342
- sdk.on("install", () => {
343
- if (AD_NETWORK === "bigabid") {
344
- trackBigabidEvent("click");
345
- }
346
- if (AD_NETWORK === "inmobi") {
347
- trackInMobiEvent("DSP_Click");
348
- clearInMobiDurationTracking();
349
- }
350
- if (AD_NETWORK === "applovin") {
351
- trackApplovinEvent("CTA_CLICKED");
352
- }
353
- });
354
- sdk.once("retry", () => {
355
- if (AD_NETWORK === "applovin") {
356
- trackApplovinEvent("CHALLENGE_RETRY");
357
- }
358
- });
452
+ sdk.once("init", tracking.onInit);
453
+ sdk.once("start", tracking.onStart);
454
+ sdk.once("interactive", tracking.onInteractive);
455
+ sdk.once("interaction", tracking.onInteraction);
456
+ sdk.on("success", tracking.onSuccess);
457
+ sdk.once("finish", tracking.onFinish);
458
+ sdk.on("install", tracking.onInstall);
459
+ sdk.once("retry", tracking.onRetry);
359
460
  }
360
461
 
361
462
  // src/assets/images.ts
@@ -985,7 +1086,7 @@ var _sdk = class _sdk {
985
1086
  if (isSDKInitialized) return;
986
1087
  if (callback) initCallback = callback;
987
1088
  if ((options == null ? void 0 : options.totalSuccessCount) && options.totalSuccessCount > 0) {
988
- setTotalInteractions(options.totalSuccessCount);
1089
+ tracking.setTotalInteractions(options.totalSuccessCount);
989
1090
  }
990
1091
  initTrackingProtocols();
991
1092
  document.readyState === "loading" ? window.addEventListener("DOMContentLoaded", initSDK) : initSDK();
@@ -1254,7 +1355,7 @@ var _sdk = class _sdk {
1254
1355
  * }
1255
1356
  */
1256
1357
  static recordSuccess() {
1257
- trackChallengeSuccess();
1358
+ tracking.trackChallengeSuccess();
1258
1359
  }
1259
1360
  /**
1260
1361
  * Records a game failure event.
@@ -1268,7 +1369,7 @@ var _sdk = class _sdk {
1268
1369
  * }
1269
1370
  */
1270
1371
  static recordFailed() {
1271
- trackChallengeFailed();
1372
+ tracking.trackChallengeFailed();
1272
1373
  }
1273
1374
  /**
1274
1375
  * Forces the playable ad into a paused state.
@@ -1371,7 +1472,7 @@ var _sdk = class _sdk {
1371
1472
  }
1372
1473
  };
1373
1474
  /** Current version of the SDK */
1374
- _sdk.version = "1.0.26";
1475
+ _sdk.version = "1.0.10";
1375
1476
  /** Current maximum width of the playable ad container in pixels */
1376
1477
  _sdk.maxWidth = Math.floor(window.innerWidth);
1377
1478
  /** Current maximum height of the playable ad container in pixels */
@@ -1396,7 +1497,7 @@ _sdk.interactions = 0;
1396
1497
  _sdk.successCount = 0;
1397
1498
  var sdk = _sdk;
1398
1499
  window["console"].log(
1399
- `%c @tencent/playable-sdk %c v${sdk.version} `,
1500
+ `%c @playcraft/adsdk %c v${sdk.version} `,
1400
1501
  "background: #007acc; color: #fff; font-size: 14px; padding: 4px 8px; border-top-left-radius: 4px; border-bottom-left-radius: 4px;",
1401
1502
  "background: #e1e4e8; color: #333; font-size: 14px; padding: 4px 8px; border-top-right-radius: 4px; border-bottom-right-radius: 4px;"
1402
1503
  );
@@ -1406,5 +1507,6 @@ window.PlayableSDK = sdk;
1406
1507
  hideWechatGuide,
1407
1508
  removeWechatGuide,
1408
1509
  sdk,
1409
- showWechatGuide
1510
+ showWechatGuide,
1511
+ tracking
1410
1512
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcraft/adsdk",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "统一的 Playable SDK,支持 MRAID、Google、Facebook、Vungle、BigoAds 等多广告渠道",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -15,8 +15,10 @@
15
15
  ],
16
16
  "scripts": {
17
17
  "build": "npx tsup",
18
- "test": "jest"
18
+ "test": "jest",
19
+ "publish": "npm run build && node scripts/publish.js"
19
20
  },
21
+ "author": "Tencent ADS Team",
20
22
  "license": "MIT",
21
23
  "devDependencies": {
22
24
  "@types/jest": "^29.5.14",
@@ -43,5 +45,8 @@
43
45
  "ironsource",
44
46
  "javascript-sdk",
45
47
  "typescript-sdk"
46
- ]
48
+ ],
49
+ "publishConfig": {
50
+ "registry": "https://mirrors.tencent.com/npm/"
51
+ }
47
52
  }