@datalyr/web 1.4.0 → 1.5.0

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.4.0
2
+ * @datalyr/web v1.5.0
3
3
  * Datalyr Web SDK - Modern attribution tracking for web applications
4
4
  * (c) 2026 Datalyr Inc.
5
5
  * Released under the MIT License
@@ -3705,6 +3705,12 @@ class Datalyr {
3705
3705
  * the React Native and iOS SDKs.
3706
3706
  */
3707
3707
  screen(screenName, properties = {}) {
3708
+ if (!this.initialized) {
3709
+ console.warn('[Datalyr] SDK not initialized. Call init() first.');
3710
+ return;
3711
+ }
3712
+ if (!this.shouldTrack())
3713
+ return;
3708
3714
  this.track('pageview', Object.assign({ screen: screenName }, properties));
3709
3715
  }
3710
3716
  /**
@@ -3751,6 +3757,57 @@ class Datalyr {
3751
3757
  getAnonymousId() {
3752
3758
  return this.identity.getAnonymousId();
3753
3759
  }
3760
+ /**
3761
+ * Get the current visitor ID (alias for getAnonymousId).
3762
+ * Matches the `visitor_id` terminology used in the dashboard, schema,
3763
+ * and integration guides — pass this to Stripe's `client_reference_id`
3764
+ * or webhook metadata for first-party attribution.
3765
+ */
3766
+ getVisitorId() {
3767
+ return this.identity.getAnonymousId();
3768
+ }
3769
+ /**
3770
+ * Returns a metadata bundle ready to pass to Stripe so the webhook can
3771
+ * deterministically link the payment back to this browser session (90%+
3772
+ * attribution match vs. 70-85% email-only).
3773
+ *
3774
+ * Usage (Stripe Checkout Session):
3775
+ * stripe.checkout.sessions.create({
3776
+ * ...datalyr.getStripeMetadata(),
3777
+ * line_items: [...],
3778
+ * })
3779
+ *
3780
+ * Usage (PaymentIntent / Subscription / Customer):
3781
+ * stripe.paymentIntents.create({
3782
+ * amount, currency,
3783
+ * metadata: datalyr.getStripeMetadata().metadata,
3784
+ * })
3785
+ *
3786
+ * The server-side Datalyr webhook reads `client_reference_id` on Checkout
3787
+ * and `metadata.visitor_id` on every other Stripe object.
3788
+ */
3789
+ getStripeMetadata() {
3790
+ const visitorId = this.identity.getAnonymousId();
3791
+ return {
3792
+ client_reference_id: visitorId,
3793
+ metadata: { visitor_id: visitorId },
3794
+ };
3795
+ }
3796
+ /**
3797
+ * Returns a metadata object ready to attach to a Whop checkout configuration.
3798
+ * Whop inherits checkout-configuration metadata onto payments and memberships
3799
+ * (https://docs.whop.com/api-reference/checkout-configurations/), so Datalyr
3800
+ * can read `metadata.visitor_id` off every resulting webhook event.
3801
+ *
3802
+ * Usage:
3803
+ * whop.checkoutConfigurations.create({
3804
+ * plan_id,
3805
+ * metadata: datalyr.getWhopCheckoutMetadata(),
3806
+ * })
3807
+ */
3808
+ getWhopCheckoutMetadata() {
3809
+ return { visitor_id: this.identity.getAnonymousId() };
3810
+ }
3754
3811
  /**
3755
3812
  * Get the current user ID
3756
3813
  */
@@ -3927,7 +3984,7 @@ class Datalyr {
3927
3984
  resolution_method: 'browser_sdk',
3928
3985
  resolution_confidence: 1.0,
3929
3986
  // SDK metadata
3930
- sdk_version: '1.4.0',
3987
+ sdk_version: '1.4.1',
3931
3988
  sdk_name: 'datalyr-web-sdk'
3932
3989
  };
3933
3990
  return payload;