@datalyr/web 1.6.5 → 1.7.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 +18 -3
- package/dist/config.d.ts +40 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.test.d.ts +2 -0
- package/dist/config.test.d.ts.map +1 -0
- package/dist/container.d.ts +10 -0
- package/dist/container.d.ts.map +1 -1
- package/dist/datalyr.cjs.js +76 -6
- package/dist/datalyr.cjs.js.map +1 -1
- package/dist/datalyr.esm.js +76 -6
- package/dist/datalyr.esm.js.map +1 -1
- package/dist/datalyr.esm.min.js +1 -1
- package/dist/datalyr.esm.min.js.map +1 -1
- package/dist/datalyr.js +76 -6
- package/dist/datalyr.js.map +1 -1
- package/dist/datalyr.min.js +1 -1
- package/dist/datalyr.min.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/datalyr.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @datalyr/web v1.
|
|
2
|
+
* @datalyr/web v1.7.0
|
|
3
3
|
* Datalyr Web SDK - Modern attribution tracking for web applications
|
|
4
4
|
* (c) 2026 Datalyr Inc.
|
|
5
5
|
* Released under the MIT License
|
|
@@ -2403,9 +2403,10 @@ var Datalyr = (function (exports) {
|
|
|
2403
2403
|
throw new Error(`Failed to fetch container scripts: ${response.status}`);
|
|
2404
2404
|
}
|
|
2405
2405
|
const data = yield response.json();
|
|
2406
|
-
// Store scripts and
|
|
2406
|
+
// Store scripts, pixels, and the SDK runtime config envelope.
|
|
2407
2407
|
this.scripts = data.scripts || [];
|
|
2408
2408
|
this.pixels = data.pixels || null;
|
|
2409
|
+
this.remoteConfig = (data.config && typeof data.config === 'object') ? data.config : undefined;
|
|
2409
2410
|
// Initialize pixels if configured. Awaited so advanced-matching hashes
|
|
2410
2411
|
// are resolved before the first dl.track() flushes through trackToPixels
|
|
2411
2412
|
// (otherwise fbq('init') would lag fbq('track') in fast-path tracks).
|
|
@@ -2435,6 +2436,13 @@ var Datalyr = (function (exports) {
|
|
|
2435
2436
|
}
|
|
2436
2437
|
});
|
|
2437
2438
|
}
|
|
2439
|
+
/**
|
|
2440
|
+
* The SDK runtime config delivered by /container-scripts, or undefined if the
|
|
2441
|
+
* response omitted it. The SDK merges this under explicit init() options.
|
|
2442
|
+
*/
|
|
2443
|
+
getRemoteConfig() {
|
|
2444
|
+
return this.remoteConfig;
|
|
2445
|
+
}
|
|
2438
2446
|
/**
|
|
2439
2447
|
* Load scripts by trigger type
|
|
2440
2448
|
*/
|
|
@@ -3092,7 +3100,7 @@ var Datalyr = (function (exports) {
|
|
|
3092
3100
|
this.config = {
|
|
3093
3101
|
enabled: config.enabled !== false,
|
|
3094
3102
|
captureFromForms: config.captureFromForms !== false,
|
|
3095
|
-
captureFromAPI: config.captureFromAPI
|
|
3103
|
+
captureFromAPI: config.captureFromAPI === true, // default OFF: same-origin response-scan can mis-identify (e.g. admin views)
|
|
3096
3104
|
captureFromShopify: config.captureFromShopify !== false,
|
|
3097
3105
|
trustedDomains: config.trustedDomains || [],
|
|
3098
3106
|
debug: config.debug || false
|
|
@@ -3501,12 +3509,57 @@ var Datalyr = (function (exports) {
|
|
|
3501
3509
|
}
|
|
3502
3510
|
}
|
|
3503
3511
|
|
|
3512
|
+
/** Keys the remote config is allowed to fill on DatalyrConfig. */
|
|
3513
|
+
const REMOTE_KEYS = [
|
|
3514
|
+
'autoIdentify',
|
|
3515
|
+
'autoIdentifyForms',
|
|
3516
|
+
'autoIdentifyAPI',
|
|
3517
|
+
'autoIdentifyShopify',
|
|
3518
|
+
'shopifyCartAttributes',
|
|
3519
|
+
'checkoutChampDomains',
|
|
3520
|
+
'respectGlobalPrivacyControl',
|
|
3521
|
+
'respectDoNotTrack',
|
|
3522
|
+
'privacyMode',
|
|
3523
|
+
];
|
|
3524
|
+
/**
|
|
3525
|
+
* Fold `remote` into `config` IN PLACE. Precedence per key:
|
|
3526
|
+
* explicit init() value > remote (dashboard) > built-in default
|
|
3527
|
+
*
|
|
3528
|
+
* `explicitKeys` = the keys the CALLER passed to init() (before built-in
|
|
3529
|
+
* defaults were merged in). For any remote key NOT in that set, remote
|
|
3530
|
+
* OVERRIDES the built-in default. This is essential because some keys
|
|
3531
|
+
* (respectDoNotTrack, respectGlobalPrivacyControl, privacyMode) get a built-in
|
|
3532
|
+
* default at init() and are therefore never `undefined` — a naive
|
|
3533
|
+
* "fill-if-undefined" would silently ignore the dashboard for them.
|
|
3534
|
+
*
|
|
3535
|
+
* No-op when there's no remote config (older worker / container disabled /
|
|
3536
|
+
* failed fetch) — built-in defaults then stand.
|
|
3537
|
+
*/
|
|
3538
|
+
function applyRemoteConfig(config, remote, explicitKeys) {
|
|
3539
|
+
if (!remote)
|
|
3540
|
+
return;
|
|
3541
|
+
const target = config;
|
|
3542
|
+
for (const key of REMOTE_KEYS) {
|
|
3543
|
+
const remoteVal = remote[key];
|
|
3544
|
+
if (remoteVal === undefined || remoteVal === null)
|
|
3545
|
+
continue;
|
|
3546
|
+
// Explicit init() always wins; otherwise remote overrides the built-in default.
|
|
3547
|
+
if (explicitKeys === null || explicitKeys === void 0 ? void 0 : explicitKeys.has(key))
|
|
3548
|
+
continue;
|
|
3549
|
+
target[key] = remoteVal;
|
|
3550
|
+
}
|
|
3551
|
+
}
|
|
3552
|
+
|
|
3504
3553
|
/**
|
|
3505
3554
|
* Datalyr Web SDK
|
|
3506
3555
|
* Modern attribution tracking for web applications
|
|
3507
3556
|
*/
|
|
3508
3557
|
class Datalyr {
|
|
3509
3558
|
constructor() {
|
|
3559
|
+
// Keys the caller passed to init() (before built-in defaults were merged).
|
|
3560
|
+
// Lets the remote-config merge override built-in defaults while always
|
|
3561
|
+
// deferring to an explicit init() value. See applyRemoteConfig.
|
|
3562
|
+
this.explicitConfigKeys = new Set();
|
|
3510
3563
|
this.superProperties = {};
|
|
3511
3564
|
this.userProperties = {};
|
|
3512
3565
|
this.optedOut = false;
|
|
@@ -3529,6 +3582,10 @@ var Datalyr = (function (exports) {
|
|
|
3529
3582
|
if (!config.workspaceId) {
|
|
3530
3583
|
throw new Error('[Datalyr] workspaceId is required');
|
|
3531
3584
|
}
|
|
3585
|
+
// Snapshot the keys the caller explicitly set, BEFORE built-in defaults are
|
|
3586
|
+
// merged in — so the remote-config merge can override built-in defaults
|
|
3587
|
+
// while still deferring to anything the caller passed explicitly.
|
|
3588
|
+
this.explicitConfigKeys = new Set(Object.keys(config));
|
|
3532
3589
|
// Set default config values
|
|
3533
3590
|
this.config = Object.assign({ endpoint: 'https://ingest.datalyr.com', debug: false, batchSize: 10, flushInterval: 5000, flushAt: 10, criticalEvents: undefined, highPriorityEvents: undefined, sessionTimeout: 60 * 60 * 1000, trackSessions: true, attributionWindow: 90 * 24 * 60 * 60 * 1000, trackedParams: [], respectDoNotTrack: false, respectGlobalPrivacyControl: true, privacyMode: 'standard', cookieDomain: 'auto', cookieExpires: 365, secureCookie: 'auto', sameSite: 'Lax', cookiePrefix: '__dl_', enablePerformanceTracking: true, enableFingerprinting: true, maxRetries: 5, retryDelay: 1000, maxOfflineQueueSize: 100, trackSPA: true, trackPageViews: true, fallbackEndpoints: [], plugins: [] }, config);
|
|
3534
3591
|
// platform:'shopify' implies cart-attribute sync: stamp visitor_id + Meta
|
|
@@ -3605,6 +3662,7 @@ var Datalyr = (function (exports) {
|
|
|
3605
3662
|
return this.initializationPromise;
|
|
3606
3663
|
}
|
|
3607
3664
|
this.initializationPromise = (() => __awaiter(this, void 0, void 0, function* () {
|
|
3665
|
+
var _a;
|
|
3608
3666
|
try {
|
|
3609
3667
|
// SEC-03 Fix: Initialize encryption for PII data
|
|
3610
3668
|
const deviceId = this.identity.getAnonymousId();
|
|
@@ -3650,6 +3708,16 @@ var Datalyr = (function (exports) {
|
|
|
3650
3708
|
this.fireCheckoutChampPurchasePixel();
|
|
3651
3709
|
}
|
|
3652
3710
|
}
|
|
3711
|
+
// Fold the remote /container-scripts config UNDER explicit init()
|
|
3712
|
+
// overrides (precedence: defaults <- remote <- explicit). No-op if the
|
|
3713
|
+
// container is disabled or the worker didn't send `config`. This is what
|
|
3714
|
+
// makes the dashboard toggles take effect with no snippet edits.
|
|
3715
|
+
applyRemoteConfig(this.config, (_a = this.container) === null || _a === void 0 ? void 0 : _a.getRemoteConfig(), this.explicitConfigKeys);
|
|
3716
|
+
// Privacy-strict turns auto-identify (email capture) OFF regardless of
|
|
3717
|
+
// the dashboard/remote value — privacy wins over the bridge.
|
|
3718
|
+
if (this.config.privacyMode === 'strict') {
|
|
3719
|
+
this.config.autoIdentify = false;
|
|
3720
|
+
}
|
|
3653
3721
|
// autoIdentify default for the CC bridge:
|
|
3654
3722
|
// - platform === 'checkoutchamp' (CC funnel pages) OR
|
|
3655
3723
|
// - checkoutChampDomains set (Shopify storefronts feeding a CC funnel)
|
|
@@ -3660,8 +3728,10 @@ var Datalyr = (function (exports) {
|
|
|
3660
3728
|
if (ccBridgeActive && this.config.autoIdentify === undefined) {
|
|
3661
3729
|
this.config.autoIdentify = true;
|
|
3662
3730
|
}
|
|
3663
|
-
// Initialize auto-identify
|
|
3664
|
-
|
|
3731
|
+
// Initialize auto-identify when enabled (explicit or remote) AND
|
|
3732
|
+
// tracking is allowed. The shouldTrack() gate keeps capture from even
|
|
3733
|
+
// setting up its form/API interceptors for opted-out / DNT / GPC users.
|
|
3734
|
+
if (this.config.autoIdentify === true && this.shouldTrack()) {
|
|
3665
3735
|
this.autoIdentify = new AutoIdentifyManager({
|
|
3666
3736
|
enabled: true,
|
|
3667
3737
|
captureFromForms: this.config.autoIdentifyForms,
|
|
@@ -3687,7 +3757,7 @@ var Datalyr = (function (exports) {
|
|
|
3687
3757
|
// Lets server-side order webhooks recover the browser visitor + Meta click
|
|
3688
3758
|
// signals (the postback webhook reads these as note_attributes). Inert unless
|
|
3689
3759
|
// enabled; best-effort and never blocks init.
|
|
3690
|
-
if (this.config.shopifyCartAttributes === true) {
|
|
3760
|
+
if (this.config.shopifyCartAttributes === true && this.shouldTrack()) {
|
|
3691
3761
|
this.syncShopifyCartAttributes().catch((error) => {
|
|
3692
3762
|
this.log('Shopify cart attribute sync failed:', error);
|
|
3693
3763
|
});
|