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