@datalyr/web 1.7.8 → 1.7.9

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.7.8
2
+ * @datalyr/web v1.7.9
3
3
  * Datalyr Web SDK - Modern attribution tracking for web applications
4
4
  * (c) 2026 Datalyr Inc.
5
5
  * Released under the MIT License
@@ -3687,12 +3687,10 @@ class ContainerManager {
3687
3687
  img.dataset.datalyrPixel = script.id;
3688
3688
  document.body.appendChild(img);
3689
3689
  }
3690
- /**
3691
- * Initialize third-party pixels (Meta, Google, TikTok)
3692
- */
3690
+ /** Initialize configured third-party pixels in the merchant's page context. */
3693
3691
  initializePixels() {
3694
3692
  return __awaiter(this, void 0, void 0, function* () {
3695
- var _a, _b, _c;
3693
+ var _a, _b, _c, _e;
3696
3694
  if (!this.pixels)
3697
3695
  return;
3698
3696
  // Initialize Meta Pixel
@@ -3707,8 +3705,58 @@ class ContainerManager {
3707
3705
  if (((_c = this.pixels.tiktok) === null || _c === void 0 ? void 0 : _c.enabled) && this.pixels.tiktok.pixel_id) {
3708
3706
  this.initializeTikTokPixel(this.pixels.tiktok);
3709
3707
  }
3708
+ // The Whop Pixel needs only the merchant's public company ID. Loading it
3709
+ // here lets Whop link this external-site visitor to a later hosted or
3710
+ // embedded Whop checkout without a Datalyr visitor_id in checkout metadata.
3711
+ if (((_e = this.pixels.whop) === null || _e === void 0 ? void 0 : _e.enabled) && this.pixels.whop.company_id) {
3712
+ this.initializeWhopPixel(this.pixels.whop);
3713
+ }
3710
3714
  });
3711
3715
  }
3716
+ /** Initialize Whop's official first-party attribution pixel. */
3717
+ initializeWhopPixel(config) {
3718
+ var _a, _b;
3719
+ try {
3720
+ const host = window;
3721
+ if (!host.whop) {
3722
+ const queue = host.whop = {
3723
+ q: [],
3724
+ t: Date.now(),
3725
+ s: [],
3726
+ o: 'https://t.whop.tw',
3727
+ track: function (...args) {
3728
+ queue.q.push([Date.now(), ...args]);
3729
+ },
3730
+ setScope: function (...args) {
3731
+ queue.s = args.filter((value) => typeof value === 'string');
3732
+ queue.q.push([Date.now(), 'setScope', ...queue.s]);
3733
+ },
3734
+ scope: function (...scope) {
3735
+ return {
3736
+ track: function (...args) {
3737
+ queue.q.push([Date.now(), ...args, { __scope: scope }]);
3738
+ },
3739
+ };
3740
+ },
3741
+ };
3742
+ const script = document.createElement('script');
3743
+ script.async = true;
3744
+ script.src = 'https://t.whop.tw/s.js';
3745
+ const firstScript = document.getElementsByTagName('script')[0];
3746
+ (_a = firstScript === null || firstScript === void 0 ? void 0 : firstScript.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(script, firstScript);
3747
+ if (!firstScript)
3748
+ document.head.appendChild(script);
3749
+ }
3750
+ if (typeof ((_b = host.whop) === null || _b === void 0 ? void 0 : _b.setScope) !== 'function') {
3751
+ throw new Error('Existing window.whop does not expose setScope');
3752
+ }
3753
+ host.whop.setScope(config.company_id);
3754
+ this.log('Whop Pixel initialized:', config.company_id);
3755
+ }
3756
+ catch (error) {
3757
+ this.log('Error initializing Whop Pixel:', error);
3758
+ }
3759
+ }
3712
3760
  /**
3713
3761
  * Initialize Meta (Facebook) Pixel
3714
3762
  *
@@ -3864,7 +3912,7 @@ class ContainerManager {
3864
3912
  * Track event to all initialized pixels
3865
3913
  */
3866
3914
  trackToPixels(eventName, properties = {}, eventId) {
3867
- var _a, _b, _c, _e, _f, _g, _h, _j, _k, _l;
3915
+ var _a, _b, _c, _e, _f, _g, _h, _j, _k, _l, _m, _p;
3868
3916
  // Datalyr-internal events ($identify, $group, $alias, $auto_identify,
3869
3917
  // $app_download_click, …) are not conversions — never forward them to ad
3870
3918
  // pixels. (Previously they fired as noise custom events with the $ stripped.)
@@ -3961,6 +4009,18 @@ class ContainerManager {
3961
4009
  this.log('Error tracking TikTok Pixel event:', error);
3962
4010
  }
3963
4011
  }
4012
+ // Whop records checkout and payment events server-side. Datalyr only sends
4013
+ // page views here, including SPA navigations, so purchases are never doubled.
4014
+ if (((_p = (_m = this.pixels) === null || _m === void 0 ? void 0 : _m.whop) === null || _p === void 0 ? void 0 : _p.enabled) &&
4015
+ window.whop &&
4016
+ (eventName === 'pageview' || eventName === 'page_view')) {
4017
+ try {
4018
+ window.whop.track('page');
4019
+ }
4020
+ catch (error) {
4021
+ this.log('Error tracking Whop Pixel page:', error);
4022
+ }
4023
+ }
3964
4024
  }
3965
4025
  /**
3966
4026
  * Manually trigger a custom script
@@ -6427,7 +6487,7 @@ class Datalyr {
6427
6487
  // drift from the package again (it sat at 1.7.4 across the 1.7.5 release). The
6428
6488
  // build guard (scripts/check-bundle.js, run by build:check) still verifies the
6429
6489
  // deployable bundles carry the package.json version. (FSR-103)
6430
- sdk_version: '1.7.8',
6490
+ sdk_version: '1.7.9',
6431
6491
  sdk_name: 'datalyr-web-sdk',
6432
6492
  // A3-25: versioned-envelope stamp. Every SDK emits schema_version so the ingest/contract
6433
6493
  // layer can key on ONE canonical envelope version (snake_case fields, event_name/event_data