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