@traqio/web 0.2.0 → 0.2.1

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/build/index.cjs CHANGED
@@ -362,12 +362,203 @@ var init_empty = __esm({
362
362
  }
363
363
  });
364
364
 
365
+ // ../sdk-core/build/adRevenue.js
366
+ var require_adRevenue = __commonJS({
367
+ "../sdk-core/build/adRevenue.js"(exports) {
368
+ "use strict";
369
+ Object.defineProperty(exports, "__esModule", { value: true });
370
+ exports.CAPACITOR_ADMOB_PAID_EVENTS = exports.MAX_RN_MIN_VERSION = exports.MAX_RN_REVENUE_EVENTS = exports.GMA_MIN_VERSION = exports.GMA_FULLSCREEN_CHANNELS = void 0;
371
+ exports.fromGoogleMobileAdsPaid = fromGoogleMobileAdsPaid;
372
+ exports.fromGoogleMobileAdsChannel = fromGoogleMobileAdsChannel;
373
+ exports.fromGoogleMobileAdsNativeAd = fromGoogleMobileAdsNativeAd;
374
+ exports.fromMaxAdInfo = fromMaxAdInfo;
375
+ exports.fromCapacitorAdMob = fromCapacitorAdMob;
376
+ exports.watchReactNativeAds = watchReactNativeAds;
377
+ var PRECISION_BY_INDEX = ["unknown", "estimated", "publisher_provided", "precise"];
378
+ function precisionOf(raw) {
379
+ var _a;
380
+ return typeof raw === "number" ? (_a = PRECISION_BY_INDEX[raw]) != null ? _a : "unknown" : "unknown";
381
+ }
382
+ function text(raw) {
383
+ return typeof raw === "string" && raw.trim() ? raw : void 0;
384
+ }
385
+ function record(raw) {
386
+ return raw && typeof raw === "object" ? raw : void 0;
387
+ }
388
+ function micros(raw) {
389
+ const n = typeof raw === "string" && /^\d+$/.test(raw.trim()) ? Number(raw) : raw;
390
+ return typeof n === "number" && Number.isSafeInteger(n) && n >= 0 ? n : void 0;
391
+ }
392
+ exports.GMA_FULLSCREEN_CHANNELS = {
393
+ rnapp_google_mobile_ads_app_open_event: "app_open",
394
+ rnapp_google_mobile_ads_interstitial_event: "interstitial",
395
+ rnapp_google_mobile_ads_rewarded_event: "rewarded",
396
+ rnapp_google_mobile_ads_rewarded_interstitial_event: "rewarded_interstitial"
397
+ };
398
+ exports.GMA_MIN_VERSION = "12.4.0";
399
+ function fromGoogleMobileAdsPaid(payload, meta = {}) {
400
+ var _a;
401
+ const p = record(payload);
402
+ if (!p)
403
+ return void 0;
404
+ const currency = text(p.currency);
405
+ if (!currency)
406
+ return void 0;
407
+ let valueMicros = micros(p.valueMicros);
408
+ if (valueMicros === void 0) {
409
+ if (!(typeof p.value === "number" && Number.isFinite(p.value) && p.value >= 0))
410
+ return void 0;
411
+ valueMicros = Math.round(p.value * 1e6);
412
+ }
413
+ const loaded = record((_a = record(p.responseInfo)) == null ? void 0 : _a.loadedAdapterResponse);
414
+ return {
415
+ valueMicros,
416
+ currency,
417
+ precision: precisionOf(p.precision),
418
+ adUnitId: meta.adUnitId,
419
+ adFormat: meta.adFormat,
420
+ adSourceName: text(loaded == null ? void 0 : loaded.adSourceName)
421
+ };
422
+ }
423
+ function fromGoogleMobileAdsChannel(channel, event) {
424
+ const e = record(event);
425
+ const body = record(e == null ? void 0 : e.body);
426
+ if (!e || (body == null ? void 0 : body.type) !== "paid")
427
+ return void 0;
428
+ return fromGoogleMobileAdsPaid(body.data, { adUnitId: text(e.adUnitId), adFormat: exports.GMA_FULLSCREEN_CHANNELS[channel] });
429
+ }
430
+ function fromGoogleMobileAdsNativeAd(event) {
431
+ const e = record(event);
432
+ if ((e == null ? void 0 : e.type) !== "paid")
433
+ return void 0;
434
+ return fromGoogleMobileAdsPaid(e, { adFormat: "native" });
435
+ }
436
+ exports.MAX_RN_REVENUE_EVENTS = [
437
+ "OnBannerAdRevenuePaid",
438
+ "OnMRecAdRevenuePaid",
439
+ "OnInterstitialAdRevenuePaid",
440
+ "OnRewardedAdRevenuePaid",
441
+ "OnAppOpenAdRevenuePaid"
442
+ ];
443
+ exports.MAX_RN_MIN_VERSION = "5.0.0";
444
+ function fromMaxAdInfo(info) {
445
+ const i = record(info);
446
+ if (!i || typeof i.revenue !== "number")
447
+ return void 0;
448
+ return {
449
+ revenue: i.revenue,
450
+ revenuePrecision: text(i.revenuePrecision),
451
+ adUnitId: text(i.adUnitId),
452
+ format: text(i.adFormat),
453
+ networkName: text(i.networkName)
454
+ };
455
+ }
456
+ exports.CAPACITOR_ADMOB_PAID_EVENTS = {
457
+ bannerAdPaid: "banner",
458
+ nativeAdPaid: "native",
459
+ interstitialAdImpression: "interstitial",
460
+ onRewardedVideoAdImpression: "rewarded",
461
+ onRewardedInterstitialAdImpression: "rewarded_interstitial",
462
+ appOpenAdImpression: "app_open"
463
+ };
464
+ function fromCapacitorAdMob(event, adFormat) {
465
+ const e = record(event);
466
+ const valueMicros = micros(e == null ? void 0 : e.valueMicros);
467
+ const currency = text(e == null ? void 0 : e.currencyCode);
468
+ if (!e || valueMicros === void 0 || !currency)
469
+ return void 0;
470
+ return {
471
+ valueMicros,
472
+ currency,
473
+ precision: precisionOf(e.precision),
474
+ adUnitId: text(e.adUnitId),
475
+ adFormat,
476
+ // The mediation ADAPTER class here, not the source's display name — still
477
+ // the only thing telling AdMob's own demand from a mediated network.
478
+ adSourceName: text(e.networkName)
479
+ };
480
+ }
481
+ function nativeModule(rn, name) {
482
+ var _a, _b, _c, _d, _e;
483
+ try {
484
+ return (_d = (_b = (_a = rn.TurboModuleRegistry) == null ? void 0 : _a.get) == null ? void 0 : _b.call(_a, name)) != null ? _d : (_c = rn.NativeModules) == null ? void 0 : _c[name];
485
+ } catch {
486
+ return (_e = rn.NativeModules) == null ? void 0 : _e[name];
487
+ }
488
+ }
489
+ function watchReactNativeAds(want, sink, rn) {
490
+ var _a, _b, _c, _d;
491
+ if (!rn) {
492
+ try {
493
+ rn = (init_empty(), __toCommonJS(empty_exports));
494
+ } catch {
495
+ return () => void 0;
496
+ }
497
+ }
498
+ const subs = [];
499
+ const guard = (parse, deliver) => (e) => {
500
+ try {
501
+ const v = parse(e);
502
+ if (v)
503
+ deliver(v);
504
+ } catch {
505
+ }
506
+ };
507
+ if (want.admob) {
508
+ for (const channel of Object.keys(exports.GMA_FULLSCREEN_CHANNELS)) {
509
+ const sub = (_a = rn.DeviceEventEmitter) == null ? void 0 : _a.addListener(channel, guard((e) => fromGoogleMobileAdsChannel(channel, e), sink.admob));
510
+ if (sub)
511
+ subs.push(sub);
512
+ }
513
+ const nativeAds = nativeModule(rn, "RNGoogleMobileAdsNativeModule");
514
+ const onNative = guard(fromGoogleMobileAdsNativeAd, sink.admob);
515
+ try {
516
+ if (nativeAds && typeof nativeAds.onAdEvent === "function") {
517
+ subs.push(nativeAds.onAdEvent(onNative));
518
+ } else if (nativeAds && rn.NativeEventEmitter) {
519
+ const emitter = new rn.NativeEventEmitter(((_b = rn.Platform) == null ? void 0 : _b.OS) === "ios" ? nativeAds : void 0);
520
+ subs.push(emitter.addListener("RNGMANativeAdEvent", onNative));
521
+ }
522
+ } catch {
523
+ }
524
+ }
525
+ if (want.applovinMax) {
526
+ const max = nativeModule(rn, "AppLovinMAX");
527
+ if (max && rn.NativeEventEmitter) {
528
+ try {
529
+ let names = [...exports.MAX_RN_REVENUE_EVENTS];
530
+ try {
531
+ const c = (_d = (_c = max.getConstants) == null ? void 0 : _c.call(max)) != null ? _d : {};
532
+ const fromModule = Object.keys(c).filter((k) => /^ON_.*_AD_REVENUE_PAID$/.test(k)).map((k) => c[k]).filter((v) => typeof v === "string");
533
+ if (fromModule.length)
534
+ names = [.../* @__PURE__ */ new Set([...fromModule, ...names])];
535
+ } catch {
536
+ }
537
+ const emitter = new rn.NativeEventEmitter(max);
538
+ for (const name of names)
539
+ subs.push(emitter.addListener(name, guard(fromMaxAdInfo, sink.applovinMax)));
540
+ } catch {
541
+ }
542
+ }
543
+ }
544
+ return () => {
545
+ for (const s of subs.splice(0)) {
546
+ try {
547
+ s.remove();
548
+ } catch {
549
+ }
550
+ }
551
+ };
552
+ }
553
+ }
554
+ });
555
+
365
556
  // ../sdk-core/build/index.js
