@traqio/web 0.6.1 → 0.6.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
@@ -820,7 +820,7 @@ var require_build = __commonJS({
820
820
  var adservices_1 = require_adservices();
821
821
  var deeplink_1 = require_deeplink();
822
822
  var adRevenue_1 = require_adRevenue();
823
- exports.SDK_VERSION = "0.10.0";
823
+ exports.SDK_VERSION = "0.11.0";
824
824
  var skan_2 = require_skan();
825
825
  Object.defineProperty(exports, "Skan", { enumerable: true, get: function() {
826
826
  return skan_2.Skan;
@@ -883,6 +883,9 @@ var require_build = __commonJS({
883
883
  var AD_ID_SENT_KEY = "traq_ad_id_sent";
884
884
  var AD_ID_SENT_DEBUG_KEY = "traq_ad_id_sent_debug";
885
885
  var AD_ID_PATH = "/ingest/advertising-id";
886
+ var AD_ID_CONSENT_KEY = "traq_ad_id_consent";
887
+ var AD_ID_ANSWER_SENT_KEY = "traq_ad_id_answer_sent";
888
+ var AD_ID_ANSWER_SENT_DEBUG_KEY = "traq_ad_id_answer_sent_debug";
886
889
  var REFERRER_KEY = "traq_referrer";
887
890
  var QUEUE_KEY = "traq_queue";
888
891
  var AD_QUEUE_KEY = "traq_ad_queue";
@@ -1036,6 +1039,7 @@ var require_build = __commonJS({
1036
1039
  this.deferred = null;
1037
1040
  this.consent = null;
1038
1041
  this.att = null;
1042
+ this.adIdConsent = null;
1039
1043
  this.adIdSync = null;
1040
1044
  this.debug = false;
1041
1045
  this.analyticsQueue = [];
@@ -1070,6 +1074,7 @@ var require_build = __commonJS({
1070
1074
  }
1071
1075
  this.debug = await detectDebug(opts);
1072
1076
  await this.restoreConsent(opts.consent);
1077
+ await this.restoreAdvertisingIdConsent();
1073
1078
  await this.restoreQueue();
1074
1079
  await this.restoreAdQueue();
1075
1080
  await this.restoreAnalytics();
@@ -1611,6 +1616,37 @@ var require_build = __commonJS({
1611
1616
  await this.deferred;
1612
1617
  }
1613
1618
  }
1619
+ /**
1620
+ * The user's answer to YOUR advertising-id consent (GDPR / ePrivacy CMP, ATT prompt)
1621
+ * — HQ todo cmx4z20d. Call it once the user has answered, at any launch; persisted.
1622
+ *
1623
+ * `true` turns IDFA / GAID collection on from now: the SDK reads the id (never
1624
+ * prompting) and sends it once. With `waitForAdvertisingIdConsent` at init, the
1625
+ * install's Meta / TikTok postback was held for it and now leaves with it. On iOS,
1626
+ * call it AFTER your ATT prompt: the IDFA exists only once ATT is authorized (a yes
1627
+ * before that releases the install without it; the IDFA follows at the next
1628
+ * foreground for later conversions).
1629
+ *
1630
+ * `false` stops collection, tells the server to forget an id it kept from an
1631
+ * earlier yes, and lets a held install leave without one. First-party measurement
1632
+ * is unchanged either way.
1633
+ *
1634
+ * Traqio.setAdvertisingIdConsent(cmp.hasConsentFor("ads"));
1635
+ *
1636
+ * Overrides `collectAdvertisingId` once called. Android still needs Google's
1637
+ * `play-services-ads-identifier` and the `AD_ID` permission in the app.
1638
+ */
1639
+ async setAdvertisingIdConsent(granted) {
1640
+ var _a, _b;
1641
+ this.adIdConsent = granted ? "granted" : "denied";
1642
+ if (!this.started || !this.opts)
1643
+ return;
1644
+ await ((_a = this.opts.storage) == null ? void 0 : _a.setItem(AD_ID_CONSENT_KEY, this.adIdConsent).catch(() => void 0));
1645
+ if (this.isWeb || this.erased)
1646
+ return;
1647
+ await ((_b = this.adIdSync) == null ? void 0 : _b.catch(() => void 0));
1648
+ await this.syncAdvertisingId();
1649
+ }
1614
1650
  /** True once `forgetMe()` has been honoured — this install sends nothing any more. */
1615
1651
  get forgotten() {
1616
1652
  return this.erased;
@@ -1809,6 +1845,31 @@ var require_build = __commonJS({
1809
1845
  get adIdSentKey() {
1810
1846
  return this.debug ? AD_ID_SENT_DEBUG_KEY : AD_ID_SENT_KEY;
1811
1847
  }
1848
+ get adIdAnswerSentKey() {
1849
+ return this.debug ? AD_ID_ANSWER_SENT_DEBUG_KEY : AD_ID_ANSWER_SENT_KEY;
1850
+ }
1851
+ /**
1852
+ * May the advertising id be read right now? The user's stored answer first; then,
1853
+ * for an app that said it would ask, no until it has; then the init opt-in.
1854
+ */
1855
+ get collectsAdvertisingId() {
1856
+ if (this.adIdConsent)
1857
+ return this.adIdConsent === "granted";
1858
+ if (this.opts.waitForAdvertisingIdConsent)
1859
+ return false;
1860
+ return this.opts.collectAdvertisingId === true;
1861
+ }
1862
+ /** A `setAdvertisingIdConsent()` made before `init()` wins over the stored answer. */
1863
+ async restoreAdvertisingIdConsent() {
1864
+ var _a, _b;
1865
+ if (this.adIdConsent) {
1866
+ await ((_a = this.opts.storage) == null ? void 0 : _a.setItem(AD_ID_CONSENT_KEY, this.adIdConsent).catch(() => void 0));
1867
+ return;
1868
+ }
1869
+ const stored = await ((_b = this.opts.storage) == null ? void 0 : _b.getItem(AD_ID_CONSENT_KEY).catch(() => null));
1870
+ if (stored === "granted" || stored === "denied")
1871
+ this.adIdConsent = stored;
1872
+ }
1812
1873
  /** Spread into every body: present only in debug mode, so a release build's payload is unchanged. */
1813
1874
  debugField() {
1814
1875
  return this.debug ? { debug: true } : {};
@@ -2152,7 +2213,7 @@ var require_build = __commonJS({
2152
2213
  /** Only with the host's opt-in; a zeroed or malformed id is never sent. */
2153
2214
  async readAdvertisingId() {
2154
2215
  var _a;
2155
- if (!this.opts.collectAdvertisingId || !((_a = this.opts.native) == null ? void 0 : _a.getAdvertisingId))
2216
+ if (!this.collectsAdvertisingId || !((_a = this.opts.native) == null ? void 0 : _a.getAdvertisingId))
2156
2217
  return void 0;
2157
2218
  try {
2158
2219
  return normalizeAdvertisingId(await this.opts.native.getAdvertisingId());
@@ -2189,6 +2250,8 @@ var require_build = __commonJS({
2189
2250
  ...metaInstallReferrers ? { metaInstallReferrers } : {},
2190
2251
  appUserId: this.opts.userId,
2191
2252
  advertisingId,
2253
+ // The app has not asked yet: the server holds the install postback for the id.
2254
+ ...this.opts.waitForAdvertisingIdConsent && !this.adIdConsent ? { advertisingIdPending: true } : {},
2192
2255
  context: this.context
2193
2256
  }
2194
2257
  });
@@ -2218,17 +2281,40 @@ var require_build = __commonJS({
2218
2281
  async postAdvertisingIdIfChanged() {
2219
2282
  var _a;
2220
2283
  const store = this.opts.storage;
2221
- if (this.isWeb || this.erased || !store || !this.opts.collectAdvertisingId)
2284
+ if (this.isWeb || this.erased || !store)
2222
2285
  return;
2223
2286
  try {
2224
2287
  if (!await store.getItem(this.installSentKey))
2225
2288
  return;
2289
+ const answer = this.adIdConsent;
2290
+ const deviceId = (_a = this.context.deviceId) != null ? _a : await this.getOrCreateDeviceId();
2291
+ const who = { deviceId, appUserId: this.opts.userId };
2292
+ if (answer === "denied") {
2293
+ if (await store.getItem(this.adIdAnswerSentKey) === "denied")
2294
+ return;
2295
+ if (await this.post({ ...who, advertisingIdConsent: "denied" }, AD_ID_PATH)) {
2296
+ await store.setItem(this.adIdAnswerSentKey, "denied");
2297
+ await store.setItem(this.adIdSentKey, "");
2298
+ }
2299
+ return;
2300
+ }
2301
+ if (!this.collectsAdvertisingId)
2302
+ return;
2303
+ const consent = answer ? { advertisingIdConsent: answer } : {};
2226
2304
  const advertisingId = await this.readAdvertisingId();
2227
- if (!advertisingId || await store.getItem(this.adIdSentKey) === advertisingId)
2305
+ if (advertisingId) {
2306
+ if (await store.getItem(this.adIdSentKey) === advertisingId)
2307
+ return;
2308
+ if (await this.post({ ...who, advertisingId, ...consent }, AD_ID_PATH)) {
2309
+ await store.setItem(this.adIdSentKey, advertisingId);
2310
+ if (answer)
2311
+ await store.setItem(this.adIdAnswerSentKey, answer);
2312
+ }
2228
2313
  return;
2229
- const deviceId = (_a = this.context.deviceId) != null ? _a : await this.getOrCreateDeviceId();
2230
- if (await this.post({ deviceId, appUserId: this.opts.userId, advertisingId }, AD_ID_PATH)) {
2231
- await store.setItem(this.adIdSentKey, advertisingId);
2314
+ }
2315
+ if (answer === "granted" && await store.getItem(this.adIdAnswerSentKey) !== "granted") {
2316
+ if (await this.post({ ...who, advertisingIdConsent: "granted" }, AD_ID_PATH))
2317
+ await store.setItem(this.adIdAnswerSentKey, "granted");
2232
2318
  }
2233
2319
  } catch {
2234
2320
  }