@traqio/web 0.6.0 → 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.cjs CHANGED
@@ -815,6 +815,7 @@ var require_build = __commonJS({
815
815
  "use strict";
816
816
  Object.defineProperty(exports, "__esModule", { value: true });
817
817
  exports.Traqio = exports.Client = exports.AdRevenueGate = 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.ANALYTICS_SESSION_IDLE_MS = exports.reportAdServicesToken = exports.Skan = exports.SDK_VERSION = void 0;
818
+ exports.normalizeMetaInstallReferrers = normalizeMetaInstallReferrers;
818
819
  exports.normalizeAdvertisingId = normalizeAdvertisingId;
819
820
  exports.fromMaxAd = fromMaxAd;
820
821
  exports.detectDebug = detectDebug;
@@ -824,7 +825,7 @@ var require_build = __commonJS({
824
825
  var adservices_1 = require_adservices();
825
826
  var deeplink_1 = require_deeplink();
826
827
  var adRevenue_1 = require_adRevenue();
827
- exports.SDK_VERSION = "0.9.0";
828
+ exports.SDK_VERSION = "0.11.0";
828
829
  var skan_2 = require_skan();
829
830
  Object.defineProperty(exports, "Skan", { enumerable: true, get: function() {
830
831
  return skan_2.Skan;
@@ -887,6 +888,9 @@ var require_build = __commonJS({
887
888
  var AD_ID_SENT_KEY = "traq_ad_id_sent";
888
889
  var AD_ID_SENT_DEBUG_KEY = "traq_ad_id_sent_debug";
889
890
  var AD_ID_PATH = "/ingest/advertising-id";
891
+ var AD_ID_CONSENT_KEY = "traq_ad_id_consent";
892
+ var AD_ID_ANSWER_SENT_KEY = "traq_ad_id_answer_sent";
893
+ var AD_ID_ANSWER_SENT_DEBUG_KEY = "traq_ad_id_answer_sent_debug";
890
894
  var REFERRER_KEY = "traq_referrer";
891
895
  var QUEUE_KEY = "traq_queue";
892
896
  var AD_QUEUE_KEY = "traq_ad_queue";
@@ -915,6 +919,32 @@ var require_build = __commonJS({
915
919
  var FLUSH_DELAY_MS = 3e3;
916
920
  var MAX_INSTALL_ATTEMPTS = 3;
917
921
  var SESSION_TIMEOUT_MS = 30 * 60 * 1e3;
922
+ var META_PROVIDERS = ["facebook", "instagram", "facebook_lite"];
923
+ function normalizeMetaInstallReferrers(raw) {
924
+ if (!Array.isArray(raw))
925
+ return [];
926
+ const out = [];
927
+ for (const item of raw) {
928
+ if (!item || typeof item !== "object")
929
+ continue;
930
+ const r = item;
931
+ if (typeof r.provider !== "string" || !META_PROVIDERS.includes(r.provider))
932
+ continue;
933
+ if (typeof r.installReferrer !== "string" || !r.installReferrer.trim())
934
+ continue;
935
+ const isCt = r.isCt === 1 || r.isCt === true ? 1 : r.isCt === 0 || r.isCt === false ? 0 : null;
936
+ if (isCt === null)
937
+ continue;
938
+ const ts = typeof r.actualTimestamp === "number" && Number.isFinite(r.actualTimestamp) && r.actualTimestamp > 0 ? r.actualTimestamp : void 0;
939
+ out.push({
940
+ provider: r.provider,
941
+ installReferrer: r.installReferrer,
942
+ isCt,
943
+ ...ts !== void 0 ? { actualTimestamp: ts } : {}
944
+ });
945
+ }
946
+ return out;
947
+ }
918
948
  var TRACKING_AUTHORIZATIONS = ["not_determined", "restricted", "denied", "authorized"];
919
949
  var MAX_PRECISION = {
920
950
  exact: "precise",
@@ -1014,6 +1044,7 @@ var require_build = __commonJS({
1014
1044
  this.deferred = null;
1015
1045
  this.consent = null;
1016
1046
  this.att = null;
1047
+ this.adIdConsent = null;
1017
1048
  this.adIdSync = null;
1018
1049
  this.debug = false;
1019
1050
  this.analyticsQueue = [];
@@ -1048,6 +1079,7 @@ var require_build = __commonJS({
1048
1079
  }
1049
1080
  this.debug = await detectDebug(opts);
1050
1081
  await this.restoreConsent(opts.consent);
1082
+ await this.restoreAdvertisingIdConsent();
1051
1083
  await this.restoreQueue();
1052
1084
  await this.restoreAdQueue();
1053
1085
  await this.restoreAnalytics();
@@ -1589,6 +1621,37 @@ var require_build = __commonJS({
1589
1621
  await this.deferred;
1590
1622
  }
1591
1623
  }
1624
+ /**
1625
+ * The user's answer to YOUR advertising-id consent (GDPR / ePrivacy CMP, ATT prompt)
1626
+ * — HQ todo cmx4z20d. Call it once the user has answered, at any launch; persisted.
1627
+ *
1628
+ * `true` turns IDFA / GAID collection on from now: the SDK reads the id (never
1629
+ * prompting) and sends it once. With `waitForAdvertisingIdConsent` at init, the
1630
+ * install's Meta / TikTok postback was held for it and now leaves with it. On iOS,
1631
+ * call it AFTER your ATT prompt: the IDFA exists only once ATT is authorized (a yes
1632
+ * before that releases the install without it; the IDFA follows at the next
1633
+ * foreground for later conversions).
1634
+ *
1635
+ * `false` stops collection, tells the server to forget an id it kept from an
1636
+ * earlier yes, and lets a held install leave without one. First-party measurement
1637
+ * is unchanged either way.
1638
+ *
1639
+ * Traqio.setAdvertisingIdConsent(cmp.hasConsentFor("ads"));
1640
+ *
1641
+ * Overrides `collectAdvertisingId` once called. Android still needs Google's
1642
+ * `play-services-ads-identifier` and the `AD_ID` permission in the app.
1643
+ */
1644
+ async setAdvertisingIdConsent(granted) {
1645
+ var _a, _b;
1646
+ this.adIdConsent = granted ? "granted" : "denied";
1647
+ if (!this.started || !this.opts)
1648
+ return;
1649
+ await ((_a = this.opts.storage) == null ? void 0 : _a.setItem(AD_ID_CONSENT_KEY, this.adIdConsent).catch(() => void 0));
1650
+ if (this.isWeb || this.erased)
1651
+ return;
1652
+ await ((_b = this.adIdSync) == null ? void 0 : _b.catch(() => void 0));
1653
+ await this.syncAdvertisingId();
1654
+ }
1592
1655
  /** True once `forgetMe()` has been honoured — this install sends nothing any more. */
1593
1656
  get forgotten() {
1594
1657
  return this.erased;
@@ -1787,6 +1850,31 @@ var require_build = __commonJS({
1787
1850
  get adIdSentKey() {
1788
1851
  return this.debug ? AD_ID_SENT_DEBUG_KEY : AD_ID_SENT_KEY;
1789
1852
  }
1853
+ get adIdAnswerSentKey() {
1854
+ return this.debug ? AD_ID_ANSWER_SENT_DEBUG_KEY : AD_ID_ANSWER_SENT_KEY;
1855
+ }
1856
+ /**
1857
+ * May the advertising id be read right now? The user's stored answer first; then,
1858
+ * for an app that said it would ask, no until it has; then the init opt-in.
1859
+ */
1860
+ get collectsAdvertisingId() {
1861
+ if (this.adIdConsent)
1862
+ return this.adIdConsent === "granted";
1863
+ if (this.opts.waitForAdvertisingIdConsent)
1864
+ return false;
1865
+ return this.opts.collectAdvertisingId === true;
1866
+ }
1867
+ /** A `setAdvertisingIdConsent()` made before `init()` wins over the stored answer. */
1868
+ async restoreAdvertisingIdConsent() {
1869
+ var _a, _b;
1870
+ if (this.adIdConsent) {
1871
+ await ((_a = this.opts.storage) == null ? void 0 : _a.setItem(AD_ID_CONSENT_KEY, this.adIdConsent).catch(() => void 0));
1872
+ return;
1873
+ }
1874
+ const stored = await ((_b = this.opts.storage) == null ? void 0 : _b.getItem(AD_ID_CONSENT_KEY).catch(() => null));
1875
+ if (stored === "granted" || stored === "denied")
1876
+ this.adIdConsent = stored;
1877
+ }
1790
1878
  /** Spread into every body: present only in debug mode, so a release build's payload is unchanged. */
1791
1879
  debugField() {
1792
1880
  return this.debug ? { debug: true } : {};
@@ -2109,10 +2197,28 @@ var require_build = __commonJS({
2109
2197
  }
2110
2198
  return result;
2111
2199
  }
2200
+ /**
2201
+ * Meta's Install Referrer answers, Android only, read just before the install
2202
+ * leaves. Never throws: an old native build, a bridge teardown or no Meta app
2203
+ * installed all mean « no field ».
2204
+ */
2205
+ async readMetaInstallReferrers(platform) {
2206
+ var _a, _b;
2207
+ const read = (_a = this.opts.native) == null ? void 0 : _a.getMetaInstallReferrers;
2208
+ if (platform !== "android" || !read)
2209
+ return void 0;
2210
+ try {
2211
+ const appId = ((_b = this.opts.metaAppId) == null ? void 0 : _b.trim()) || void 0;
2212
+ const list = normalizeMetaInstallReferrers(await read.call(this.opts.native, appId));
2213
+ return list.length ? list : void 0;
2214
+ } catch {
2215
+ return void 0;
2216
+ }
2217
+ }
2112
2218
  /** Only with the host's opt-in; a zeroed or malformed id is never sent. */
2113
2219
  async readAdvertisingId() {
2114
2220
  var _a;
2115
- if (!this.opts.collectAdvertisingId || !((_a = this.opts.native) == null ? void 0 : _a.getAdvertisingId))
2221
+ if (!this.collectsAdvertisingId || !((_a = this.opts.native) == null ? void 0 : _a.getAdvertisingId))
2116
2222
  return void 0;
2117
2223
  try {
2118
2224
  return normalizeAdvertisingId(await this.opts.native.getAdvertisingId());
@@ -2141,12 +2247,16 @@ var require_build = __commonJS({
2141
2247
  }
2142
2248
  }
2143
2249
  const advertisingId = await this.readAdvertisingId();
2250
+ const metaInstallReferrers = await this.readMetaInstallReferrers(platform);
2144
2251
  const ok = await this.post({
2145
2252
  install: {
2146
2253
  platform,
2147
2254
  installReferrer: referrer.referrer,
2255
+ ...metaInstallReferrers ? { metaInstallReferrers } : {},
2148
2256
  appUserId: this.opts.userId,
2149
2257
  advertisingId,
2258
+ // The app has not asked yet: the server holds the install postback for the id.
2259
+ ...this.opts.waitForAdvertisingIdConsent && !this.adIdConsent ? { advertisingIdPending: true } : {},
2150
2260
  context: this.context
2151
2261
  }
2152
2262
  });
@@ -2176,17 +2286,40 @@ var require_build = __commonJS({
2176
2286
  async postAdvertisingIdIfChanged() {
2177
2287
  var _a;
2178
2288
  const store = this.opts.storage;
2179
- if (this.isWeb || this.erased || !store || !this.opts.collectAdvertisingId)
2289
+ if (this.isWeb || this.erased || !store)
2180
2290
  return;
2181
2291
  try {
2182
2292
  if (!await store.getItem(this.installSentKey))
2183
2293
  return;
2294
+ const answer = this.adIdConsent;
2295
+ const deviceId = (_a = this.context.deviceId) != null ? _a : await this.getOrCreateDeviceId();
2296
+ const who = { deviceId, appUserId: this.opts.userId };
2297
+ if (answer === "denied") {
2298
+ if (await store.getItem(this.adIdAnswerSentKey) === "denied")
2299
+ return;
2300
+ if (await this.post({ ...who, advertisingIdConsent: "denied" }, AD_ID_PATH)) {
2301
+ await store.setItem(this.adIdAnswerSentKey, "denied");
2302
+ await store.setItem(this.adIdSentKey, "");
2303
+ }
2304
+ return;
2305
+ }
2306
+ if (!this.collectsAdvertisingId)
2307
+ return;
2308
+ const consent = answer ? { advertisingIdConsent: answer } : {};
2184
2309
  const advertisingId = await this.readAdvertisingId();
2185
- if (!advertisingId || await store.getItem(this.adIdSentKey) === advertisingId)
2310
+ if (advertisingId) {
2311
+ if (await store.getItem(this.adIdSentKey) === advertisingId)
2312
+ return;
2313
+ if (await this.post({ ...who, advertisingId, ...consent }, AD_ID_PATH)) {
2314
+ await store.setItem(this.adIdSentKey, advertisingId);
2315
+ if (answer)
2316
+ await store.setItem(this.adIdAnswerSentKey, answer);
2317
+ }
2186
2318
  return;
2187
- const deviceId = (_a = this.context.deviceId) != null ? _a : await this.getOrCreateDeviceId();
2188
- if (await this.post({ deviceId, appUserId: this.opts.userId, advertisingId }, AD_ID_PATH)) {
2189
- await store.setItem(this.adIdSentKey, advertisingId);
2319
+ }
2320
+ if (answer === "granted" && await store.getItem(this.adIdAnswerSentKey) !== "granted") {
2321
+ if (await this.post({ ...who, advertisingIdConsent: "granted" }, AD_ID_PATH))
2322
+ await store.setItem(this.adIdAnswerSentKey, "granted");
2190
2323
  }
2191
2324
  } catch {
2192
2325
  }