@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.
package/dist/datalyr.js CHANGED
@@ -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
@@ -3639,6 +3639,16 @@ var Datalyr = (function (exports) {
3639
3639
  yield this.container.init().catch(error => {
3640
3640
  this.log('Container initialization failed:', error);
3641
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
+ }
3642
3652
  }
3643
3653
  // autoIdentify default for the CC bridge:
3644
3654
  // - platform === 'checkoutchamp' (CC funnel pages) OR
@@ -4274,6 +4284,93 @@ var Datalyr = (function (exports) {
4274
4284
  this.log("restoreFromURL failed:", error);
4275
4285
  }
4276
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
+ }
4277
4374
  /**
4278
4375
  * Storefront → Checkout Champ link stamping. Finds every `<a href>` whose host
4279
4376
  * matches the configured CC domain list and appends `?_dl_vid=…&_dl_fbc=…&
@@ -4458,7 +4555,7 @@ var Datalyr = (function (exports) {
4458
4555
  resolution_method: 'browser_sdk',
4459
4556
  resolution_confidence: 1.0,
4460
4557
  // SDK metadata (keep in sync with package.json version)
4461
- sdk_version: '1.6.4',
4558
+ sdk_version: '1.6.5',
4462
4559
  sdk_name: 'datalyr-web-sdk'
4463
4560
  };
4464
4561
  return payload;