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