@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/esm/index.js CHANGED
@@ -158,6 +158,14 @@ function ensureProtocol() {
158
158
  }
159
159
 
160
160
  // src/tracking.ts
161
+ function getCurrentAdNetwork(adNetwork) {
162
+ const network = adNetwork || (typeof AD_NETWORK !== "undefined" ? AD_NETWORK : "");
163
+ const supportedNetworks = ["bigabid", "inmobi", "applovin"];
164
+ if (supportedNetworks.includes(network)) {
165
+ return network;
166
+ }
167
+ return null;
168
+ }
161
169
  function trackURL(url) {
162
170
  if (url) {
163
171
  const trackingPixel = new Image();
@@ -182,39 +190,46 @@ function trackApplovinEvent(event) {
182
190
  window.ALPlayableAnalytics.trackEvent(event);
183
191
  }
184
192
  }
185
- var totalInteractions = 0;
186
- var progressMilestones = [];
187
- function setTotalInteractions(total) {
188
- totalInteractions = total;
189
- }
190
- function trackChallengeSuccess() {
191
- if (AD_NETWORK === "applovin") {
192
- trackApplovinEvent("CHALLENGE_SOLVED");
193
- }
194
- if (AD_NETWORK === "bigabid") {
195
- trackBigabidComplete();
193
+ var bigabidCompleteTriggered = false;
194
+ function trackBigabidComplete() {
195
+ if (!bigabidCompleteTriggered) {
196
+ trackBigabidEvent("complete");
197
+ bigabidCompleteTriggered = true;
196
198
  }
197
- if (AD_NETWORK === "inmobi") {
198
- trackInMobiEvent("Gameplay_Complete");
199
+ }
200
+ var inmobiTimers = [];
201
+ function startInMobiDurationTracking() {
202
+ const durations = [5, 10, 15, 20, 25, 30];
203
+ for (const sec of durations) {
204
+ const timer = setTimeout(() => trackInMobiEvent(`Spent_${sec}_Seconds`), sec * 1e3);
205
+ inmobiTimers.push(timer);
199
206
  }
200
207
  }
201
- function trackChallengeFailed() {
202
- if (AD_NETWORK === "applovin") {
203
- trackApplovinEvent("CHALLENGE_FAILED");
208
+ function clearInMobiDurationTracking() {
209
+ for (const timer of inmobiTimers) {
210
+ clearTimeout(timer);
204
211
  }
212
+ inmobiTimers = [];
213
+ }
214
+ var totalInteractions = 0;
215
+ var progressMilestones = [];
216
+ function setTotalInteractions(total) {
217
+ totalInteractions = total;
205
218
  }
206
- function initProgressMilestones() {
219
+ function initProgressMilestones(adNetwork) {
207
220
  if (totalInteractions <= 0) return;
208
- if (AD_NETWORK === "applovin") {
221
+ const network = getCurrentAdNetwork(adNetwork);
222
+ if (!network) return;
223
+ if (network === "applovin") {
209
224
  progressMilestones = [
210
225
  { percent: 25, triggered: false, callback: () => trackApplovinEvent("CHALLENGE_PASS_25") },
211
226
  { percent: 50, triggered: false, callback: () => trackApplovinEvent("CHALLENGE_PASS_50") },
212
227
  { percent: 75, triggered: false, callback: () => trackApplovinEvent("CHALLENGE_PASS_75") },
213
- { percent: 100, triggered: false, callback: () => trackChallengeSuccess() }
228
+ { percent: 100, triggered: false, callback: () => _trackChallengeSuccess(adNetwork) }
214
229
  ];
215
- } else if (AD_NETWORK === "bigabid") {
230
+ } else if (network === "bigabid") {
216
231
  progressMilestones = [
217
- { percent: 100, triggered: false, callback: () => trackChallengeSuccess() }
232
+ { percent: 100, triggered: false, callback: () => _trackChallengeSuccess(adNetwork) }
218
233
  ];
219
234
  }
220
235
  }
@@ -228,104 +243,189 @@ function checkInteractionProgress(currentInteractions) {
228
243
  }
229
244
  }
230
245
  }
231
- var bigabidCompleteTriggered = false;
232
- function trackBigabidComplete() {
233
- if (!bigabidCompleteTriggered) {
234
- trackBigabidEvent("complete");
235
- bigabidCompleteTriggered = true;
246
+ function _onInit(adNetwork) {
247
+ initProgressMilestones(adNetwork);
248
+ const network = getCurrentAdNetwork(adNetwork);
249
+ if (!network) return;
250
+ if (network === "bigabid") {
251
+ trackBigabidEvent("mraid_viewable");
252
+ }
253
+ if (network === "inmobi") {
254
+ trackInMobiEvent("Ad_Load_Start");
255
+ }
256
+ if (network === "applovin") {
257
+ trackApplovinEvent("LOADING");
236
258
  }
237
259
  }
238
- var inmobiTimers = [];
239
- function startInMobiDurationTracking() {
240
- const durations = [5, 10, 15, 20, 25, 30];
241
- for (const sec of durations) {
242
- const timer = setTimeout(() => trackInMobiEvent(`Spent_${sec}_Seconds`), sec * 1e3);
243
- inmobiTimers.push(timer);
260
+ function _onStart(adNetwork) {
261
+ const network = getCurrentAdNetwork(adNetwork);
262
+ if (!network) return;
263
+ if (network === "bigabid") {
264
+ trackBigabidEvent("game_viewable");
265
+ }
266
+ if (network === "inmobi") {
267
+ trackInMobiEvent("Ad_Viewable");
268
+ startInMobiDurationTracking();
269
+ }
270
+ if (network === "applovin") {
271
+ trackApplovinEvent("LOADED");
244
272
  }
245
273
  }
246
- function clearInMobiDurationTracking() {
247
- for (const timer of inmobiTimers) {
248
- clearTimeout(timer);
274
+ function _onInteractive(adNetwork) {
275
+ const network = getCurrentAdNetwork(adNetwork);
276
+ if (!network) return;
277
+ if (network === "applovin") {
278
+ trackApplovinEvent("DISPLAYED");
249
279
  }
250
- inmobiTimers = [];
251
280
  }
281
+ function _onInteraction(adNetwork) {
282
+ const network = getCurrentAdNetwork(adNetwork);
283
+ if (!network) return;
284
+ if (network === "bigabid") {
285
+ trackBigabidEvent("engagement");
286
+ }
287
+ if (network === "inmobi") {
288
+ trackInMobiEvent("First_Engagement");
289
+ }
290
+ if (network === "applovin") {
291
+ trackApplovinEvent("CHALLENGE_STARTED");
292
+ }
293
+ }
294
+ function _onSuccess(successCount) {
295
+ checkInteractionProgress(successCount);
296
+ }
297
+ function _onFinish(adNetwork) {
298
+ const network = getCurrentAdNetwork(adNetwork);
299
+ if (!network) return;
300
+ if (network === "bigabid") {
301
+ trackBigabidComplete();
302
+ }
303
+ if (network === "inmobi") {
304
+ trackInMobiEvent("Gameplay_Complete");
305
+ clearInMobiDurationTracking();
306
+ }
307
+ if (network === "applovin") {
308
+ trackApplovinEvent("ENDCARD_SHOWN");
309
+ }
310
+ }
311
+ function _onInstall(adNetwork) {
312
+ const network = getCurrentAdNetwork(adNetwork);
313
+ if (!network) return;
314
+ if (network === "bigabid") {
315
+ trackBigabidEvent("click");
316
+ }
317
+ if (network === "inmobi") {
318
+ trackInMobiEvent("DSP_Click");
319
+ clearInMobiDurationTracking();
320
+ }
321
+ if (network === "applovin") {
322
+ trackApplovinEvent("CTA_CLICKED");
323
+ }
324
+ }
325
+ function _onRetry(adNetwork) {
326
+ const network = getCurrentAdNetwork(adNetwork);
327
+ if (!network) return;
328
+ if (network === "applovin") {
329
+ trackApplovinEvent("CHALLENGE_RETRY");
330
+ }
331
+ }
332
+ function _trackChallengeSuccess(adNetwork) {
333
+ const network = getCurrentAdNetwork(adNetwork);
334
+ if (!network) return;
335
+ if (network === "applovin") {
336
+ trackApplovinEvent("CHALLENGE_SOLVED");
337
+ }
338
+ if (network === "bigabid") {
339
+ trackBigabidComplete();
340
+ }
341
+ if (network === "inmobi") {
342
+ trackInMobiEvent("Gameplay_Complete");
343
+ }
344
+ }
345
+ function _trackChallengeFailed(adNetwork) {
346
+ const network = getCurrentAdNetwork(adNetwork);
347
+ if (!network) return;
348
+ if (network === "applovin") {
349
+ trackApplovinEvent("CHALLENGE_FAILED");
350
+ }
351
+ }
352
+ var tracking = {
353
+ /**
354
+ * SDK 初始化开始
355
+ * @param adNetwork - 可选的广告渠道名称
356
+ */
357
+ onInit: _onInit,
358
+ /**
359
+ * 游戏资源加载完成
360
+ * @param adNetwork - 可选的广告渠道名称
361
+ */
362
+ onStart: _onStart,
363
+ /**
364
+ * 主场景就绪,用户可交互
365
+ * @param adNetwork - 可选的广告渠道名称
366
+ */
367
+ onInteractive: _onInteractive,
368
+ /**
369
+ * 首次交互
370
+ * @param adNetwork - 可选的广告渠道名称
371
+ */
372
+ onInteraction: _onInteraction,
373
+ /**
374
+ * 成功计数(用于进度百分比追踪)
375
+ * @param successCount - 当前成功次数
376
+ */
377
+ onSuccess: _onSuccess,
378
+ /**
379
+ * 游戏结束
380
+ * @param adNetwork - 可选的广告渠道名称
381
+ */
382
+ onFinish: _onFinish,
383
+ /**
384
+ * 点击安装
385
+ * @param adNetwork - 可选的广告渠道名称
386
+ */
387
+ onInstall: _onInstall,
388
+ /**
389
+ * 重试游戏
390
+ * @param adNetwork - 可选的广告渠道名称
391
+ */
392
+ onRetry: _onRetry,
393
+ /**
394
+ * 设置交互总数(用于进度百分比计算)
395
+ * @param total - 交互总数
396
+ */
397
+ setTotalInteractions,
398
+ /**
399
+ * 检查交互进度
400
+ * @param currentInteractions - 当前交互次数
401
+ */
402
+ checkInteractionProgress,
403
+ /**
404
+ * 触发游戏成功事件
405
+ * @param adNetwork - 可选的广告渠道名称
406
+ */
407
+ trackChallengeSuccess: _trackChallengeSuccess,
408
+ /**
409
+ * 触发游戏失败事件
410
+ * @param adNetwork - 可选的广告渠道名称
411
+ */
412
+ trackChallengeFailed: _trackChallengeFailed
413
+ };
414
+
415
+ // src/tracking-init.ts
252
416
  function initTrackingProtocols() {
253
417
  const supportedNetworks = ["bigabid", "inmobi", "applovin"];
254
418
  if (!supportedNetworks.includes(AD_NETWORK)) {
255
419
  return;
256
420
  }
257
- initProgressMilestones();
258
- sdk.once("init", () => {
259
- if (AD_NETWORK === "bigabid") {
260
- trackBigabidEvent("mraid_viewable");
261
- }
262
- if (AD_NETWORK === "inmobi") {
263
- trackInMobiEvent("Ad_Load_Start");
264
- }
265
- if (AD_NETWORK === "applovin") {
266
- trackApplovinEvent("LOADING");
267
- }
268
- });
269
- sdk.once("start", () => {
270
- if (AD_NETWORK === "bigabid") {
271
- trackBigabidEvent("game_viewable");
272
- }
273
- if (AD_NETWORK === "inmobi") {
274
- trackInMobiEvent("Ad_Viewable");
275
- startInMobiDurationTracking();
276
- }
277
- if (AD_NETWORK === "applovin") {
278
- trackApplovinEvent("LOADED");
279
- }
280
- });
281
- sdk.once("interactive", () => {
282
- if (AD_NETWORK === "applovin") {
283
- trackApplovinEvent("DISPLAYED");
284
- }
285
- });
286
- sdk.once("interaction", () => {
287
- if (AD_NETWORK === "bigabid") {
288
- trackBigabidEvent("engagement");
289
- }
290
- if (AD_NETWORK === "inmobi") {
291
- trackInMobiEvent("First_Engagement");
292
- }
293
- if (AD_NETWORK === "applovin") {
294
- trackApplovinEvent("CHALLENGE_STARTED");
295
- }
296
- });
297
- sdk.on("success", (successCount) => {
298
- checkInteractionProgress(successCount);
299
- });
300
- sdk.once("finish", () => {
301
- if (AD_NETWORK === "bigabid") {
302
- trackBigabidComplete();
303
- }
304
- if (AD_NETWORK === "inmobi") {
305
- trackInMobiEvent("Gameplay_Complete");
306
- clearInMobiDurationTracking();
307
- }
308
- if (AD_NETWORK === "applovin") {
309
- trackApplovinEvent("ENDCARD_SHOWN");
310
- }
311
- });
312
- sdk.on("install", () => {
313
- if (AD_NETWORK === "bigabid") {
314
- trackBigabidEvent("click");
315
- }
316
- if (AD_NETWORK === "inmobi") {
317
- trackInMobiEvent("DSP_Click");
318
- clearInMobiDurationTracking();
319
- }
320
- if (AD_NETWORK === "applovin") {
321
- trackApplovinEvent("CTA_CLICKED");
322
- }
323
- });
324
- sdk.once("retry", () => {
325
- if (AD_NETWORK === "applovin") {
326
- trackApplovinEvent("CHALLENGE_RETRY");
327
- }
328
- });
421
+ sdk.once("init", tracking.onInit);
422
+ sdk.once("start", tracking.onStart);
423
+ sdk.once("interactive", tracking.onInteractive);
424
+ sdk.once("interaction", tracking.onInteraction);
425
+ sdk.on("success", tracking.onSuccess);
426
+ sdk.once("finish", tracking.onFinish);
427
+ sdk.on("install", tracking.onInstall);
428
+ sdk.once("retry", tracking.onRetry);
329
429
  }
330
430
 
331
431
  // src/assets/images.ts
@@ -955,7 +1055,7 @@ var _sdk = class _sdk {
955
1055
  if (isSDKInitialized) return;
956
1056
  if (callback) initCallback = callback;
957
1057
  if ((options == null ? void 0 : options.totalSuccessCount) && options.totalSuccessCount > 0) {
958
- setTotalInteractions(options.totalSuccessCount);
1058
+ tracking.setTotalInteractions(options.totalSuccessCount);
959
1059
  }
960
1060
  initTrackingProtocols();
961
1061
  document.readyState === "loading" ? window.addEventListener("DOMContentLoaded", initSDK) : initSDK();
@@ -1224,7 +1324,7 @@ var _sdk = class _sdk {
1224
1324
  * }
1225
1325
  */
1226
1326
  static recordSuccess() {
1227
- trackChallengeSuccess();
1327
+ tracking.trackChallengeSuccess();
1228
1328
  }
1229
1329
  /**
1230
1330
  * Records a game failure event.
@@ -1238,7 +1338,7 @@ var _sdk = class _sdk {
1238
1338
  * }
1239
1339
  */
1240
1340
  static recordFailed() {
1241
- trackChallengeFailed();
1341
+ tracking.trackChallengeFailed();
1242
1342
  }
1243
1343
  /**
1244
1344
  * Forces the playable ad into a paused state.
@@ -1341,7 +1441,7 @@ var _sdk = class _sdk {
1341
1441
  }
1342
1442
  };
1343
1443
  /** Current version of the SDK */
1344
- _sdk.version = "1.0.26";
1444
+ _sdk.version = "1.0.10";
1345
1445
  /** Current maximum width of the playable ad container in pixels */
1346
1446
  _sdk.maxWidth = Math.floor(window.innerWidth);
1347
1447
  /** Current maximum height of the playable ad container in pixels */
@@ -1366,7 +1466,7 @@ _sdk.interactions = 0;
1366
1466
  _sdk.successCount = 0;
1367
1467
  var sdk = _sdk;
1368
1468
  window["console"].log(
1369
- `%c @tencent/playable-sdk %c v${sdk.version} `,
1469
+ `%c @playcraft/adsdk %c v${sdk.version} `,
1370
1470
  "background: #007acc; color: #fff; font-size: 14px; padding: 4px 8px; border-top-left-radius: 4px; border-bottom-left-radius: 4px;",
1371
1471
  "background: #e1e4e8; color: #333; font-size: 14px; padding: 4px 8px; border-top-right-radius: 4px; border-bottom-right-radius: 4px;"
1372
1472
  );
@@ -1376,5 +1476,6 @@ export {
1376
1476
  hideWechatGuide,
1377
1477
  removeWechatGuide,
1378
1478
  sdk,
1379
- showWechatGuide
1479
+ showWechatGuide,
1480
+ tracking
1380
1481
  };