@traqio/web 0.1.3 → 0.2.0
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/README.md +3 -0
- package/build/index.cjs +53 -8
- package/build/index.cjs.map +2 -2
- package/build/index.d.ts +10 -0
- package/build/index.js +53 -8
- 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.d.ts
CHANGED
|
@@ -25,6 +25,14 @@ export interface WebInitOptions {
|
|
|
25
25
|
trackIdDays?: number;
|
|
26
26
|
/** `false` = never write a cookie, localStorage only (no sharing across subdomains). Default `true`. */
|
|
27
27
|
cookies?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Debug mode. Omitted = on when the page is served from your machine (`localhost`,
|
|
30
|
+
* `127.0.0.1`, `*.localhost`, `*.local`, `file:`), off everywhere else. Debug
|
|
31
|
+
* traffic shows in the console's Live events › Debug view and is never counted,
|
|
32
|
+
* attributed, sent to an ad network or a webhook, or billed. `true` for a staging
|
|
33
|
+
* site, `false` to count a local page.
|
|
34
|
+
*/
|
|
35
|
+
debug?: boolean;
|
|
28
36
|
}
|
|
29
37
|
/** What `track()` accepts beside the event name. */
|
|
30
38
|
export interface WebTrackProps {
|
|
@@ -51,6 +59,8 @@ export declare class TraqioWeb {
|
|
|
51
59
|
* does nothing there.
|
|
52
60
|
*/
|
|
53
61
|
init(opts: WebInitOptions): Promise<void>;
|
|
62
|
+
/** Whether this page runs in debug mode — see `WebInitOptions.debug`. Settled by `init()`. */
|
|
63
|
+
get isDebug(): boolean;
|
|
54
64
|
/** Record an event — `signup`, `purchase`, `add_to_cart`… Batched, retried, kept across page loads. */
|
|
55
65
|
track(name: string, props?: WebTrackProps): void;
|
|
56
66
|
/** Set the user id once known (after sign-in). */
|
package/build/index.js
CHANGED
|
@@ -264,7 +264,8 @@ var require_adservices = __commonJS({
|
|
|
264
264
|
sdkKey: opts.sdkKey,
|
|
265
265
|
token: token.trim(),
|
|
266
266
|
deviceId: opts.deviceId,
|
|
267
|
-
appUserId: opts.userId
|
|
267
|
+
appUserId: opts.userId,
|
|
268
|
+
...opts.debug ? { debug: true } : {}
|
|
268
269
|
})
|
|
269
270
|
});
|
|
270
271
|
if (!res.ok)
|
|
@@ -364,10 +365,12 @@ var require_build = __commonJS({
|
|
|
364
365
|
exports.Traqio = exports.Client = exports.isTrackingUrl = exports.isOpenUrl = exports.reportAdServicesToken = exports.Skan = exports.SDK_VERSION = void 0;
|
|
365
366
|
exports.normalizeAdvertisingId = normalizeAdvertisingId;
|
|
366
367
|
exports.fromMaxAd = fromMaxAd;
|
|
368
|
+
exports.detectDebug = detectDebug;
|
|
369
|
+
exports.isLocalPage = isLocalPage;
|
|
367
370
|
var skan_1 = require_skan();
|
|
368
371
|
var adservices_1 = require_adservices();
|
|
369
372
|
var deeplink_1 = require_deeplink();
|
|
370
|
-
exports.SDK_VERSION = "0.
|
|
373
|
+
exports.SDK_VERSION = "0.3.0";
|
|
371
374
|
var skan_2 = require_skan();
|
|
372
375
|
Object.defineProperty(exports, "Skan", { enumerable: true, get: function() {
|
|
373
376
|
return skan_2.Skan;
|
|
@@ -384,6 +387,7 @@ var require_build = __commonJS({
|
|
|
384
387
|
return deeplink_2.isTrackingUrl;
|
|
385
388
|
} });
|
|
386
389
|
var INSTALL_SENT_KEY = "traq_install_sent";
|
|
390
|
+
var INSTALL_SENT_DEBUG_KEY = "traq_install_sent_debug";
|
|
387
391
|
var INSTALL_ATTEMPTS_KEY = "traq_install_attempts";
|
|
388
392
|
var REFERRER_KEY = "traq_referrer";
|
|
389
393
|
var QUEUE_KEY = "traq_queue";
|
|
@@ -492,6 +496,11 @@ var require_build = __commonJS({
|
|
|
492
496
|
this.undelivered = [];
|
|
493
497
|
this.deferred = null;
|
|
494
498
|
this.consent = null;
|
|
499
|
+
this.debug = false;
|
|
500
|
+
}
|
|
501
|
+
/** Whether this run is in debug mode — see `InitOptions.debug`. Settled by `init()`. */
|
|
502
|
+
get isDebug() {
|
|
503
|
+
return this.debug;
|
|
495
504
|
}
|
|
496
505
|
async init(opts) {
|
|
497
506
|
var _a;
|
|
@@ -502,6 +511,7 @@ var require_build = __commonJS({
|
|
|
502
511
|
if (!this.opts.storage) {
|
|
503
512
|
console.warn("[traqio] no storage available \u2014 pass `storage` to init() or install @react-native-async-storage/async-storage, otherwise the install is re-sent at every launch.");
|
|
504
513
|
}
|
|
514
|
+
this.debug = await detectDebug(opts);
|
|
505
515
|
await this.restoreConsent(opts.consent);
|
|
506
516
|
await this.restoreQueue();
|
|
507
517
|
await this.restoreAdQueue();
|
|
@@ -509,7 +519,7 @@ var require_build = __commonJS({
|
|
|
509
519
|
if (await this.restoreErased())
|
|
510
520
|
return;
|
|
511
521
|
if (!this.isWeb) {
|
|
512
|
-
const freshInstall = Boolean(this.opts.storage) && !await this.opts.storage.getItem(
|
|
522
|
+
const freshInstall = Boolean(this.opts.storage) && !await this.opts.storage.getItem(this.installSentKey).catch(() => "1");
|
|
513
523
|
await this.sendInstallOnce();
|
|
514
524
|
if (this.opts.deepLinking !== false) {
|
|
515
525
|
this.deferred = this.resolveDeferredOnce(freshInstall).then((link) => link != null ? link : this.retryDeferredWithConsent());
|
|
@@ -772,7 +782,8 @@ var require_build = __commonJS({
|
|
|
772
782
|
deviceId: this.context.deviceId,
|
|
773
783
|
userId: this.opts.userId,
|
|
774
784
|
storage: this.opts.storage,
|
|
775
|
-
native: { getAttributionToken: () => native.getAttributionToken() }
|
|
785
|
+
native: { getAttributionToken: () => native.getAttributionToken() },
|
|
786
|
+
debug: this.debug
|
|
776
787
|
});
|
|
777
788
|
}
|
|
778
789
|
async initSkan() {
|
|
@@ -910,6 +921,13 @@ var require_build = __commonJS({
|
|
|
910
921
|
var _a;
|
|
911
922
|
return ((_a = this.opts) == null ? void 0 : _a.platform) === "web";
|
|
912
923
|
}
|
|
924
|
+
get installSentKey() {
|
|
925
|
+
return this.debug ? INSTALL_SENT_DEBUG_KEY : INSTALL_SENT_KEY;
|
|
926
|
+
}
|
|
927
|
+
/** Spread into every body: present only in debug mode, so a release build's payload is unchanged. */
|
|
928
|
+
debugField() {
|
|
929
|
+
return this.debug ? { debug: true } : {};
|
|
930
|
+
}
|
|
913
931
|
wireLifecycle() {
|
|
914
932
|
const events = {
|
|
915
933
|
background: () => this.flush(),
|
|
@@ -1121,7 +1139,7 @@ var require_build = __commonJS({
|
|
|
1121
1139
|
async sendInstallOnce() {
|
|
1122
1140
|
var _a, _b;
|
|
1123
1141
|
const store = this.opts.storage;
|
|
1124
|
-
if (store && await store.getItem(
|
|
1142
|
+
if (store && await store.getItem(this.installSentKey))
|
|
1125
1143
|
return;
|
|
1126
1144
|
const platform = (_b = (_a = this.opts.native) == null ? void 0 : _a.platform) != null ? _b : "android";
|
|
1127
1145
|
const referrer = await this.readReferrer();
|
|
@@ -1142,7 +1160,7 @@ var require_build = __commonJS({
|
|
|
1142
1160
|
}
|
|
1143
1161
|
});
|
|
1144
1162
|
if (ok)
|
|
1145
|
-
await (store == null ? void 0 : store.setItem(
|
|
1163
|
+
await (store == null ? void 0 : store.setItem(this.installSentKey, "1"));
|
|
1146
1164
|
}
|
|
1147
1165
|
scheduleFlush(delay = FLUSH_DELAY_MS) {
|
|
1148
1166
|
if (this.flushTimer)
|
|
@@ -1217,7 +1235,7 @@ var require_build = __commonJS({
|
|
|
1217
1235
|
const res = await fetch(`${this.opts.endpoint}${path}`, {
|
|
1218
1236
|
method: "POST",
|
|
1219
1237
|
headers: { "Content-Type": "application/json" },
|
|
1220
|
-
body: JSON.stringify({ sdkKey: this.opts.sdkKey, ...body }),
|
|
1238
|
+
body: JSON.stringify({ sdkKey: this.opts.sdkKey, ...body, ...this.debugField() }),
|
|
1221
1239
|
...this.keepalive()
|
|
1222
1240
|
});
|
|
1223
1241
|
return res.ok ? await res.json() : null;
|
|
@@ -1262,7 +1280,7 @@ var require_build = __commonJS({
|
|
|
1262
1280
|
const res = await fetch(`${this.opts.endpoint}${path}`, {
|
|
1263
1281
|
method: "POST",
|
|
1264
1282
|
headers: { "Content-Type": "application/json" },
|
|
1265
|
-
body: JSON.stringify({ sdkKey: this.opts.sdkKey, ...body, ...consent }),
|
|
1283
|
+
body: JSON.stringify({ sdkKey: this.opts.sdkKey, ...body, ...consent, ...this.debugField() }),
|
|
1266
1284
|
...this.keepalive()
|
|
1267
1285
|
});
|
|
1268
1286
|
if (res.ok)
|
|
@@ -1274,6 +1292,28 @@ var require_build = __commonJS({
|
|
|
1274
1292
|
}
|
|
1275
1293
|
};
|
|
1276
1294
|
exports.Client = Client2;
|
|
1295
|
+
async function detectDebug(opts) {
|
|
1296
|
+
var _a, _b;
|
|
1297
|
+
if (opts.debug !== void 0)
|
|
1298
|
+
return opts.debug;
|
|
1299
|
+
if (opts.platform === "web")
|
|
1300
|
+
return isLocalPage();
|
|
1301
|
+
if (globalThis.__DEV__ === true)
|
|
1302
|
+
return true;
|
|
1303
|
+
try {
|
|
1304
|
+
return await ((_b = (_a = opts.native) == null ? void 0 : _a.isDebugBuild) == null ? void 0 : _b.call(_a)) === true;
|
|
1305
|
+
} catch {
|
|
1306
|
+
return false;
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
function isLocalPage(loc = globalThis.location) {
|
|
1310
|
+
if (!loc)
|
|
1311
|
+
return false;
|
|
1312
|
+
if (loc.protocol === "file:")
|
|
1313
|
+
return true;
|
|
1314
|
+
const host = loc.hostname.toLowerCase().replace(/^\[|\]$/g, "");
|
|
1315
|
+
return host === "localhost" || host.endsWith(".localhost") || host.endsWith(".local") || host === "::1" || host === "0.0.0.0" || /^127\.\d+\.\d+\.\d+$/.test(host);
|
|
1316
|
+
}
|
|
1277
1317
|
exports.Traqio = new Client2();
|
|
1278
1318
|
}
|
|
1279
1319
|
});
|
|
@@ -1558,12 +1598,17 @@ var TraqioWeb = class {
|
|
|
1558
1598
|
platform: "web",
|
|
1559
1599
|
userId: opts.userId,
|
|
1560
1600
|
consent,
|
|
1601
|
+
debug: opts.debug,
|
|
1561
1602
|
lifecycle: ({ background, foreground }) => {
|
|
1562
1603
|
document.addEventListener("visibilitychange", () => document.visibilityState === "hidden" ? background() : foreground());
|
|
1563
1604
|
window.addEventListener("pagehide", background);
|
|
1564
1605
|
}
|
|
1565
1606
|
});
|
|
1566
1607
|
}
|
|
1608
|
+
/** Whether this page runs in debug mode — see `WebInitOptions.debug`. Settled by `init()`. */
|
|
1609
|
+
get isDebug() {
|
|
1610
|
+
return this.core.isDebug;
|
|
1611
|
+
}
|
|
1567
1612
|
/** Record an event — `signup`, `purchase`, `add_to_cart`… Batched, retried, kept across page loads. */
|
|
1568
1613
|
track(name, props) {
|
|
1569
1614
|
this.core.track(name, props);
|