366
557
  var require_build = __commonJS({
367
558
  "../sdk-core/build/index.js"(exports) {
368
559
  "use strict";
369
560
  Object.defineProperty(exports, "__esModule", { value: true });
370
- exports.Traqio = exports.Client = exports.isTrackingUrl = exports.isOpenUrl = exports.reportAdServicesToken = exports.Skan = exports.SDK_VERSION = void 0;
561
+ exports.Traqio = exports.Client = exports.watchReactNativeAds = exports.fromMaxAdInfo = exports.fromGoogleMobileAdsPaid = exports.fromGoogleMobileAdsNativeAd = exports.fromGoogleMobileAdsChannel = exports.fromCapacitorAdMob = exports.MAX_RN_REVENUE_EVENTS = exports.MAX_RN_MIN_VERSION = exports.GMA_MIN_VERSION = exports.GMA_FULLSCREEN_CHANNELS = exports.CAPACITOR_ADMOB_PAID_EVENTS = exports.isTrackingUrl = exports.isOpenUrl = exports.reportAdServicesToken = exports.Skan = exports.SDK_VERSION = void 0;
371
562
  exports.normalizeAdvertisingId = normalizeAdvertisingId;
372
563
  exports.fromMaxAd = fromMaxAd;
373
564
  exports.detectDebug = detectDebug;
@@ -375,7 +566,8 @@ var require_build = __commonJS({
375
566
  var skan_1 = require_skan();
376
567
  var adservices_1 = require_adservices();
377
568
  var deeplink_1 = require_deeplink();
378
- exports.SDK_VERSION = "0.3.0";
569
+ var adRevenue_1 = require_adRevenue();
570
+ exports.SDK_VERSION = "0.4.0";
379
571
  var skan_2 = require_skan();
380
572
  Object.defineProperty(exports, "Skan", { enumerable: true, get: function() {
381
573
  return skan_2.Skan;
@@ -391,6 +583,40 @@ var require_build = __commonJS({
391
583
  Object.defineProperty(exports, "isTrackingUrl", { enumerable: true, get: function() {
392
584
  return deeplink_2.isTrackingUrl;
393
585
  } });
586
+ var adRevenue_2 = require_adRevenue();
587
+ Object.defineProperty(exports, "CAPACITOR_ADMOB_PAID_EVENTS", { enumerable: true, get: function() {
588
+ return adRevenue_2.CAPACITOR_ADMOB_PAID_EVENTS;
589
+ } });
590
+ Object.defineProperty(exports, "GMA_FULLSCREEN_CHANNELS", { enumerable: true, get: function() {
591
+ return adRevenue_2.GMA_FULLSCREEN_CHANNELS;
592
+ } });
593
+ Object.defineProperty(exports, "GMA_MIN_VERSION", { enumerable: true, get: function() {
594
+ return adRevenue_2.GMA_MIN_VERSION;
595
+ } });
596
+ Object.defineProperty(exports, "MAX_RN_MIN_VERSION", { enumerable: true, get: function() {
597
+ return adRevenue_2.MAX_RN_MIN_VERSION;
598
+ } });
599
+ Object.defineProperty(exports, "MAX_RN_REVENUE_EVENTS", { enumerable: true, get: function() {
600
+ return adRevenue_2.MAX_RN_REVENUE_EVENTS;
601
+ } });
602
+ Object.defineProperty(exports, "fromCapacitorAdMob", { enumerable: true, get: function() {
603
+ return adRevenue_2.fromCapacitorAdMob;
604
+ } });
605
+ Object.defineProperty(exports, "fromGoogleMobileAdsChannel", { enumerable: true, get: function() {
606
+ return adRevenue_2.fromGoogleMobileAdsChannel;
607
+ } });
608
+ Object.defineProperty(exports, "fromGoogleMobileAdsNativeAd", { enumerable: true, get: function() {
609
+ return adRevenue_2.fromGoogleMobileAdsNativeAd;
610
+ } });
611
+ Object.defineProperty(exports, "fromGoogleMobileAdsPaid", { enumerable: true, get: function() {
612
+ return adRevenue_2.fromGoogleMobileAdsPaid;
613
+ } });
614
+ Object.defineProperty(exports, "fromMaxAdInfo", { enumerable: true, get: function() {
615
+ return adRevenue_2.fromMaxAdInfo;
616
+ } });
617
+ Object.defineProperty(exports, "watchReactNativeAds", { enumerable: true, get: function() {
618
+ return adRevenue_2.watchReactNativeAds;
619
+ } });
394
620
  var INSTALL_SENT_KEY = "traq_install_sent";
395
621
  var INSTALL_SENT_DEBUG_KEY = "traq_install_sent_debug";
396
622
  var INSTALL_ATTEMPTS_KEY = "traq_install_attempts";
@@ -502,6 +728,14 @@ var require_build = __commonJS({
502
728
  this.deferred = null;
503
729
  this.consent = null;
504
730
  this.debug = false;
731
+ this.maxRevenuePaid = (adInfo) => {
732
+ try {
733
+ const ad = (0, adRevenue_1.fromMaxAdInfo)(adInfo);
734
+ if (ad)
735
+ this.trackMaxAdRevenue(ad);
736
+ } catch {
737
+ }
738
+ };
505
739
  }
506
740
  /** Whether this run is in debug mode — see `InitOptions.debug`. Settled by `init()`. */
507
741
  get isDebug() {
@@ -535,9 +769,28 @@ var require_build = __commonJS({
535
769
  await this.initSkan();
536
770
  await this.initAppleAds();
537
771
  this.wireLifecycle();
772
+ this.wireAdRevenue();
538
773
  if (this.queue.length || this.adQueue.length)
539
774
  this.scheduleFlush(0);
540
775
  }
776
+ // `InitOptions.adRevenue`: hand the ad SDKs' own paid events to the trackers.
777
+ wireAdRevenue() {
778
+ var _a;
779
+ const want = this.opts.adRevenue;
780
+ if (!want || this.isWeb || !(want.admob || want.applovinMax))
781
+ return;
782
+ const sink = {
783
+ admob: (ad) => this.trackAdRevenue(ad),
784
+ applovinMax: (ad) => this.trackMaxAdRevenue(ad)
785
+ };
786
+ try {
787
+ if ((_a = this.opts.native) == null ? void 0 : _a.watchAdRevenue)
788
+ this.opts.native.watchAdRevenue(want, sink);
789
+ else
790
+ (0, adRevenue_1.watchReactNativeAds)(want, sink);
791
+ } catch {
792
+ }
793
+ }
541
794
  track(name, props) {
542
795
  var _a, _b;
543
796
  if (!this.started || this.erased)
@@ -590,6 +843,27 @@ var require_build = __commonJS({
590
843
  if (converted)
591
844
  this.queueAdRevenue(converted, "applovin_max");
592
845
  }
846
+ /**
847
+ * The one line for an ad that reports through its own callback — a
848
+ * react-native-google-mobile-ads `<BannerAd>` (the full-screen formats are
849
+ * captured by `adRevenue: { admob: true }`):
850
+ *
851
+ * <BannerAd unitId={AD_UNIT_ID} size={…} onPaid={Traqio.admobPaid(AD_UNIT_ID)} />
852
+ * ad.addAdEventListener(AdEventType.PAID, Traqio.admobPaid(AD_UNIT_ID, "rewarded"))
853
+ *
854
+ * Reads the library's PAID payload (`value` in currency units, or v17's exact
855
+ * `valueMicros`) and reports it as AdMob revenue.
856
+ */
857
+ admobPaid(adUnitId, adFormat = "banner") {
858
+ return (event) => {
859
+ try {
860
+ const ad = (0, adRevenue_1.fromGoogleMobileAdsPaid)(event, { adUnitId, adFormat });
861
+ if (ad)
862
+ this.trackAdRevenue(ad);
863
+ } catch {
864
+ }
865
+ };
866
+ }
593
867
  queueAdRevenue(ad, source) {
594
868
  var _a;
595
869
  if (!this.started || this.erased)