@datalyr/web 1.6.4 → 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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @datalyr/web v1.6.4
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
@@ -3636,6 +3636,16 @@ class Datalyr {
3636
3636
  yield this.container.init().catch(error => {
3637
3637
  this.log('Container initialization failed:', error);
3638
3638
  });
3639
+ // Checkout Champ thank-you/upsell page: co-fire the browser Meta Pixel
3640
+ // Purchase with the SAME deterministic event_id the CC webhook stamps
3641
+ // server-side, so Meta dedupes the browser event against the server-side
3642
+ // CAPI event (dedup = event_name + event_id). Pixel-only — the CC Export
3643
+ // Profile webhook owns the server event + CAPI postback. No-op anywhere
3644
+ // except a post-purchase page (keyed on CC's sessionStorage orderData).
3645
+ // Must run AFTER container.init() so fbq is loaded + init'd.
3646
+ if (this.config.platform === 'checkoutchamp') {
3647
+ this.fireCheckoutChampPurchasePixel();
3648
+ }
3639
3649
  }
3640
3650
  // autoIdentify default for the CC bridge:
3641
3651
  // - platform === 'checkoutchamp' (CC funnel pages) OR
@@ -4271,6 +4281,93 @@ class Datalyr {
4271
4281
  this.log("restoreFromURL failed:", error);
4272
4282
  }
4273
4283
  }
4284
+ /**
4285
+ * Checkout Champ Meta Pixel ⇄ CAPI deduplication.
4286
+ *
4287
+ * On a CC thank-you / upsell page, fire the BROWSER Meta Pixel Purchase with the
4288
+ * exact same event_id the CC webhook stamps server-side, so Meta collapses the
4289
+ * browser Pixel event and the server-side CAPI event into one (dedup key =
4290
+ * event_name + event_id). This gives the EMQ lift of a matched browser+server
4291
+ * event without double-counting conversions in Ads Manager.
4292
+ *
4293
+ * PIXEL-ONLY by design. We do NOT enqueue a server event here: the CC Export
4294
+ * Profile webhook (webhooks/platforms/checkoutchamp.js) already ingests the
4295
+ * purchase and fires CAPI. Calling track() here would create a second server
4296
+ * event (source='web') AND double-fire CAPI — defeating the whole point.
4297
+ *
4298
+ * The event_id MUST stay byte-identical to the server formula:
4299
+ * webhooks/platforms/checkoutchamp.js:250
4300
+ * generateEventId('checkoutchamp', `${event_type}_${order_id}`)
4301
+ * webhooks/core/ingest.js:122 → `${platform}_${webhookEventId}`
4302
+ * ⇒ `checkoutchamp_purchase_<order_id>`
4303
+ * where <order_id> is the value CC posts to the webhook via its [orderId] macro.
4304
+ * We read the browser-side counterpart from CC's own client-side order object:
4305
+ * JSON.parse(sessionStorage.getItem('orderData')).orderId
4306
+ * (CC docs: referenced in custom scripts as `orderDataTmp.orderId`).
4307
+ *
4308
+ * ASSUMPTION TO VERIFY ON A REAL CC TEST ORDER: that sessionStorage
4309
+ * orderData.orderId === the [orderId] CC sends to the postback. If a merchant's
4310
+ * CC plan exposes a different id client-side, the two event_ids won't match and
4311
+ * Meta will show duplicates — caught by the test order in the setup checklist.
4312
+ *
4313
+ * v1 scope: the primary order only. Per-upsell Pixel dedup (each upsell is its
4314
+ * own order_id + parent_order_id server-side) needs the upsell sessionStorage
4315
+ * shape confirmed on a live funnel first — tracked as a follow-up.
4316
+ */
4317
+ fireCheckoutChampPurchasePixel() {
4318
+ var _a;
4319
+ if (typeof window === "undefined")
4320
+ return;
4321
+ try {
4322
+ // Needs the container (where the Meta Pixel lives). trackToPixels itself
4323
+ // no-ops unless a Meta pixel is enabled + fbq is present, so an
4324
+ // unconfigured workspace silently does nothing.
4325
+ if (!this.container)
4326
+ return;
4327
+ const raw = (_a = window.sessionStorage) === null || _a === void 0 ? void 0 : _a.getItem("orderData");
4328
+ if (!raw)
4329
+ return; // not a post-purchase page — nothing to dedupe
4330
+ const order = JSON.parse(raw) || {};
4331
+ const orderId = order.orderId;
4332
+ if (!orderId)
4333
+ return;
4334
+ // orderData persists across upsell page loads — fire the primary Purchase
4335
+ // Pixel once per order. (Meta also dedupes by event_id over 48h, so this is
4336
+ // belt-and-suspenders against a per-page re-fire.)
4337
+ const guardKey = `__dl_cc_purchase_${orderId}`;
4338
+ if (window.sessionStorage.getItem(guardKey))
4339
+ return;
4340
+ window.sessionStorage.setItem(guardKey, "1");
4341
+ // KEEP IN SYNC with the server formula above.
4342
+ const eventId = `checkoutchamp_purchase_${orderId}`;
4343
+ // value/currency are for EMQ quality only — Meta dedup is event_id+name, so
4344
+ // a mismatch here never breaks dedup. Best-effort parse of CC's fields.
4345
+ const value = Number(order.totalAmount);
4346
+ const properties = {
4347
+ order_id: String(orderId),
4348
+ content_type: "product",
4349
+ };
4350
+ if (Number.isFinite(value))
4351
+ properties.value = value;
4352
+ const currency = order.currencyCode || order.currency;
4353
+ if (currency)
4354
+ properties.currency = String(currency);
4355
+ if (order.productId)
4356
+ properties.content_ids = [String(order.productId)];
4357
+ // Pixel-only co-fire. 'purchase' maps to Meta 'Purchase' in trackToPixels,
4358
+ // matching the server-side rule's platform_event_name.
4359
+ this.container.trackToPixels("purchase", properties, eventId);
4360
+ this.log("Checkout Champ Purchase Pixel co-fired (CAPI dedup):", {
4361
+ eventId,
4362
+ value: properties.value,
4363
+ currency: properties.currency,
4364
+ });
4365
+ }
4366
+ catch (error) {
4367
+ // Never let dedup co-fire break the page or init.
4368
+ this.log("fireCheckoutChampPurchasePixel failed:", error);
4369
+ }
4370
+ }
4274
4371
  /**
4275
4372
  * Storefront → Checkout Champ link stamping. Finds every `<a href>` whose host
4276
4373
  * matches the configured CC domain list and appends `?_dl_vid=…&_dl_fbc=…&
@@ -4455,7 +4552,7 @@ class Datalyr {
4455
4552
  resolution_method: 'browser_sdk',
4456
4553
  resolution_confidence: 1.0,
4457
4554
  // SDK metadata (keep in sync with package.json version)
4458
- sdk_version: '1.6.4',
4555
+ sdk_version: '1.6.5',
4459
4556
  sdk_name: 'datalyr-web-sdk'
4460
4557
  };
4461
4558
  return payload;