@traqio/web 0.1.2 → 0.1.3
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 +142 -12
- package/build/index.cjs.map +2 -2
- package/build/index.js +142 -12
- package/build/index.js.map +2 -2
- package/build/traqio.min.js +1 -1
- package/build/traqio.min.js.map +3 -3
- package/package.json +2 -2
package/build/index.js
CHANGED
|
@@ -299,17 +299,51 @@ var require_deeplink = __commonJS({
|
|
|
299
299
|
"use strict";
|
|
300
300
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
301
301
|
exports.isTrackingUrl = isTrackingUrl;
|
|
302
|
+
exports.isOpenUrl = isOpenUrl;
|
|
302
303
|
exports.toDeepLink = toDeepLink;
|
|
304
|
+
exports.upgradeStoredDeepLink = upgradeStoredDeepLink;
|
|
303
305
|
var TRACKING_PATH = /^\/c\/[A-Za-z0-9_-]{1,50}\/?$/;
|
|
304
|
-
|
|
306
|
+
var OPEN_PATH = /^\/o\/[0-9a-fA-F-]{36}\/?$/;
|
|
307
|
+
function pathOf(url) {
|
|
305
308
|
var _a;
|
|
306
309
|
const m = /^https?:\/\/[^/?#]+(\/[^?#]*)?/i.exec(url);
|
|
307
|
-
return
|
|
310
|
+
return m ? (_a = m[1]) != null ? _a : "" : null;
|
|
311
|
+
}
|
|
312
|
+
function isTrackingUrl(url) {
|
|
313
|
+
const path = pathOf(url);
|
|
314
|
+
return path !== null && (TRACKING_PATH.test(path) || OPEN_PATH.test(path));
|
|
315
|
+
}
|
|
316
|
+
function isOpenUrl(url) {
|
|
317
|
+
const path = pathOf(url);
|
|
318
|
+
return path !== null && OPEN_PATH.test(path);
|
|
308
319
|
}
|
|
309
320
|
function toDeepLink(answer, deferred, url) {
|
|
321
|
+
var _a, _b, _c;
|
|
310
322
|
if (!(answer == null ? void 0 : answer.matched) || !answer.via)
|
|
311
323
|
return null;
|
|
312
|
-
|
|
324
|
+
const matchType = (_a = answer.matchType) != null ? _a : answer.via === "ip_match" ? "probabilistic" : answer.via;
|
|
325
|
+
const payload = (_b = answer.payload) != null ? _b : { deepLink: answer.deepLink, value: null, params: {} };
|
|
326
|
+
return {
|
|
327
|
+
payload,
|
|
328
|
+
matchType,
|
|
329
|
+
confidence: matchType === "probabilistic" ? (_c = answer.confidence) != null ? _c : "low" : null,
|
|
330
|
+
deferred,
|
|
331
|
+
code: answer.code,
|
|
332
|
+
deepLink: payload.deepLink,
|
|
333
|
+
via: answer.via,
|
|
334
|
+
...url ? { url } : {}
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
function upgradeStoredDeepLink(stored) {
|
|
338
|
+
var _a, _b, _c;
|
|
339
|
+
if (!stored || typeof stored !== "object")
|
|
340
|
+
return null;
|
|
341
|
+
const link = stored;
|
|
342
|
+
if (link.payload && link.matchType)
|
|
343
|
+
return link;
|
|
344
|
+
if (!link.via)
|
|
345
|
+
return null;
|
|
346
|
+
return toDeepLink({ matched: true, via: link.via, code: (_a = link.code) != null ? _a : null, deepLink: (_b = link.deepLink) != null ? _b : null }, (_c = link.deferred) != null ? _c : true, link.url);
|
|
313
347
|
}
|
|
314
348
|
}
|
|
315
349
|
});
|
|
@@ -327,13 +361,13 @@ var require_build = __commonJS({
|
|
|
327
361
|
"../sdk-core/build/index.js"(exports) {
|
|
328
362
|
"use strict";
|
|
329
363
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
330
|
-
exports.Traqio = exports.Client = exports.isTrackingUrl = exports.reportAdServicesToken = exports.Skan = exports.SDK_VERSION = void 0;
|
|
364
|
+
exports.Traqio = exports.Client = exports.isTrackingUrl = exports.isOpenUrl = exports.reportAdServicesToken = exports.Skan = exports.SDK_VERSION = void 0;
|
|
331
365
|
exports.normalizeAdvertisingId = normalizeAdvertisingId;
|
|
332
366
|
exports.fromMaxAd = fromMaxAd;
|
|
333
367
|
var skan_1 = require_skan();
|
|
334
368
|
var adservices_1 = require_adservices();
|
|
335
369
|
var deeplink_1 = require_deeplink();
|
|
336
|
-
exports.SDK_VERSION = "0.
|
|
370
|
+
exports.SDK_VERSION = "0.2.0";
|
|
337
371
|
var skan_2 = require_skan();
|
|
338
372
|
Object.defineProperty(exports, "Skan", { enumerable: true, get: function() {
|
|
339
373
|
return skan_2.Skan;
|
|
@@ -343,6 +377,9 @@ var require_build = __commonJS({
|
|
|
343
377
|
return adservices_2.reportAdServicesToken;
|
|
344
378
|
} });
|
|
345
379
|
var deeplink_2 = require_deeplink();
|
|
380
|
+
Object.defineProperty(exports, "isOpenUrl", { enumerable: true, get: function() {
|
|
381
|
+
return deeplink_2.isOpenUrl;
|
|
382
|
+
} });
|
|
346
383
|
Object.defineProperty(exports, "isTrackingUrl", { enumerable: true, get: function() {
|
|
347
384
|
return deeplink_2.isTrackingUrl;
|
|
348
385
|
} });
|
|
@@ -355,6 +392,8 @@ var require_build = __commonJS({
|
|
|
355
392
|
var LAST_SESSION_KEY = "traq_last_session";
|
|
356
393
|
var ERASED_KEY = "traq_erased";
|
|
357
394
|
var DEFERRED_KEY = "traq_deferred_link";
|
|
395
|
+
var DEFERRED_RETRY_KEY = "traq_deferred_consent_retry_until";
|
|
396
|
+
var DEFERRED_RETRY_WINDOW_MS = 60 * 6e4;
|
|
358
397
|
var CONSENT_KEY = "traq_consent";
|
|
359
398
|
var MAX_BATCH = 20;
|
|
360
399
|
var NON_RETRYABLE_STATUS = /* @__PURE__ */ new Set([400, 413, 422]);
|
|
@@ -473,7 +512,7 @@ var require_build = __commonJS({
|
|
|
473
512
|
const freshInstall = Boolean(this.opts.storage) && !await this.opts.storage.getItem(INSTALL_SENT_KEY).catch(() => "1");
|
|
474
513
|
await this.sendInstallOnce();
|
|
475
514
|
if (this.opts.deepLinking !== false) {
|
|
476
|
-
this.deferred = this.resolveDeferredOnce(freshInstall);
|
|
515
|
+
this.deferred = this.resolveDeferredOnce(freshInstall).then((link) => link != null ? link : this.retryDeferredWithConsent());
|
|
477
516
|
this.wireDeepLinks();
|
|
478
517
|
}
|
|
479
518
|
}
|
|
@@ -591,20 +630,47 @@ var require_build = __commonJS({
|
|
|
591
630
|
if (!this.started || this.erased || this.opts.deepLinking === false || !(0, deeplink_1.isTrackingUrl)(url))
|
|
592
631
|
return null;
|
|
593
632
|
const answer = await this.postJson({ url }, "/deeplink/open");
|
|
594
|
-
const
|
|
633
|
+
const deferred = (0, deeplink_1.isOpenUrl)(url);
|
|
634
|
+
const link = (0, deeplink_1.toDeepLink)(answer, deferred, url);
|
|
635
|
+
if (link && deferred)
|
|
636
|
+
await this.keepDeferred(link);
|
|
595
637
|
if (link)
|
|
596
638
|
this.emitDeepLink(link);
|
|
597
639
|
return link;
|
|
598
640
|
}
|
|
599
641
|
/**
|
|
600
|
-
* The deferred deep link of this install, if it came from one — resolved
|
|
601
|
-
*
|
|
602
|
-
*
|
|
642
|
+
* The deferred deep link of this install, if it came from one — resolved on the
|
|
643
|
+
* first launch and remembered. Null on every install that did not come from a
|
|
644
|
+
* link. `matchType` says how it was found; read `payload.value` for the token the
|
|
645
|
+
* shared URL carried (`deep_link_value`).
|
|
646
|
+
*
|
|
647
|
+
* iOS has no install referrer: the deterministic carriers there are the landing
|
|
648
|
+
* page's « Open in app » link (delivered through `handleUrl` / `onDeepLink`) and
|
|
649
|
+
* its code (`redeemDeepLinkCode`). The probabilistic fallback runs only when the
|
|
650
|
+
* user consented — `setConsent(true)` or `consent: true` at init — and the app
|
|
651
|
+
* turned the IP match on in the console.
|
|
603
652
|
*/
|
|
604
653
|
getDeferredDeepLink() {
|
|
605
654
|
var _a;
|
|
606
655
|
return (_a = this.deferred) != null ? _a : Promise.resolve(null);
|
|
607
656
|
}
|
|
657
|
+
/**
|
|
658
|
+
* The code the iOS landing page showed (« ABCD-EFGH »), typed by the user in the
|
|
659
|
+
* app — the manual fallback when neither the store nor a link carried the click.
|
|
660
|
+
* Case, spaces and the dash are forgiven. Resolves to the link (`matchType:
|
|
661
|
+
* "code"`), delivered to `onDeepLink` too, or null for an unknown / expired code.
|
|
662
|
+
*/
|
|
663
|
+
async redeemDeepLinkCode(code) {
|
|
664
|
+
if (!this.started || this.erased || this.opts.deepLinking === false || !code.trim())
|
|
665
|
+
return null;
|
|
666
|
+
const answer = await this.postJson({ code }, "/deeplink/code");
|
|
667
|
+
const link = (0, deeplink_1.toDeepLink)(answer, true);
|
|
668
|
+
if (!link)
|
|
669
|
+
return null;
|
|
670
|
+
await this.keepDeferred(link);
|
|
671
|
+
this.emitDeepLink(link);
|
|
672
|
+
return link;
|
|
673
|
+
}
|
|
608
674
|
/**
|
|
609
675
|
* GDPR Art. 17, from inside the app: delete everything the server holds about this
|
|
610
676
|
* device and this user, and stop sending.
|
|
@@ -648,6 +714,10 @@ var require_build = __commonJS({
|
|
|
648
714
|
var _a, _b;
|
|
649
715
|
this.consent = granted ? "granted" : "denied";
|
|
650
716
|
await ((_b = (_a = this.opts) == null ? void 0 : _a.storage) == null ? void 0 : _b.setItem(CONSENT_KEY, this.consent).catch(() => void 0));
|
|
717
|
+
if (granted && this.deferred && !this.erased) {
|
|
718
|
+
this.deferred = this.deferred.then((link) => link != null ? link : this.retryDeferredWithConsent());
|
|
719
|
+
await this.deferred;
|
|
720
|
+
}
|
|
651
721
|
}
|
|
652
722
|
/** True once `forgetMe()` has been honoured — this install sends nothing any more. */
|
|
653
723
|
get forgotten() {
|
|
@@ -734,7 +804,7 @@ var require_build = __commonJS({
|
|
|
734
804
|
try {
|
|
735
805
|
const cached = await (store == null ? void 0 : store.getItem(DEFERRED_KEY));
|
|
736
806
|
if (cached)
|
|
737
|
-
return JSON.parse(cached);
|
|
807
|
+
return (0, deeplink_1.upgradeStoredDeepLink)(JSON.parse(cached));
|
|
738
808
|
} catch {
|
|
739
809
|
}
|
|
740
810
|
if (!freshInstall && !await (store == null ? void 0 : store.getItem(`${DEFERRED_KEY}_pending`).catch(() => null)))
|
|
@@ -742,18 +812,78 @@ var require_build = __commonJS({
|
|
|
742
812
|
const platform = (_b = (_a = this.opts.native) == null ? void 0 : _a.platform) != null ? _b : "android";
|
|
743
813
|
const referrer = platform === "android" ? await this.readReferrer() : null;
|
|
744
814
|
await (store == null ? void 0 : store.setItem(`${DEFERRED_KEY}_pending`, "1").catch(() => void 0));
|
|
745
|
-
const answer = await this.
|
|
815
|
+
const answer = await this.askDeferred(platform, referrer == null ? void 0 : referrer.referrer);
|
|
746
816
|
if (!answer)
|
|
747
817
|
return null;
|
|
748
818
|
const link = (0, deeplink_1.toDeepLink)(answer, true);
|
|
819
|
+
const kept = await this.storedDeferred();
|
|
820
|
+
if (kept)
|
|
821
|
+
return kept;
|
|
749
822
|
try {
|
|
750
823
|
await (store == null ? void 0 : store.setItem(DEFERRED_KEY, JSON.stringify(link)));
|
|
824
|
+
if (!link && this.consent !== "granted") {
|
|
825
|
+
await (store == null ? void 0 : store.setItem(DEFERRED_RETRY_KEY, String(Date.now() + DEFERRED_RETRY_WINDOW_MS)));
|
|
826
|
+
}
|
|
751
827
|
} catch {
|
|
752
828
|
}
|
|
753
829
|
if (link)
|
|
754
830
|
this.emitDeepLink(link);
|
|
755
831
|
return link;
|
|
756
832
|
}
|
|
833
|
+
/** The deferred ask: the referrer (Android), the consent, and what the tap is compared with. */
|
|
834
|
+
askDeferred(platform, installReferrer) {
|
|
835
|
+
return this.postJson({
|
|
836
|
+
platform,
|
|
837
|
+
installReferrer,
|
|
838
|
+
...this.consent ? { consent: this.consent } : {},
|
|
839
|
+
...this.context.osVersion ? { osVersion: this.context.osVersion } : {},
|
|
840
|
+
...this.context.deviceModel ? { deviceModel: this.context.deviceModel } : {}
|
|
841
|
+
}, "/deeplink/deferred");
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* The user consented AFTER the first launch asked without consent and found
|
|
845
|
+
* nothing: ask once more, inside the hour, so the probabilistic layer can run.
|
|
846
|
+
* Never when a link is already known, never twice.
|
|
847
|
+
*/
|
|
848
|
+
async retryDeferredWithConsent() {
|
|
849
|
+
var _a, _b, _c, _d;
|
|
850
|
+
const store = (_a = this.opts) == null ? void 0 : _a.storage;
|
|
851
|
+
if (!store || this.consent !== "granted" || this.opts.deepLinking === false || this.isWeb)
|
|
852
|
+
return null;
|
|
853
|
+
const until = Number(await store.getItem(DEFERRED_RETRY_KEY).catch(() => null));
|
|
854
|
+
if (!until)
|
|
855
|
+
return null;
|
|
856
|
+
await store.setItem(DEFERRED_RETRY_KEY, "").catch(() => void 0);
|
|
857
|
+
if (Date.now() > until)
|
|
858
|
+
return null;
|
|
859
|
+
const known = await this.storedDeferred();
|
|
860
|
+
if (known)
|
|
861
|
+
return known;
|
|
862
|
+
const link = (0, deeplink_1.toDeepLink)(await this.askDeferred((_c = (_b = this.opts.native) == null ? void 0 : _b.platform) != null ? _c : "ios", void 0), true);
|
|
863
|
+
if (!link)
|
|
864
|
+
return null;
|
|
865
|
+
await ((_d = this.opts.storage) == null ? void 0 : _d.setItem(DEFERRED_KEY, JSON.stringify(link)).catch(() => void 0));
|
|
866
|
+
this.emitDeepLink(link);
|
|
867
|
+
return link;
|
|
868
|
+
}
|
|
869
|
+
/** The deferred link already stored for this install, if any. */
|
|
870
|
+
async storedDeferred() {
|
|
871
|
+
var _a;
|
|
872
|
+
try {
|
|
873
|
+
const raw = await ((_a = this.opts.storage) == null ? void 0 : _a.getItem(DEFERRED_KEY));
|
|
874
|
+
return raw ? (0, deeplink_1.upgradeStoredDeepLink)(JSON.parse(raw)) : null;
|
|
875
|
+
} catch {
|
|
876
|
+
return null;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
/** Remember `link` as this install's deferred link, unless one is already known. */
|
|
880
|
+
async keepDeferred(link) {
|
|
881
|
+
var _a;
|
|
882
|
+
if (await this.storedDeferred())
|
|
883
|
+
return;
|
|
884
|
+
await ((_a = this.opts.storage) == null ? void 0 : _a.setItem(DEFERRED_KEY, JSON.stringify(link)).catch(() => void 0));
|
|
885
|
+
this.deferred = Promise.resolve(link);
|
|
886
|
+
}
|
|
757
887
|
emitDeepLink(link) {
|
|
758
888
|
if (!this.deepLinkListeners.size) {
|
|
759
889
|
this.undelivered.push(link);
|