@datalyr/web 1.6.3 → 1.6.5
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/attribution.d.ts.map +1 -1
- package/dist/datalyr.cjs.js +363 -4
- package/dist/datalyr.cjs.js.map +1 -1
- package/dist/datalyr.esm.js +363 -4
- 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 +363 -4
- 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 +55 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.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.6.
|
|
2
|
+
* @datalyr/web v1.6.5
|
|
3
3
|
* Datalyr Web SDK - Modern attribution tracking for web applications
|
|
4
4
|
* (c) 2026 Datalyr Inc.
|
|
5
5
|
* Released under the MIT License
|
|
@@ -1527,6 +1527,7 @@ var Datalyr = (function (exports) {
|
|
|
1527
1527
|
* Capture advertising platform cookies
|
|
1528
1528
|
*/
|
|
1529
1529
|
captureAdCookies() {
|
|
1530
|
+
var _a, _b;
|
|
1530
1531
|
const adCookies = {};
|
|
1531
1532
|
// Facebook/Meta cookies
|
|
1532
1533
|
adCookies._fbp = cookies.get('_fbp');
|
|
@@ -1551,13 +1552,29 @@ var Datalyr = (function (exports) {
|
|
|
1551
1552
|
// Optionally set the cookie for future use
|
|
1552
1553
|
cookies.set('_fbp', adCookies._fbp, 90);
|
|
1553
1554
|
}
|
|
1555
|
+
// Persist the click time the FIRST time we see fbclid/gclid in URL so we can
|
|
1556
|
+
// rebuild fbc (and stamp real click time on server-side events) later even
|
|
1557
|
+
// when _fbc/_gclid cookies get evicted. Once-only: never overwrite.
|
|
1558
|
+
const fbclid = this.getCurrentFbclid();
|
|
1559
|
+
if (fbclid && !cookies.get('_dl_fbclid_at')) {
|
|
1560
|
+
cookies.set('_dl_fbclid_at', String(Date.now()), 90);
|
|
1561
|
+
}
|
|
1562
|
+
const gclid = this.hasClickId('gclid') ? ((_b = (_a = this.queryParamsCache) === null || _a === void 0 ? void 0 : _a.gclid) !== null && _b !== void 0 ? _b : null) : null;
|
|
1563
|
+
if (gclid && !cookies.get('_dl_gclid_at')) {
|
|
1564
|
+
cookies.set('_dl_gclid_at', String(Date.now()), 90);
|
|
1565
|
+
}
|
|
1554
1566
|
// Generate _fbc if we have fbclid but no _fbc.
|
|
1555
1567
|
// Meta's fbc format is `fb.{subdomainIndex}.{creationTime}.{fbclid}` where
|
|
1556
1568
|
// creationTime is UNIX time in MILLISECONDS (matches the _fbp generation above
|
|
1557
1569
|
// and the real _fbc cookie the Meta Pixel writes). Do NOT use seconds here.
|
|
1558
|
-
const fbclid = this.getCurrentFbclid();
|
|
1559
1570
|
if (fbclid && !adCookies._fbc) {
|
|
1560
|
-
|
|
1571
|
+
// Prefer the persisted click time when valid; fall back to now if the
|
|
1572
|
+
// cookie is missing or corrupted (e.g. user edited it to garbage).
|
|
1573
|
+
// Without this guard, Number("abc") = NaN and Meta would reject
|
|
1574
|
+
// `fb.1.NaN.{fbclid}`.
|
|
1575
|
+
const stored = cookies.get('_dl_fbclid_at');
|
|
1576
|
+
const parsed = stored ? Number(stored) : NaN;
|
|
1577
|
+
const timestamp = Number.isFinite(parsed) && parsed > 0 ? parsed : Date.now();
|
|
1561
1578
|
adCookies._fbc = `fb.1.${timestamp}.${fbclid}`;
|
|
1562
1579
|
// Optionally set the cookie for future use
|
|
1563
1580
|
cookies.set('_fbc', adCookies._fbc, 90);
|
|
@@ -3514,6 +3531,14 @@ var Datalyr = (function (exports) {
|
|
|
3514
3531
|
}
|
|
3515
3532
|
// Set default config values
|
|
3516
3533
|
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
|
+
// platform:'shopify' implies cart-attribute sync: stamp visitor_id + Meta
|
|
3535
|
+
// click signals into note_attributes so server-side order webhooks can
|
|
3536
|
+
// attribute guest checkouts. Lets the Shopify theme app-embed enable it via
|
|
3537
|
+
// data-platform="shopify" alone. `=== undefined` so an explicit
|
|
3538
|
+
// shopifyCartAttributes:false still wins.
|
|
3539
|
+
if (this.config.platform === 'shopify' && this.config.shopifyCartAttributes === undefined) {
|
|
3540
|
+
this.config.shopifyCartAttributes = true;
|
|
3541
|
+
}
|
|
3517
3542
|
// Initialize cookie storage with config
|
|
3518
3543
|
this.cookies = new CookieStorage({
|
|
3519
3544
|
domain: this.config.cookieDomain,
|
|
@@ -3525,6 +3550,12 @@ var Datalyr = (function (exports) {
|
|
|
3525
3550
|
storage.migrateFromLegacyPrefix();
|
|
3526
3551
|
// Check opt-out AFTER cookies configured (Issue #14)
|
|
3527
3552
|
this.optedOut = this.cookies.get('__dl_opt_out') === 'true';
|
|
3553
|
+
// CC funnel page entry: restore the _dl_* URL bridge BEFORE IdentityManager
|
|
3554
|
+
// initializes so the storefront's visitor_id is the one used here (instead
|
|
3555
|
+
// of auto-generating a fresh one on this domain).
|
|
3556
|
+
if (this.config.platform === 'checkoutchamp') {
|
|
3557
|
+
this.restoreFromURL();
|
|
3558
|
+
}
|
|
3528
3559
|
// Initialize modules
|
|
3529
3560
|
this.identity = new IdentityManager();
|
|
3530
3561
|
this.session = new SessionManager(this.config.sessionTimeout);
|
|
@@ -3608,6 +3639,26 @@ var Datalyr = (function (exports) {
|
|
|
3608
3639
|
yield this.container.init().catch(error => {
|
|
3609
3640
|
this.log('Container initialization failed:', error);
|
|
3610
3641
|
});
|
|
3642
|
+
// Checkout Champ thank-you/upsell page: co-fire the browser Meta Pixel
|
|
3643
|
+
// Purchase with the SAME deterministic event_id the CC webhook stamps
|
|
3644
|
+
// server-side, so Meta dedupes the browser event against the server-side
|
|
3645
|
+
// CAPI event (dedup = event_name + event_id). Pixel-only — the CC Export
|
|
3646
|
+
// Profile webhook owns the server event + CAPI postback. No-op anywhere
|
|
3647
|
+
// except a post-purchase page (keyed on CC's sessionStorage orderData).
|
|
3648
|
+
// Must run AFTER container.init() so fbq is loaded + init'd.
|
|
3649
|
+
if (this.config.platform === 'checkoutchamp') {
|
|
3650
|
+
this.fireCheckoutChampPurchasePixel();
|
|
3651
|
+
}
|
|
3652
|
+
}
|
|
3653
|
+
// autoIdentify default for the CC bridge:
|
|
3654
|
+
// - platform === 'checkoutchamp' (CC funnel pages) OR
|
|
3655
|
+
// - checkoutChampDomains set (Shopify storefronts feeding a CC funnel)
|
|
3656
|
+
// turn autoIdentify on unless the caller explicitly set it to false.
|
|
3657
|
+
// The 95% claim relies on email capture on BOTH ends of the bridge.
|
|
3658
|
+
const ccBridgeActive = this.config.platform === 'checkoutchamp'
|
|
3659
|
+
|| (Array.isArray(this.config.checkoutChampDomains) && this.config.checkoutChampDomains.length > 0);
|
|
3660
|
+
if (ccBridgeActive && this.config.autoIdentify === undefined) {
|
|
3661
|
+
this.config.autoIdentify = true;
|
|
3611
3662
|
}
|
|
3612
3663
|
// Initialize auto-identify if explicitly enabled (opt-in)
|
|
3613
3664
|
if (this.config.autoIdentify === true) {
|
|
@@ -3641,6 +3692,12 @@ var Datalyr = (function (exports) {
|
|
|
3641
3692
|
this.log('Shopify cart attribute sync failed:', error);
|
|
3642
3693
|
});
|
|
3643
3694
|
}
|
|
3695
|
+
// Storefront → CC bridge: stamp _dl_* params on outbound links to the
|
|
3696
|
+
// configured CC domains so visitor_id + click signals cross the domain
|
|
3697
|
+
// boundary. Inert unless checkoutChampDomains is set.
|
|
3698
|
+
if (Array.isArray(this.config.checkoutChampDomains) && this.config.checkoutChampDomains.length > 0) {
|
|
3699
|
+
this.syncOutboundLinkParams(this.config.checkoutChampDomains);
|
|
3700
|
+
}
|
|
3644
3701
|
// Track initial page view if enabled (AFTER encryption ready)
|
|
3645
3702
|
if (this.config.trackPageViews) {
|
|
3646
3703
|
this.page();
|
|
@@ -4111,6 +4168,7 @@ var Datalyr = (function (exports) {
|
|
|
4111
4168
|
const visitorId = this.identity.getAnonymousId();
|
|
4112
4169
|
const fbc = this.cookies.get("_fbc") || attribution._fbc;
|
|
4113
4170
|
const fbp = this.cookies.get("_fbp") || attribution._fbp;
|
|
4171
|
+
const fbclidAt = this.cookies.get("_dl_fbclid_at");
|
|
4114
4172
|
if (visitorId)
|
|
4115
4173
|
attributes._datalyr_visitor_id = visitorId;
|
|
4116
4174
|
if (fbc)
|
|
@@ -4119,6 +4177,8 @@ var Datalyr = (function (exports) {
|
|
|
4119
4177
|
attributes._datalyr_fbp = String(fbp);
|
|
4120
4178
|
if (fbclid)
|
|
4121
4179
|
attributes._datalyr_fbclid = String(fbclid);
|
|
4180
|
+
if (fbclidAt)
|
|
4181
|
+
attributes._datalyr_fbclid_at = String(fbclidAt);
|
|
4122
4182
|
if (Object.keys(attributes).length === 0)
|
|
4123
4183
|
return;
|
|
4124
4184
|
try {
|
|
@@ -4136,6 +4196,305 @@ var Datalyr = (function (exports) {
|
|
|
4136
4196
|
}
|
|
4137
4197
|
});
|
|
4138
4198
|
}
|
|
4199
|
+
/**
|
|
4200
|
+
* Restore _dl_* URL bridge params on a Checkout Champ funnel page.
|
|
4201
|
+
* Runs BEFORE IdentityManager so the storefront's visitor_id wins over a
|
|
4202
|
+
* freshly auto-generated one. Also restores _fbc / _fbp cookies and the
|
|
4203
|
+
* fbclid click time so server-side rebuilds carry the real click moment.
|
|
4204
|
+
*
|
|
4205
|
+
* Strategy: stamp matching cookies (without clobbering pre-existing values),
|
|
4206
|
+
* then rewrite the URL so `_dl_fbclid` becomes `fbclid` — that way the rest
|
|
4207
|
+
* of the SDK's attribution layer (which reads `params.fbclid`) works
|
|
4208
|
+
* unchanged, and any merchant analytics also see the canonical click ID.
|
|
4209
|
+
*/
|
|
4210
|
+
restoreFromURL() {
|
|
4211
|
+
var _a;
|
|
4212
|
+
if (typeof window === "undefined" || typeof document === "undefined")
|
|
4213
|
+
return;
|
|
4214
|
+
try {
|
|
4215
|
+
const params = new URLSearchParams(window.location.search);
|
|
4216
|
+
const get = (k) => params.get(k);
|
|
4217
|
+
const vid = get("_dl_vid");
|
|
4218
|
+
const fbc = get("_dl_fbc");
|
|
4219
|
+
const fbp = get("_dl_fbp");
|
|
4220
|
+
const fbclid = get("_dl_fbclid");
|
|
4221
|
+
const fbclidAt = get("_dl_fbclid_at");
|
|
4222
|
+
const gclid = get("_dl_gclid");
|
|
4223
|
+
const gclidAt = get("_dl_gclid_at");
|
|
4224
|
+
// visitor_id: bridge wins. The whole point of `_dl_vid` is to unify the
|
|
4225
|
+
// storefront's session with the CC funnel session. A pre-existing local
|
|
4226
|
+
// cookie from a prior direct CC visit would silently sink the integration
|
|
4227
|
+
// (CC events stay on the local id; storefront events use the bridged id;
|
|
4228
|
+
// the two never link). Overwrite — orphaned local events are fine.
|
|
4229
|
+
if (vid)
|
|
4230
|
+
this.cookies.set("__dl_visitor_id", vid, 365);
|
|
4231
|
+
// Meta cookies + click-time cookies: existing wins. _fbc / _fbp may have
|
|
4232
|
+
// been written by Meta Pixel on the CC funnel page itself (more recent
|
|
4233
|
+
// than the bridged value); _dl_fbclid_at should record first-touch click
|
|
4234
|
+
// time per device, not get reset by a bridge from a new campaign.
|
|
4235
|
+
const setIfMissing = (name, value) => {
|
|
4236
|
+
if (!value)
|
|
4237
|
+
return;
|
|
4238
|
+
if (this.cookies.get(name))
|
|
4239
|
+
return;
|
|
4240
|
+
this.cookies.set(name, value, 365);
|
|
4241
|
+
};
|
|
4242
|
+
setIfMissing("_fbc", fbc);
|
|
4243
|
+
setIfMissing("_fbp", fbp);
|
|
4244
|
+
setIfMissing("_dl_fbclid_at", fbclidAt);
|
|
4245
|
+
setIfMissing("_dl_gclid_at", gclidAt);
|
|
4246
|
+
// Rewrite URL: _dl_fbclid → fbclid (etc.) so captureAttribution() picks
|
|
4247
|
+
// them up via its existing `params.fbclid` path. Strip the _dl_* params
|
|
4248
|
+
// either way so they don't leak into downstream analytics URLs.
|
|
4249
|
+
let rewrote = false;
|
|
4250
|
+
const mappings = [
|
|
4251
|
+
["fbclid", fbclid],
|
|
4252
|
+
["gclid", gclid]
|
|
4253
|
+
];
|
|
4254
|
+
for (const [canonical, value] of mappings) {
|
|
4255
|
+
if (value && !params.get(canonical)) {
|
|
4256
|
+
params.set(canonical, value);
|
|
4257
|
+
rewrote = true;
|
|
4258
|
+
}
|
|
4259
|
+
}
|
|
4260
|
+
for (const k of ["_dl_vid", "_dl_fbc", "_dl_fbp", "_dl_fbclid", "_dl_fbclid_at", "_dl_gclid", "_dl_gclid_at"]) {
|
|
4261
|
+
if (params.has(k)) {
|
|
4262
|
+
params.delete(k);
|
|
4263
|
+
rewrote = true;
|
|
4264
|
+
}
|
|
4265
|
+
}
|
|
4266
|
+
if (rewrote && typeof ((_a = window.history) === null || _a === void 0 ? void 0 : _a.replaceState) === "function") {
|
|
4267
|
+
const newSearch = params.toString();
|
|
4268
|
+
const newUrl = window.location.pathname +
|
|
4269
|
+
(newSearch ? "?" + newSearch : "") +
|
|
4270
|
+
window.location.hash;
|
|
4271
|
+
window.history.replaceState(window.history.state, "", newUrl);
|
|
4272
|
+
}
|
|
4273
|
+
this.log("Checkout Champ bridge restored:", {
|
|
4274
|
+
had_vid: !!vid,
|
|
4275
|
+
had_fbc: !!fbc,
|
|
4276
|
+
had_fbp: !!fbp,
|
|
4277
|
+
had_fbclid: !!fbclid,
|
|
4278
|
+
had_gclid: !!gclid
|
|
4279
|
+
});
|
|
4280
|
+
}
|
|
4281
|
+
catch (error) {
|
|
4282
|
+
// Don't let bridge restoration block init — fall through to normal SDK
|
|
4283
|
+
// behavior (a fresh visitor_id, no restored click signals).
|
|
4284
|
+
this.log("restoreFromURL failed:", error);
|
|
4285
|
+
}
|
|
4286
|
+
}
|
|
4287
|
+
/**
|
|
4288
|
+
* Checkout Champ Meta Pixel ⇄ CAPI deduplication.
|
|
4289
|
+
*
|
|
4290
|
+
* On a CC thank-you / upsell page, fire the BROWSER Meta Pixel Purchase with the
|
|
4291
|
+
* exact same event_id the CC webhook stamps server-side, so Meta collapses the
|
|
4292
|
+
* browser Pixel event and the server-side CAPI event into one (dedup key =
|
|
4293
|
+
* event_name + event_id). This gives the EMQ lift of a matched browser+server
|
|
4294
|
+
* event without double-counting conversions in Ads Manager.
|
|
4295
|
+
*
|
|
4296
|
+
* PIXEL-ONLY by design. We do NOT enqueue a server event here: the CC Export
|
|
4297
|
+
* Profile webhook (webhooks/platforms/checkoutchamp.js) already ingests the
|
|
4298
|
+
* purchase and fires CAPI. Calling track() here would create a second server
|
|
4299
|
+
* event (source='web') AND double-fire CAPI — defeating the whole point.
|
|
4300
|
+
*
|
|
4301
|
+
* The event_id MUST stay byte-identical to the server formula:
|
|
4302
|
+
* webhooks/platforms/checkoutchamp.js:250
|
|
4303
|
+
* generateEventId('checkoutchamp', `${event_type}_${order_id}`)
|
|
4304
|
+
* webhooks/core/ingest.js:122 → `${platform}_${webhookEventId}`
|
|
4305
|
+
* ⇒ `checkoutchamp_purchase_<order_id>`
|
|
4306
|
+
* where <order_id> is the value CC posts to the webhook via its [orderId] macro.
|
|
4307
|
+
* We read the browser-side counterpart from CC's own client-side order object:
|
|
4308
|
+
* JSON.parse(sessionStorage.getItem('orderData')).orderId
|
|
4309
|
+
* (CC docs: referenced in custom scripts as `orderDataTmp.orderId`).
|
|
4310
|
+
*
|
|
4311
|
+
* ASSUMPTION TO VERIFY ON A REAL CC TEST ORDER: that sessionStorage
|
|
4312
|
+
* orderData.orderId === the [orderId] CC sends to the postback. If a merchant's
|
|
4313
|
+
* CC plan exposes a different id client-side, the two event_ids won't match and
|
|
4314
|
+
* Meta will show duplicates — caught by the test order in the setup checklist.
|
|
4315
|
+
*
|
|
4316
|
+
* v1 scope: the primary order only. Per-upsell Pixel dedup (each upsell is its
|
|
4317
|
+
* own order_id + parent_order_id server-side) needs the upsell sessionStorage
|
|
4318
|
+
* shape confirmed on a live funnel first — tracked as a follow-up.
|
|
4319
|
+
*/
|
|
4320
|
+
fireCheckoutChampPurchasePixel() {
|
|
4321
|
+
var _a;
|
|
4322
|
+
if (typeof window === "undefined")
|
|
4323
|
+
return;
|
|
4324
|
+
try {
|
|
4325
|
+
// Needs the container (where the Meta Pixel lives). trackToPixels itself
|
|
4326
|
+
// no-ops unless a Meta pixel is enabled + fbq is present, so an
|
|
4327
|
+
// unconfigured workspace silently does nothing.
|
|
4328
|
+
if (!this.container)
|
|
4329
|
+
return;
|
|
4330
|
+
const raw = (_a = window.sessionStorage) === null || _a === void 0 ? void 0 : _a.getItem("orderData");
|
|
4331
|
+
if (!raw)
|
|
4332
|
+
return; // not a post-purchase page — nothing to dedupe
|
|
4333
|
+
const order = JSON.parse(raw) || {};
|
|
4334
|
+
const orderId = order.orderId;
|
|
4335
|
+
if (!orderId)
|
|
4336
|
+
return;
|
|
4337
|
+
// orderData persists across upsell page loads — fire the primary Purchase
|
|
4338
|
+
// Pixel once per order. (Meta also dedupes by event_id over 48h, so this is
|
|
4339
|
+
// belt-and-suspenders against a per-page re-fire.)
|
|
4340
|
+
const guardKey = `__dl_cc_purchase_${orderId}`;
|
|
4341
|
+
if (window.sessionStorage.getItem(guardKey))
|
|
4342
|
+
return;
|
|
4343
|
+
window.sessionStorage.setItem(guardKey, "1");
|
|
4344
|
+
// KEEP IN SYNC with the server formula above.
|
|
4345
|
+
const eventId = `checkoutchamp_purchase_${orderId}`;
|
|
4346
|
+
// value/currency are for EMQ quality only — Meta dedup is event_id+name, so
|
|
4347
|
+
// a mismatch here never breaks dedup. Best-effort parse of CC's fields.
|
|
4348
|
+
const value = Number(order.totalAmount);
|
|
4349
|
+
const properties = {
|
|
4350
|
+
order_id: String(orderId),
|
|
4351
|
+
content_type: "product",
|
|
4352
|
+
};
|
|
4353
|
+
if (Number.isFinite(value))
|
|
4354
|
+
properties.value = value;
|
|
4355
|
+
const currency = order.currencyCode || order.currency;
|
|
4356
|
+
if (currency)
|
|
4357
|
+
properties.currency = String(currency);
|
|
4358
|
+
if (order.productId)
|
|
4359
|
+
properties.content_ids = [String(order.productId)];
|
|
4360
|
+
// Pixel-only co-fire. 'purchase' maps to Meta 'Purchase' in trackToPixels,
|
|
4361
|
+
// matching the server-side rule's platform_event_name.
|
|
4362
|
+
this.container.trackToPixels("purchase", properties, eventId);
|
|
4363
|
+
this.log("Checkout Champ Purchase Pixel co-fired (CAPI dedup):", {
|
|
4364
|
+
eventId,
|
|
4365
|
+
value: properties.value,
|
|
4366
|
+
currency: properties.currency,
|
|
4367
|
+
});
|
|
4368
|
+
}
|
|
4369
|
+
catch (error) {
|
|
4370
|
+
// Never let dedup co-fire break the page or init.
|
|
4371
|
+
this.log("fireCheckoutChampPurchasePixel failed:", error);
|
|
4372
|
+
}
|
|
4373
|
+
}
|
|
4374
|
+
/**
|
|
4375
|
+
* Storefront → Checkout Champ link stamping. Finds every `<a href>` whose host
|
|
4376
|
+
* matches the configured CC domain list and appends `?_dl_vid=…&_dl_fbc=…&
|
|
4377
|
+
* _dl_fbp=…&_dl_fbclid=…&_dl_fbclid_at=…&_dl_gclid=…` so the user's
|
|
4378
|
+
* visitor_id + Meta click signals cross the domain. MutationObserver watches
|
|
4379
|
+
* for dynamically-injected links. On click, force-flush the event queue so
|
|
4380
|
+
* any pending track() events land before the browser navigates away.
|
|
4381
|
+
*/
|
|
4382
|
+
syncOutboundLinkParams(domains) {
|
|
4383
|
+
if (typeof window === "undefined" || typeof document === "undefined")
|
|
4384
|
+
return;
|
|
4385
|
+
const lowerDomains = domains.map((d) => d.toLowerCase());
|
|
4386
|
+
const matchesCcDomain = (href) => {
|
|
4387
|
+
try {
|
|
4388
|
+
const host = new URL(href, window.location.href).hostname.toLowerCase();
|
|
4389
|
+
return lowerDomains.some((d) => host === d || host.endsWith("." + d));
|
|
4390
|
+
}
|
|
4391
|
+
catch (_a) {
|
|
4392
|
+
return false;
|
|
4393
|
+
}
|
|
4394
|
+
};
|
|
4395
|
+
const buildBridgeParams = () => {
|
|
4396
|
+
const attribution = this.attribution.getAttributionData();
|
|
4397
|
+
const out = {};
|
|
4398
|
+
const vid = this.identity.getAnonymousId();
|
|
4399
|
+
const fbc = this.cookies.get("_fbc") || attribution._fbc;
|
|
4400
|
+
const fbp = this.cookies.get("_fbp") || attribution._fbp;
|
|
4401
|
+
const fbclid = attribution.clickIdType === "fbclid" ? attribution.clickId : null;
|
|
4402
|
+
const fbclidAt = this.cookies.get("_dl_fbclid_at");
|
|
4403
|
+
const gclid = attribution.clickIdType === "gclid" ? attribution.clickId : null;
|
|
4404
|
+
const gclidAt = this.cookies.get("_dl_gclid_at");
|
|
4405
|
+
if (vid)
|
|
4406
|
+
out._dl_vid = vid;
|
|
4407
|
+
if (fbc)
|
|
4408
|
+
out._dl_fbc = String(fbc);
|
|
4409
|
+
if (fbp)
|
|
4410
|
+
out._dl_fbp = String(fbp);
|
|
4411
|
+
if (fbclid)
|
|
4412
|
+
out._dl_fbclid = String(fbclid);
|
|
4413
|
+
if (fbclidAt)
|
|
4414
|
+
out._dl_fbclid_at = String(fbclidAt);
|
|
4415
|
+
if (gclid)
|
|
4416
|
+
out._dl_gclid = String(gclid);
|
|
4417
|
+
if (gclidAt)
|
|
4418
|
+
out._dl_gclid_at = String(gclidAt);
|
|
4419
|
+
return out;
|
|
4420
|
+
};
|
|
4421
|
+
const stampLink = (anchor) => {
|
|
4422
|
+
if (!anchor.href || !matchesCcDomain(anchor.href))
|
|
4423
|
+
return;
|
|
4424
|
+
try {
|
|
4425
|
+
const u = new URL(anchor.href, window.location.href);
|
|
4426
|
+
const bridge = buildBridgeParams();
|
|
4427
|
+
let mutated = false;
|
|
4428
|
+
for (const [k, v] of Object.entries(bridge)) {
|
|
4429
|
+
if (!u.searchParams.get(k)) {
|
|
4430
|
+
u.searchParams.set(k, v);
|
|
4431
|
+
mutated = true;
|
|
4432
|
+
}
|
|
4433
|
+
}
|
|
4434
|
+
if (mutated)
|
|
4435
|
+
anchor.href = u.toString();
|
|
4436
|
+
}
|
|
4437
|
+
catch (_a) {
|
|
4438
|
+
// Ignore malformed URLs — don't break the page.
|
|
4439
|
+
}
|
|
4440
|
+
};
|
|
4441
|
+
const stampAll = () => {
|
|
4442
|
+
document.querySelectorAll("a[href]").forEach((el) => stampLink(el));
|
|
4443
|
+
};
|
|
4444
|
+
const onClick = (e) => {
|
|
4445
|
+
var _a, _b;
|
|
4446
|
+
const target = (_a = e.target) === null || _a === void 0 ? void 0 : _a.closest("a[href]");
|
|
4447
|
+
if (!target)
|
|
4448
|
+
return;
|
|
4449
|
+
const anchor = target;
|
|
4450
|
+
if (!matchesCcDomain(anchor.href))
|
|
4451
|
+
return;
|
|
4452
|
+
stampLink(anchor); // re-stamp in case attribution changed since DOMReady
|
|
4453
|
+
try {
|
|
4454
|
+
(_b = this.queue) === null || _b === void 0 ? void 0 : _b.flush();
|
|
4455
|
+
}
|
|
4456
|
+
catch (_c) {
|
|
4457
|
+
// Best-effort — never block navigation.
|
|
4458
|
+
}
|
|
4459
|
+
};
|
|
4460
|
+
stampAll();
|
|
4461
|
+
document.addEventListener("click", onClick, true);
|
|
4462
|
+
try {
|
|
4463
|
+
// Debounce re-stamping. A busy SPA (infinite scroll, animations,
|
|
4464
|
+
// React/Vue updates) can fire thousands of mutations per second; a naive
|
|
4465
|
+
// re-stamp on every notification would burn CPU pointlessly when
|
|
4466
|
+
// outbound link sets only change occasionally. 150ms is small enough to
|
|
4467
|
+
// catch links before the user can click them, large enough to coalesce
|
|
4468
|
+
// bursts.
|
|
4469
|
+
let restampTimer = null;
|
|
4470
|
+
const scheduleRestamp = () => {
|
|
4471
|
+
if (restampTimer != null)
|
|
4472
|
+
return;
|
|
4473
|
+
restampTimer = setTimeout(() => {
|
|
4474
|
+
restampTimer = null;
|
|
4475
|
+
stampAll();
|
|
4476
|
+
}, 150);
|
|
4477
|
+
};
|
|
4478
|
+
const observer = new MutationObserver(scheduleRestamp);
|
|
4479
|
+
observer.observe(document.documentElement, { childList: true, subtree: true });
|
|
4480
|
+
// Observer + click listener live for the session; pagehide cleans up on
|
|
4481
|
+
// full-page unload. SPA route changes are fine — we WANT stamping to keep
|
|
4482
|
+
// working across virtual navigations.
|
|
4483
|
+
window.addEventListener("pagehide", () => {
|
|
4484
|
+
try {
|
|
4485
|
+
observer.disconnect();
|
|
4486
|
+
}
|
|
4487
|
+
catch ( /* idempotent */_a) { /* idempotent */ }
|
|
4488
|
+
if (restampTimer != null)
|
|
4489
|
+
clearTimeout(restampTimer);
|
|
4490
|
+
document.removeEventListener("click", onClick, true);
|
|
4491
|
+
}, { once: true });
|
|
4492
|
+
}
|
|
4493
|
+
catch (error) {
|
|
4494
|
+
this.log("MutationObserver setup failed (CC link sync):", error);
|
|
4495
|
+
}
|
|
4496
|
+
this.log("Checkout Champ outbound-link sync active for:", lowerDomains);
|
|
4497
|
+
}
|
|
4139
4498
|
/**
|
|
4140
4499
|
* Create event payload
|
|
4141
4500
|
*/
|
|
@@ -4196,7 +4555,7 @@ var Datalyr = (function (exports) {
|
|
|
4196
4555
|
resolution_method: 'browser_sdk',
|
|
4197
4556
|
resolution_confidence: 1.0,
|
|
4198
4557
|
// SDK metadata (keep in sync with package.json version)
|
|
4199
|
-
sdk_version: '1.6.
|
|
4558
|
+
sdk_version: '1.6.5',
|
|
4200
4559
|
sdk_name: 'datalyr-web-sdk'
|
|
4201
4560
|
};
|
|
4202
4561
|
return payload;
|