@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/README.md
CHANGED
|
@@ -112,6 +112,9 @@ networks.
|
|
|
112
112
|
| `waitForConsent` | `false` | Store nothing until `setConsent(true)` |
|
|
113
113
|
| `trackIdDays` | `30` | How long the trackID is kept after the click |
|
|
114
114
|
| `cookies` | `true` | `false` = localStorage only, no sharing across subdomains |
|
|
115
|
+
| `debug` | detected | Debug traffic, kept out of every report (see below) |
|
|
116
|
+
|
|
117
|
+
**Debug traffic.** Omitted, `debug` is on for a page served from `localhost`, `127.0.0.1`, `*.localhost`, `*.local` or `file:`, and off everywhere else; `true` forces it (a staging site), `false` counts a local page. `traqio.isDebug` tells which mode is on. Debug traffic shows in the console's **Live events › Debug** view, but it is never counted in a report, attributed, sent to an ad network or a webhook, or billed.
|
|
115
118
|
|
|
116
119
|
## Requirements
|
|
117
120
|
|
package/build/index.cjs
CHANGED
|
@@ -269,7 +269,8 @@ var require_adservices = __commonJS({
|
|
|
269
269
|
sdkKey: opts.sdkKey,
|
|
270
270
|
token: token.trim(),
|
|
271
271
|
deviceId: opts.deviceId,
|
|
272
|
-
appUserId: opts.userId
|
|
272
|
+
appUserId: opts.userId,
|
|
273
|
+
...opts.debug ? { debug: true } : {}
|
|
273
274
|
})
|
|
274
275
|
});
|
|
275
276
|
if (!res.ok)
|
|
@@ -369,10 +370,12 @@ var require_build = __commonJS({
|
|
|
369
370
|
exports.Traqio = exports.Client = exports.isTrackingUrl = exports.isOpenUrl = exports.reportAdServicesToken = exports.Skan = exports.SDK_VERSION = void 0;
|
|
370
371
|
exports.normalizeAdvertisingId = normalizeAdvertisingId;
|
|
371
372
|
exports.fromMaxAd = fromMaxAd;
|
|
373
|
+
exports.detectDebug = detectDebug;
|
|
374
|
+
exports.isLocalPage = isLocalPage;
|
|
372
375
|
var skan_1 = require_skan();
|
|
373
376
|
var adservices_1 = require_adservices();
|
|
374
377
|
var deeplink_1 = require_deeplink();
|
|
375
|
-
exports.SDK_VERSION = "0.
|
|
378
|
+
exports.SDK_VERSION = "0.3.0";
|
|
376
379
|
var skan_2 = require_skan();
|
|
377
380
|
Object.defineProperty(exports, "Skan", { enumerable: true, get: function() {
|
|
378
381
|
return skan_2.Skan;
|
|
@@ -389,6 +392,7 @@ var require_build = __commonJS({
|
|
|
389
392
|
return deeplink_2.isTrackingUrl;
|
|
390
393
|
} });
|
|
391
394
|
var INSTALL_SENT_KEY = "traq_install_sent";
|
|
395
|
+
var INSTALL_SENT_DEBUG_KEY = "traq_install_sent_debug";
|
|
392
396
|
var INSTALL_ATTEMPTS_KEY = "traq_install_attempts";
|
|
393
397
|
var REFERRER_KEY = "traq_referrer";
|
|
394
398
|
var QUEUE_KEY = "traq_queue";
|
|
@@ -497,6 +501,11 @@ var require_build = __commonJS({
|
|
|
497
501
|
this.undelivered = [];
|
|
498
502
|
this.deferred = null;
|
|
499
503
|
this.consent = null;
|
|
504
|
+
this.debug = false;
|
|
505
|
+
}
|
|
506
|
+
/** Whether this run is in debug mode — see `InitOptions.debug`. Settled by `init()`. */
|
|
507
|
+
get isDebug() {
|
|
508
|
+
return this.debug;
|
|
500
509
|
}
|
|
501
510
|
async init(opts) {
|
|
502
511
|
var _a;
|
|
@@ -507,6 +516,7 @@ var require_build = __commonJS({
|
|
|
507
516
|
if (!this.opts.storage) {
|
|
508
517
|
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.");
|
|
509
518
|
}
|
|
519
|
+
this.debug = await detectDebug(opts);
|
|
510
520
|
await this.restoreConsent(opts.consent);
|
|
511
521
|
await this.restoreQueue();
|
|
512
522
|
await this.restoreAdQueue();
|
|
@@ -514,7 +524,7 @@ var require_build = __commonJS({
|
|
|
514
524
|
if (await this.restoreErased())
|
|
515
525
|
return;
|
|
516
526
|
if (!this.isWeb) {
|
|
517
|
-
const freshInstall = Boolean(this.opts.storage) && !await this.opts.storage.getItem(
|
|
527
|
+
const freshInstall = Boolean(this.opts.storage) && !await this.opts.storage.getItem(this.installSentKey).catch(() => "1");
|
|
518
528
|
await this.sendInstallOnce();
|
|
519
529
|
if (this.opts.deepLinking !== false) {
|
|
520
530
|
this.deferred = this.resolveDeferredOnce(freshInstall).then((link) => link != null ? link : this.retryDeferredWithConsent());
|
|
@@ -777,7 +787,8 @@ var require_build = __commonJS({
|
|
|
777
787
|
deviceId: this.context.deviceId,
|
|
778
788
|
userId: this.opts.userId,
|
|
779
789
|
storage: this.opts.storage,
|
|
780
|
-
native: { getAttributionToken: () => native.getAttributionToken() }
|
|
790
|
+
native: { getAttributionToken: () => native.getAttributionToken() },
|
|
791
|
+
debug: this.debug
|
|
781
792
|
});
|
|
782
793
|
}
|
|
783
794
|
async initSkan() {
|
|
@@ -915,6 +926,13 @@ var require_build = __commonJS({
|
|
|
915
926
|
var _a;
|
|
916
927
|
return ((_a = this.opts) == null ? void 0 : _a.platform) === "web";
|
|
917
928
|
}
|
|
929
|
+
get installSentKey() {
|
|
930
|
+
return this.debug ? INSTALL_SENT_DEBUG_KEY : INSTALL_SENT_KEY;
|
|
931
|
+
}
|
|
932
|
+
/** Spread into every body: present only in debug mode, so a release build's payload is unchanged. */
|
|
933
|
+
debugField() {
|
|
934
|
+
return this.debug ? { debug: true } : {};
|
|
935
|
+
}
|
|
918
936
|
wireLifecycle() {
|
|
919
937
|
const events = {
|
|
920
938
|
background: () => this.flush(),
|
|
@@ -1126,7 +1144,7 @@ var require_build = __commonJS({
|
|
|
1126
1144
|
async sendInstallOnce() {
|
|
1127
1145
|
var _a, _b;
|
|
1128
1146
|
const store = this.opts.storage;
|
|
1129
|
-
if (store && await store.getItem(
|
|
1147
|
+
if (store && await store.getItem(this.installSentKey))
|
|
1130
1148
|
return;
|
|
1131
1149
|
const platform = (_b = (_a = this.opts.native) == null ? void 0 : _a.platform) != null ? _b : "android";
|
|
1132
1150
|
const referrer = await this.readReferrer();
|
|
@@ -1147,7 +1165,7 @@ var require_build = __commonJS({
|
|
|
1147
1165
|
}
|
|
1148
1166
|
});
|
|
1149
1167
|
if (ok)
|
|
1150
|
-
await (store == null ? void 0 : store.setItem(
|
|
1168
|
+
await (store == null ? void 0 : store.setItem(this.installSentKey, "1"));
|
|
1151
1169
|
}
|
|
1152
1170
|
scheduleFlush(delay = FLUSH_DELAY_MS) {
|
|
1153
1171
|
if (this.flushTimer)
|
|
@@ -1222,7 +1240,7 @@ var require_build = __commonJS({
|
|
|
1222
1240
|
const res = await fetch(`${this.opts.endpoint}${path}`, {
|
|
1223
1241
|
method: "POST",
|
|
1224
1242
|
headers: { "Content-Type": "application/json" },
|
|
1225
|
-
body: JSON.stringify({ sdkKey: this.opts.sdkKey, ...body }),
|
|
1243
|
+
body: JSON.stringify({ sdkKey: this.opts.sdkKey, ...body, ...this.debugField() }),
|
|
1226
1244
|
...this.keepalive()
|
|
1227
1245
|
});
|
|
1228
1246
|
return res.ok ? await res.json() : null;
|
|
@@ -1267,7 +1285,7 @@ var require_build = __commonJS({
|
|
|
1267
1285
|
const res = await fetch(`${this.opts.endpoint}${path}`, {
|
|
1268
1286
|
method: "POST",
|
|
1269
1287
|
headers: { "Content-Type": "application/json" },
|
|
1270
|
-
body: JSON.stringify({ sdkKey: this.opts.sdkKey, ...body, ...consent }),
|
|
1288
|
+
body: JSON.stringify({ sdkKey: this.opts.sdkKey, ...body, ...consent, ...this.debugField() }),
|
|
1271
1289
|
...this.keepalive()
|
|
1272
1290
|
});
|
|
1273
1291
|
if (res.ok)
|
|
@@ -1279,6 +1297,28 @@ var require_build = __commonJS({
|
|
|
1279
1297
|
}
|
|
1280
1298
|
};
|
|
1281
1299
|
exports.Client = Client2;
|
|
1300
|
+
async function detectDebug(opts) {
|
|
1301
|
+
var _a, _b;
|
|
1302
|
+
if (opts.debug !== void 0)
|
|
1303
|
+
return opts.debug;
|
|
1304
|
+
if (opts.platform === "web")
|
|
1305
|
+
return isLocalPage();
|
|
1306
|
+
if (globalThis.__DEV__ === true)
|
|
1307
|
+
return true;
|
|
1308
|
+
try {
|
|
1309
|
+
return await ((_b = (_a = opts.native) == null ? void 0 : _a.isDebugBuild) == null ? void 0 : _b.call(_a)) === true;
|
|
1310
|
+
} catch {
|
|
1311
|
+
return false;
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
function isLocalPage(loc = globalThis.location) {
|
|
1315
|
+
if (!loc)
|
|
1316
|
+
return false;
|
|
1317
|
+
if (loc.protocol === "file:")
|
|
1318
|
+
return true;
|
|
1319
|
+
const host = loc.hostname.toLowerCase().replace(/^\[|\]$/g, "");
|
|
1320
|
+
return host === "localhost" || host.endsWith(".localhost") || host.endsWith(".local") || host === "::1" || host === "0.0.0.0" || /^127\.\d+\.\d+\.\d+$/.test(host);
|
|
1321
|
+
}
|
|
1282
1322
|
exports.Traqio = new Client2();
|
|
1283
1323
|
}
|
|
1284
1324
|
});
|
|
@@ -1570,12 +1610,17 @@ var TraqioWeb = class {
|
|
|
1570
1610
|
platform: "web",
|
|
1571
1611
|
userId: opts.userId,
|
|
1572
1612
|
consent,
|
|
1613
|
+
debug: opts.debug,
|
|
1573
1614
|
lifecycle: ({ background, foreground }) => {
|
|
1574
1615
|
document.addEventListener("visibilitychange", () => document.visibilityState === "hidden" ? background() : foreground());
|
|
1575
1616
|
window.addEventListener("pagehide", background);
|
|
1576
1617
|
}
|
|
1577
1618
|
});
|
|
1578
1619
|
}
|
|
1620
|
+
/** Whether this page runs in debug mode — see `WebInitOptions.debug`. Settled by `init()`. */
|
|
1621
|
+
get isDebug() {
|
|
1622
|
+
return this.core.isDebug;
|
|
1623
|
+
}
|
|
1579
1624
|
/** Record an event — `signup`, `purchase`, `add_to_cart`… Batched, retried, kept across page loads. */
|
|
1580
1625
|
track(name, props) {
|
|
1581
1626
|
this.core.track(name, props);
|