@datalyr/web 1.7.3 → 1.7.4
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/dist/datalyr.cjs.js +169 -3
- package/dist/datalyr.cjs.js.map +1 -1
- package/dist/datalyr.esm.js +169 -3
- 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 +169 -3
- 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 +27 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/stripe-links.test.d.ts +2 -0
- package/dist/stripe-links.test.d.ts.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/datalyr.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @datalyr/web v1.7.
|
|
2
|
+
* @datalyr/web v1.7.4
|
|
3
3
|
* Datalyr Web SDK - Modern attribution tracking for web applications
|
|
4
4
|
* (c) 2026 Datalyr Inc.
|
|
5
5
|
* Released under the MIT License
|
|
@@ -4336,7 +4336,7 @@ class Datalyr {
|
|
|
4336
4336
|
return this.initializationPromise;
|
|
4337
4337
|
}
|
|
4338
4338
|
this.initializationPromise = (() => __awaiter(this, void 0, void 0, function* () {
|
|
4339
|
-
var _a;
|
|
4339
|
+
var _a, _b;
|
|
4340
4340
|
try {
|
|
4341
4341
|
// SEC-03: encryption is for PII-AT-REST only — it must NOT gate event delivery,
|
|
4342
4342
|
// pageviews, or pixels. On a non-secure context (http://) or an old browser,
|
|
@@ -4459,6 +4459,15 @@ class Datalyr {
|
|
|
4459
4459
|
// opted-out / DNT / GPC visitor's id + click-ids aren't stamped on outbound links.
|
|
4460
4460
|
this.syncOutboundLinkParams(this.config.checkoutChampDomains);
|
|
4461
4461
|
}
|
|
4462
|
+
// Stripe Payment Link auto-decoration (D1, DEFAULT ON): stamp
|
|
4463
|
+
// client_reference_id=<visitor_id> (+ prefilled_email when identified) onto
|
|
4464
|
+
// buy.stripe.com / custom payment-link domain anchors and Stripe embeds, so a
|
|
4465
|
+
// snippet-only merchant's checkout.session.completed webhooks attribute
|
|
4466
|
+
// deterministically with zero server work. Gated on shouldTrack() so
|
|
4467
|
+
// opted-out / DNT / GPC visitors never get an id stamped into outbound links.
|
|
4468
|
+
if (this.config.stripePaymentLinks !== false && this.shouldTrack()) {
|
|
4469
|
+
this.syncStripePaymentLinks((_b = this.config.stripeLinkDomains) !== null && _b !== void 0 ? _b : []);
|
|
4470
|
+
}
|
|
4462
4471
|
// Track initial page view if enabled (AFTER encryption ready)
|
|
4463
4472
|
if (this.config.trackPageViews) {
|
|
4464
4473
|
this.page();
|
|
@@ -5379,6 +5388,159 @@ class Datalyr {
|
|
|
5379
5388
|
}
|
|
5380
5389
|
this.log("Checkout Champ outbound-link sync active for:", lowerDomains);
|
|
5381
5390
|
}
|
|
5391
|
+
/**
|
|
5392
|
+
* Stripe Payment Link auto-decoration (D1). Structurally mirrors
|
|
5393
|
+
* syncOutboundLinkParams: stampAll on init, debounced MutationObserver for
|
|
5394
|
+
* SPA-rendered anchors, capture-phase click re-stamp + queue flush, disposer
|
|
5395
|
+
* wired into destroy()/pagehide.
|
|
5396
|
+
*
|
|
5397
|
+
* Match: exact-host equality against buy.stripe.com + config.stripeLinkDomains
|
|
5398
|
+
* via the URL API — NEVER substring (a[href*=...] would match
|
|
5399
|
+
* evil.com/buy.stripe.com paths) and NEVER checkout.stripe.com (Checkout
|
|
5400
|
+
* Session URLs ignore these params — the session is already created).
|
|
5401
|
+
*
|
|
5402
|
+
* Stamp (URL API preserves existing query + hash):
|
|
5403
|
+
* - client_reference_id=<visitorId> only if the param is absent (merchant-set
|
|
5404
|
+
* wins) and the id passes the Stripe format guard (Stripe silently DROPS
|
|
5405
|
+
* invalid values — don't write garbage into merchant links).
|
|
5406
|
+
* - prefilled_email=<email> only if identified email exists, the param is
|
|
5407
|
+
* absent, locked_prefilled_email is absent, and privacyMode !== 'strict'.
|
|
5408
|
+
* - <stripe-pricing-table>/<stripe-buy-button>: client-reference-id attribute
|
|
5409
|
+
* if absent.
|
|
5410
|
+
*
|
|
5411
|
+
* The decorated link's checkout.session.completed arrives with
|
|
5412
|
+
* client_reference_id, which stripe-connect.js already reads — zero server
|
|
5413
|
+
* changes. window.open(paymentLink) is not covered (use getVisitorId()
|
|
5414
|
+
* manually); iframe/shadow-DOM links are unreachable from document.
|
|
5415
|
+
*/
|
|
5416
|
+
syncStripePaymentLinks(extraDomains) {
|
|
5417
|
+
if (typeof window === "undefined" || typeof document === "undefined")
|
|
5418
|
+
return;
|
|
5419
|
+
const hosts = new Set(["buy.stripe.com"]);
|
|
5420
|
+
for (const d of extraDomains) {
|
|
5421
|
+
const h = String(d).trim().toLowerCase();
|
|
5422
|
+
if (h)
|
|
5423
|
+
hosts.add(h);
|
|
5424
|
+
}
|
|
5425
|
+
const matchesPaymentLinkHost = (href) => {
|
|
5426
|
+
try {
|
|
5427
|
+
const host = new URL(href, window.location.href).hostname.toLowerCase();
|
|
5428
|
+
return hosts.has(host); // exact-host equality only
|
|
5429
|
+
}
|
|
5430
|
+
catch (_a) {
|
|
5431
|
+
return false;
|
|
5432
|
+
}
|
|
5433
|
+
};
|
|
5434
|
+
// Stripe accepts alphanumeric + `-` + `_`, max 200 chars, and silently drops
|
|
5435
|
+
// invalid values. Legacy/foreign persisted cookie ids are unconstrained —
|
|
5436
|
+
// skip silently rather than stamp a value Stripe would discard.
|
|
5437
|
+
const CLIENT_REFERENCE_ID_RE = /^[A-Za-z0-9_-]{1,200}$/;
|
|
5438
|
+
const getClientReferenceId = () => {
|
|
5439
|
+
const vid = this.identity.getAnonymousId();
|
|
5440
|
+
return vid && CLIENT_REFERENCE_ID_RE.test(vid) ? vid : null;
|
|
5441
|
+
};
|
|
5442
|
+
const getPrefilledEmail = () => {
|
|
5443
|
+
var _a;
|
|
5444
|
+
if (this.config.privacyMode === "strict")
|
|
5445
|
+
return null;
|
|
5446
|
+
const email = (_a = this.userProperties) === null || _a === void 0 ? void 0 : _a.email;
|
|
5447
|
+
return typeof email === "string" && email ? email : null;
|
|
5448
|
+
};
|
|
5449
|
+
const stampLink = (anchor) => {
|
|
5450
|
+
if (!anchor.href || !matchesPaymentLinkHost(anchor.href))
|
|
5451
|
+
return;
|
|
5452
|
+
try {
|
|
5453
|
+
const u = new URL(anchor.href, window.location.href);
|
|
5454
|
+
let mutated = false;
|
|
5455
|
+
const vid = getClientReferenceId();
|
|
5456
|
+
if (vid && !u.searchParams.get("client_reference_id")) {
|
|
5457
|
+
u.searchParams.set("client_reference_id", vid);
|
|
5458
|
+
mutated = true;
|
|
5459
|
+
}
|
|
5460
|
+
const email = getPrefilledEmail();
|
|
5461
|
+
if (email &&
|
|
5462
|
+
!u.searchParams.get("prefilled_email") &&
|
|
5463
|
+
!u.searchParams.get("locked_prefilled_email")) {
|
|
5464
|
+
// URL API percent-encodes automatically.
|
|
5465
|
+
u.searchParams.set("prefilled_email", email);
|
|
5466
|
+
mutated = true;
|
|
5467
|
+
}
|
|
5468
|
+
if (mutated)
|
|
5469
|
+
anchor.href = u.toString();
|
|
5470
|
+
}
|
|
5471
|
+
catch (_a) {
|
|
5472
|
+
// Ignore malformed URLs — don't break the page.
|
|
5473
|
+
}
|
|
5474
|
+
};
|
|
5475
|
+
const stampEmbeds = () => {
|
|
5476
|
+
const vid = getClientReferenceId();
|
|
5477
|
+
if (!vid)
|
|
5478
|
+
return;
|
|
5479
|
+
document.querySelectorAll("stripe-pricing-table, stripe-buy-button").forEach((el) => {
|
|
5480
|
+
if (!el.getAttribute("client-reference-id")) {
|
|
5481
|
+
el.setAttribute("client-reference-id", vid);
|
|
5482
|
+
}
|
|
5483
|
+
});
|
|
5484
|
+
};
|
|
5485
|
+
const stampAll = () => {
|
|
5486
|
+
document.querySelectorAll("a[href]").forEach((el) => stampLink(el));
|
|
5487
|
+
stampEmbeds();
|
|
5488
|
+
};
|
|
5489
|
+
const onClick = (e) => {
|
|
5490
|
+
var _a, _b;
|
|
5491
|
+
const target = (_a = e.target) === null || _a === void 0 ? void 0 : _a.closest("a[href]");
|
|
5492
|
+
if (!target)
|
|
5493
|
+
return;
|
|
5494
|
+
const anchor = target;
|
|
5495
|
+
if (!matchesPaymentLinkHost(anchor.href))
|
|
5496
|
+
return;
|
|
5497
|
+
stampLink(anchor); // re-stamp in case identify() happened since DOMReady
|
|
5498
|
+
try {
|
|
5499
|
+
(_b = this.queue) === null || _b === void 0 ? void 0 : _b.flush();
|
|
5500
|
+
}
|
|
5501
|
+
catch (_c) {
|
|
5502
|
+
// Best-effort — never block navigation.
|
|
5503
|
+
}
|
|
5504
|
+
};
|
|
5505
|
+
stampAll();
|
|
5506
|
+
document.addEventListener("click", onClick, true);
|
|
5507
|
+
try {
|
|
5508
|
+
// Debounce re-stamping (same rationale as the CC sync): a busy SPA can fire
|
|
5509
|
+
// thousands of mutations per second; 150ms is small enough to catch links
|
|
5510
|
+
// before the user can click them, large enough to coalesce bursts. The
|
|
5511
|
+
// click-time re-stamp is the final safety net — no pushState hook needed.
|
|
5512
|
+
let restampTimer = null;
|
|
5513
|
+
const scheduleRestamp = () => {
|
|
5514
|
+
if (restampTimer != null)
|
|
5515
|
+
return;
|
|
5516
|
+
restampTimer = setTimeout(() => {
|
|
5517
|
+
restampTimer = null;
|
|
5518
|
+
stampAll();
|
|
5519
|
+
}, 150);
|
|
5520
|
+
};
|
|
5521
|
+
const observer = new MutationObserver(scheduleRestamp);
|
|
5522
|
+
observer.observe(document.documentElement, { childList: true, subtree: true });
|
|
5523
|
+
// Observer + click listener live for the session; pagehide cleans up on
|
|
5524
|
+
// full-page unload, and destroy() tears them down early via this disposer
|
|
5525
|
+
// (otherwise destroy()+re-init() leaks the observer + capturing listener).
|
|
5526
|
+
this.stripeLinksDisposer = () => {
|
|
5527
|
+
try {
|
|
5528
|
+
observer.disconnect();
|
|
5529
|
+
}
|
|
5530
|
+
catch ( /* idempotent */_a) { /* idempotent */ }
|
|
5531
|
+
if (restampTimer != null) {
|
|
5532
|
+
clearTimeout(restampTimer);
|
|
5533
|
+
restampTimer = null;
|
|
5534
|
+
}
|
|
5535
|
+
document.removeEventListener("click", onClick, true);
|
|
5536
|
+
};
|
|
5537
|
+
window.addEventListener("pagehide", () => { var _a; return (_a = this.stripeLinksDisposer) === null || _a === void 0 ? void 0 : _a.call(this); }, { once: true });
|
|
5538
|
+
}
|
|
5539
|
+
catch (error) {
|
|
5540
|
+
this.log("MutationObserver setup failed (Stripe Payment Link sync):", error);
|
|
5541
|
+
}
|
|
5542
|
+
this.log("Stripe Payment Link auto-decoration active for:", Array.from(hosts));
|
|
5543
|
+
}
|
|
5382
5544
|
/**
|
|
5383
5545
|
* Create event payload
|
|
5384
5546
|
*/
|
|
@@ -5461,7 +5623,7 @@ class Datalyr {
|
|
|
5461
5623
|
// SDK metadata. MUST stay in sync with package.json "version" — the build guard
|
|
5462
5624
|
// (scripts/check-bundle.js, run by build:check) fails the build if the bundle's
|
|
5463
5625
|
// sdk_version doesn't match package.json. (FSR-103)
|
|
5464
|
-
sdk_version: '1.7.
|
|
5626
|
+
sdk_version: '1.7.4',
|
|
5465
5627
|
sdk_name: 'datalyr-web-sdk'
|
|
5466
5628
|
};
|
|
5467
5629
|
return payload;
|
|
@@ -5682,6 +5844,10 @@ class Datalyr {
|
|
|
5682
5844
|
this.outboundDisposer();
|
|
5683
5845
|
this.outboundDisposer = undefined;
|
|
5684
5846
|
}
|
|
5847
|
+
if (this.stripeLinksDisposer) {
|
|
5848
|
+
this.stripeLinksDisposer();
|
|
5849
|
+
this.stripeLinksDisposer = undefined;
|
|
5850
|
+
}
|
|
5685
5851
|
// Clean up queue
|
|
5686
5852
|
if (this.queue) {
|
|
5687
5853
|
this.queue.destroy();
|