@traqio/web 0.3.1 → 0.3.2

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.js CHANGED
@@ -636,7 +636,7 @@ var require_build = __commonJS({
636
636
  var adservices_1 = require_adservices();
637
637
  var deeplink_1 = require_deeplink();
638
638
  var adRevenue_1 = require_adRevenue();
639
- exports.SDK_VERSION = "0.5.1";
639
+ exports.SDK_VERSION = "0.6.0";
640
640
  var skan_2 = require_skan();
641
641
  Object.defineProperty(exports, "Skan", { enumerable: true, get: function() {
642
642
  return skan_2.Skan;
@@ -692,6 +692,9 @@ var require_build = __commonJS({
692
692
  var INSTALL_SENT_KEY = "traq_install_sent";
693
693
  var INSTALL_SENT_DEBUG_KEY = "traq_install_sent_debug";
694
694
  var INSTALL_ATTEMPTS_KEY = "traq_install_attempts";
695
+ var AD_ID_SENT_KEY = "traq_ad_id_sent";
696
+ var AD_ID_SENT_DEBUG_KEY = "traq_ad_id_sent_debug";
697
+ var AD_ID_PATH = "/ingest/advertising-id";
695
698
  var REFERRER_KEY = "traq_referrer";
696
699
  var QUEUE_KEY = "traq_queue";
697
700
  var AD_QUEUE_KEY = "traq_ad_queue";
@@ -811,6 +814,7 @@ var require_build = __commonJS({
811
814
  this.deferred = null;
812
815
  this.consent = null;
813
816
  this.att = null;
817
+ this.adIdSync = null;
814
818
  this.debug = false;
815
819
  this.maxRevenuePaid = (adInfo) => {
816
820
  try {
@@ -845,6 +849,7 @@ var require_build = __commonJS({
845
849
  if (!this.isWeb) {
846
850
  const freshInstall = Boolean(this.opts.storage) && !await this.opts.storage.getItem(this.installSentKey).catch(() => "1");
847
851
  await this.sendInstallOnce();
852
+ void this.syncAdvertisingId();
848
853
  if (this.opts.deepLinking !== false) {
849
854
  this.deferred = this.resolveDeferredOnce(freshInstall).then((link) => link != null ? link : this.retryDeferredWithConsent());
850
855
  this.wireDeepLinks();
@@ -1147,6 +1152,7 @@ var require_build = __commonJS({
1147
1152
  if (!this.started || this.erased)
1148
1153
  return;
1149
1154
  void this.maybeStartSession();
1155
+ void this.syncAdvertisingId();
1150
1156
  }
1151
1157
  /** The conversion-value mapping in force on this device, once fetched. */
1152
1158
  get skanMapping() {
@@ -1311,6 +1317,9 @@ var require_build = __commonJS({
1311
1317
  get installSentKey() {
1312
1318
  return this.debug ? INSTALL_SENT_DEBUG_KEY : INSTALL_SENT_KEY;
1313
1319
  }
1320
+ get adIdSentKey() {
1321
+ return this.debug ? AD_ID_SENT_DEBUG_KEY : AD_ID_SENT_KEY;
1322
+ }
1314
1323
  /** Spread into every body: present only in debug mode, so a release build's payload is unchanged. */
1315
1324
  debugField() {
1316
1325
  return this.debug ? { debug: true } : {};
@@ -1334,6 +1343,7 @@ var require_build = __commonJS({
1334
1343
  return;
1335
1344
  }
1336
1345
  void this.maybeStartSession();
1346
+ void this.syncAdvertisingId();
1337
1347
  });
1338
1348
  } catch {
1339
1349
  }
@@ -1543,17 +1553,56 @@ var require_build = __commonJS({
1543
1553
  return;
1544
1554
  }
1545
1555
  }
1556
+ const advertisingId = await this.readAdvertisingId();
1546
1557
  const ok = await this.post({
1547
1558
  install: {
1548
1559
  platform,
1549
1560
  installReferrer: referrer.referrer,
1550
1561
  appUserId: this.opts.userId,
1551
- advertisingId: await this.readAdvertisingId(),
1562
+ advertisingId,
1552
1563
  context: this.context
1553
1564
  }
1554
1565
  });
1555
- if (ok)
1566
+ if (ok) {
1556
1567
  await (store == null ? void 0 : store.setItem(this.installSentKey, "1"));
1568
+ if (advertisingId)
1569
+ await (store == null ? void 0 : store.setItem(this.adIdSentKey, advertisingId).catch(() => void 0));
1570
+ }
1571
+ }
1572
+ /**
1573
+ * The opted-in advertising id the install could not carry (todo cmwlauev). The
1574
+ * install leaves at first launch, before an app shows its own ATT prompt, so on iOS
1575
+ * it almost never has the IDFA. Re-read at every start and foreground — reading
1576
+ * never prompts (decision cmvjohk6) — and posted ONCE when it differs from the one
1577
+ * the server last acknowledged; a failure is retried at the next foreground.
1578
+ *
1579
+ * Only after the install is reported: the install itself carries an id it can read.
1580
+ */
1581
+ syncAdvertisingId() {
1582
+ if (this.adIdSync)
1583
+ return this.adIdSync;
1584
+ this.adIdSync = this.postAdvertisingIdIfChanged().finally(() => {
1585
+ this.adIdSync = null;
1586
+ });
1587
+ return this.adIdSync;
1588
+ }
1589
+ async postAdvertisingIdIfChanged() {
1590
+ var _a;
1591
+ const store = this.opts.storage;
1592
+ if (this.isWeb || this.erased || !store || !this.opts.collectAdvertisingId)
1593
+ return;
1594
+ try {
1595
+ if (!await store.getItem(this.installSentKey))
1596
+ return;
1597
+ const advertisingId = await this.readAdvertisingId();
1598
+ if (!advertisingId || await store.getItem(this.adIdSentKey) === advertisingId)
1599
+ return;
1600
+ const deviceId = (_a = this.context.deviceId) != null ? _a : await this.getOrCreateDeviceId();
1601
+ if (await this.post({ deviceId, appUserId: this.opts.userId, advertisingId }, AD_ID_PATH)) {
1602
+ await store.setItem(this.adIdSentKey, advertisingId);
1603
+ }
1604
+ } catch {
1605
+ }
1557
1606
  }
1558
1607
  scheduleFlush(delay = FLUSH_DELAY_MS) {
1559
1608
  if (this.flushTimer)
@@ -1683,8 +1732,8 @@ var require_build = __commonJS({
1683
1732
  * key fixed in the console makes the same queued batch succeed.
1684
1733
  */
1685
1734
  async send(body, path = "/ingest") {
1686
- const consent = this.consent && (path === "/ingest" || path === "/ingest/session") ? { consent: this.consent } : {};
1687
- const att = path === "/ingest" && this.asksTrackingAuthorization ? await this.readTrackingAuthorization() : null;
1735
+ const consent = this.consent && (path === "/ingest" || path === "/ingest/session" || path === AD_ID_PATH) ? { consent: this.consent } : {};
1736
+ const att = (path === "/ingest" || path === AD_ID_PATH) && this.asksTrackingAuthorization ? await this.readTrackingAuthorization() : null;
1688
1737
  try {
1689
1738
  const res = await fetch(`${this.opts.endpoint}${path}`, {
1690
1739
  method: "POST",