@outlit/browser 0.4.0 → 1.0.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,9 +1,9 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
3
  import { ReactNode } from 'react';
4
- import { j as OutlitOptions, U as UserIdentity, O as Outlit } from '../tracker-DK-2gYCi.mjs';
4
+ import { f as OutlitOptions, U as UserIdentity, O as Outlit, B as BillingOptions } from '../tracker-BY_JTlOP.mjs';
5
5
  import { BrowserTrackOptions, BrowserIdentifyOptions } from '@outlit/core';
6
- export { BrowserIdentifyOptions, BrowserTrackOptions, ExplicitJourneyStage, TrackerConfig } from '@outlit/core';
6
+ export { BrowserIdentifyOptions, BrowserTrackOptions, CustomerIdentifier, ExplicitJourneyStage, TrackerConfig } from '@outlit/core';
7
7
 
8
8
  interface OutlitContextValue {
9
9
  outlit: Outlit | null;
@@ -117,25 +117,22 @@ interface UseOutlitReturn {
117
117
  */
118
118
  clearUser: () => void;
119
119
  /**
120
- * Mark the current user as activated.
121
- * Call after a user completes onboarding or activation milestone.
120
+ * User namespace methods for contact journey stages.
122
121
  */
123
- activate: (properties?: Record<string, string | number | boolean | null>) => void;
122
+ user: {
123
+ identify: (options: BrowserIdentifyOptions) => void;
124
+ activate: (properties?: Record<string, string | number | boolean | null>) => void;
125
+ engaged: (properties?: Record<string, string | number | boolean | null>) => void;
126
+ inactive: (properties?: Record<string, string | number | boolean | null>) => void;
127
+ };
124
128
  /**
125
- * Mark the current user as engaged.
126
- * Call when user reaches a usage milestone.
129
+ * Customer namespace methods for billing status.
127
130
  */
128
- engaged: (properties?: Record<string, string | number | boolean | null>) => void;
129
- /**
130
- * Mark the current user as paid.
131
- * Call after successful payment/subscription.
132
- */
133
- paid: (properties?: Record<string, string | number | boolean | null>) => void;
134
- /**
135
- * Mark the current user as churned.
136
- * Call when subscription is cancelled.
137
- */
138
- churned: (properties?: Record<string, string | number | boolean | null>) => void;
131
+ customer: {
132
+ trialing: (options: BillingOptions) => void;
133
+ paid: (options: BillingOptions) => void;
134
+ churned: (options: BillingOptions) => void;
135
+ };
139
136
  /**
140
137
  * Whether Outlit is initialized.
141
138
  */
@@ -159,10 +156,10 @@ interface UseOutlitReturn {
159
156
  * import { useOutlit } from '@outlit/browser/react'
160
157
  *
161
158
  * function MyComponent() {
162
- * const { track, identify } = useOutlit()
159
+ * const { track, user } = useOutlit()
163
160
  *
164
161
  * return (
165
- * <button onClick={() => track('button_clicked', { id: 'cta' })}>
162
+ * <button onClick={() => user.activate({ milestone: 'onboarding_complete' })}>
166
163
  * Click me
167
164
  * </button>
168
165
  * )
@@ -219,4 +216,4 @@ declare function useTrack(): (eventName: string, properties?: BrowserTrackOption
219
216
  */
220
217
  declare function useIdentify(): (options: BrowserIdentifyOptions) => void;
221
218
 
222
- export { OutlitContext, type OutlitContextValue, OutlitProvider, type OutlitProviderProps, type UseOutlitReturn, UserIdentity, useIdentify, useOutlit, useTrack };
219
+ export { BillingOptions, OutlitContext, type OutlitContextValue, OutlitProvider, type OutlitProviderProps, type UseOutlitReturn, UserIdentity, useIdentify, useOutlit, useTrack };
@@ -1,9 +1,9 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
3
  import { ReactNode } from 'react';
4
- import { j as OutlitOptions, U as UserIdentity, O as Outlit } from '../tracker-DK-2gYCi.js';
4
+ import { f as OutlitOptions, U as UserIdentity, O as Outlit, B as BillingOptions } from '../tracker-BY_JTlOP.js';
5
5
  import { BrowserTrackOptions, BrowserIdentifyOptions } from '@outlit/core';
6
- export { BrowserIdentifyOptions, BrowserTrackOptions, ExplicitJourneyStage, TrackerConfig } from '@outlit/core';
6
+ export { BrowserIdentifyOptions, BrowserTrackOptions, CustomerIdentifier, ExplicitJourneyStage, TrackerConfig } from '@outlit/core';
7
7
 
8
8
  interface OutlitContextValue {
9
9
  outlit: Outlit | null;
@@ -117,25 +117,22 @@ interface UseOutlitReturn {
117
117
  */
118
118
  clearUser: () => void;
119
119
  /**
120
- * Mark the current user as activated.
121
- * Call after a user completes onboarding or activation milestone.
120
+ * User namespace methods for contact journey stages.
122
121
  */
123
- activate: (properties?: Record<string, string | number | boolean | null>) => void;
122
+ user: {
123
+ identify: (options: BrowserIdentifyOptions) => void;
124
+ activate: (properties?: Record<string, string | number | boolean | null>) => void;
125
+ engaged: (properties?: Record<string, string | number | boolean | null>) => void;
126
+ inactive: (properties?: Record<string, string | number | boolean | null>) => void;
127
+ };
124
128
  /**
125
- * Mark the current user as engaged.
126
- * Call when user reaches a usage milestone.
129
+ * Customer namespace methods for billing status.
127
130
  */
128
- engaged: (properties?: Record<string, string | number | boolean | null>) => void;
129
- /**
130
- * Mark the current user as paid.
131
- * Call after successful payment/subscription.
132
- */
133
- paid: (properties?: Record<string, string | number | boolean | null>) => void;
134
- /**
135
- * Mark the current user as churned.
136
- * Call when subscription is cancelled.
137
- */
138
- churned: (properties?: Record<string, string | number | boolean | null>) => void;
131
+ customer: {
132
+ trialing: (options: BillingOptions) => void;
133
+ paid: (options: BillingOptions) => void;
134
+ churned: (options: BillingOptions) => void;
135
+ };
139
136
  /**
140
137
  * Whether Outlit is initialized.
141
138
  */
@@ -159,10 +156,10 @@ interface UseOutlitReturn {
159
156
  * import { useOutlit } from '@outlit/browser/react'
160
157
  *
161
158
  * function MyComponent() {
162
- * const { track, identify } = useOutlit()
159
+ * const { track, user } = useOutlit()
163
160
  *
164
161
  * return (
165
- * <button onClick={() => track('button_clicked', { id: 'cta' })}>
162
+ * <button onClick={() => user.activate({ milestone: 'onboarding_complete' })}>
166
163
  * Click me
167
164
  * </button>
168
165
  * )
@@ -219,4 +216,4 @@ declare function useTrack(): (eventName: string, properties?: BrowserTrackOption
219
216
  */
220
217
  declare function useIdentify(): (options: BrowserIdentifyOptions) => void;
221
218
 
222
- export { OutlitContext, type OutlitContextValue, OutlitProvider, type OutlitProviderProps, type UseOutlitReturn, UserIdentity, useIdentify, useOutlit, useTrack };
219
+ export { BillingOptions, OutlitContext, type OutlitContextValue, OutlitProvider, type OutlitProviderProps, type UseOutlitReturn, UserIdentity, useIdentify, useOutlit, useTrack };
@@ -730,7 +730,7 @@ var Outlit = class {
730
730
  * Links the anonymous visitor to a known user.
731
731
  *
732
732
  * When email or userId is provided, also sets the current user identity
733
- * for stage events (activate, engaged, paid).
733
+ * for stage events (activate, engaged, inactive).
734
734
  */
735
735
  identify(options) {
736
736
  if (!this.isTrackingEnabled) {
@@ -791,37 +791,22 @@ var Outlit = class {
791
791
  this.identify({ email: identity.email, userId: identity.userId, traits: identity.traits });
792
792
  }
793
793
  /**
794
- * Mark the current user as activated.
795
- * This is typically called after a user completes onboarding or a key activation milestone.
796
- * Requires the user to be identified (via setUser or identify with userId).
794
+ * User namespace methods for contact journey stages.
797
795
  */
798
- activate(properties) {
799
- this.sendStageEvent("activated", properties);
800
- }
801
- /**
802
- * Mark the current user as engaged.
803
- * This is typically called when a user reaches a usage milestone.
804
- * Can also be computed automatically by the engagement cron.
805
- */
806
- engaged(properties) {
807
- this.sendStageEvent("engaged", properties);
808
- }
809
- /**
810
- * Mark the current user as paid.
811
- * This is typically called after a successful payment/subscription.
812
- * Can also be triggered by Stripe integration.
813
- */
814
- paid(properties) {
815
- this.sendStageEvent("paid", properties);
816
- }
796
+ user = {
797
+ identify: (options) => this.identify(options),
798
+ activate: (properties) => this.sendStageEvent("activated", properties),
799
+ engaged: (properties) => this.sendStageEvent("engaged", properties),
800
+ inactive: (properties) => this.sendStageEvent("inactive", properties)
801
+ };
817
802
  /**
818
- * Mark the current user as churned.
819
- * This is typically called when a subscription is cancelled.
820
- * Can also be triggered by Stripe integration.
803
+ * Customer namespace methods for billing status.
821
804
  */
822
- churned(properties) {
823
- this.sendStageEvent("churned", properties);
824
- }
805
+ customer = {
806
+ trialing: (options) => this.sendBillingEvent("trialing", options),
807
+ paid: (options) => this.sendBillingEvent("paid", options),
808
+ churned: (options) => this.sendBillingEvent("churned", options)
809
+ };
825
810
  /**
826
811
  * Internal method to send a stage event.
827
812
  */
@@ -844,6 +829,26 @@ var Outlit = class {
844
829
  });
845
830
  this.enqueue(event);
846
831
  }
832
+ sendBillingEvent(status, options) {
833
+ if (!this.isTrackingEnabled) {
834
+ console.warn("[Outlit] Tracking not enabled. Call enableTracking() first.");
835
+ return;
836
+ }
837
+ if (!options.customerId && !options.stripeCustomerId && !options.domain) {
838
+ console.warn("[Outlit] customer.* requires customerId, stripeCustomerId, or domain");
839
+ return;
840
+ }
841
+ const event = (0, import_core3.buildBillingEvent)({
842
+ url: window.location.href,
843
+ referrer: document.referrer,
844
+ status,
845
+ customerId: options.customerId,
846
+ stripeCustomerId: options.stripeCustomerId,
847
+ domain: options.domain,
848
+ properties: options.properties
849
+ });
850
+ this.enqueue(event);
851
+ }
847
852
  /**
848
853
  * Get the current visitor ID.
849
854
  * Returns null if tracking is not enabled.
@@ -960,8 +965,11 @@ var Outlit = class {
960
965
  const blob = new Blob([JSON.stringify(payload)], { type: "application/json" });
961
966
  const sent = navigator.sendBeacon(url, blob);
962
967
  if (sent) return;
968
+ console.warn(
969
+ `[Outlit] sendBeacon failed for ${events.length} events, falling back to fetch`
970
+ );
963
971
  }
964
- await fetch(url, {
972
+ const response = await fetch(url, {
965
973
  method: "POST",
966
974
  headers: {
967
975
  "Content-Type": "application/json"
@@ -969,8 +977,13 @@ var Outlit = class {
969
977
  body: JSON.stringify(payload),
970
978
  keepalive: true
971
979
  });
980
+ if (!response.ok) {
981
+ console.warn(
982
+ `[Outlit] Server returned ${response.status} when sending ${events.length} events`
983
+ );
984
+ }
972
985
  } catch (error) {
973
- console.warn("[Outlit] Failed to send events:", error);
986
+ console.warn(`[Outlit] Failed to send ${events.length} events:`, error);
974
987
  }
975
988
  }
976
989
  };
@@ -1078,6 +1091,16 @@ function useOutlit() {
1078
1091
  },
1079
1092
  [outlit]
1080
1093
  );
1094
+ const userIdentify = (0, import_react2.useCallback)(
1095
+ (options) => {
1096
+ if (!outlit) {
1097
+ console.warn("[Outlit] Not initialized. Make sure OutlitProvider is mounted.");
1098
+ return;
1099
+ }
1100
+ outlit.user.identify(options);
1101
+ },
1102
+ [outlit]
1103
+ );
1081
1104
  const getVisitorId = (0, import_react2.useCallback)(() => {
1082
1105
  if (!outlit) return null;
1083
1106
  return outlit.getVisitorId();
@@ -1105,7 +1128,7 @@ function useOutlit() {
1105
1128
  console.warn("[Outlit] Not initialized. Make sure OutlitProvider is mounted.");
1106
1129
  return;
1107
1130
  }
1108
- outlit.activate(properties);
1131
+ outlit.user.activate(properties);
1109
1132
  },
1110
1133
  [outlit]
1111
1134
  );
@@ -1115,27 +1138,47 @@ function useOutlit() {
1115
1138
  console.warn("[Outlit] Not initialized. Make sure OutlitProvider is mounted.");
1116
1139
  return;
1117
1140
  }
1118
- outlit.engaged(properties);
1141
+ outlit.user.engaged(properties);
1119
1142
  },
1120
1143
  [outlit]
1121
1144
  );
1122
- const paid = (0, import_react2.useCallback)(
1145
+ const inactive = (0, import_react2.useCallback)(
1123
1146
  (properties) => {
1124
1147
  if (!outlit) {
1125
1148
  console.warn("[Outlit] Not initialized. Make sure OutlitProvider is mounted.");
1126
1149
  return;
1127
1150
  }
1128
- outlit.paid(properties);
1151
+ outlit.user.inactive(properties);
1152
+ },
1153
+ [outlit]
1154
+ );
1155
+ const trialing = (0, import_react2.useCallback)(
1156
+ (options) => {
1157
+ if (!outlit) {
1158
+ console.warn("[Outlit] Not initialized. Make sure OutlitProvider is mounted.");
1159
+ return;
1160
+ }
1161
+ outlit.customer.trialing(options);
1162
+ },
1163
+ [outlit]
1164
+ );
1165
+ const paid = (0, import_react2.useCallback)(
1166
+ (options) => {
1167
+ if (!outlit) {
1168
+ console.warn("[Outlit] Not initialized. Make sure OutlitProvider is mounted.");
1169
+ return;
1170
+ }
1171
+ outlit.customer.paid(options);
1129
1172
  },
1130
1173
  [outlit]
1131
1174
  );
1132
1175
  const churned = (0, import_react2.useCallback)(
1133
- (properties) => {
1176
+ (options) => {
1134
1177
  if (!outlit) {
1135
1178
  console.warn("[Outlit] Not initialized. Make sure OutlitProvider is mounted.");
1136
1179
  return;
1137
1180
  }
1138
- outlit.churned(properties);
1181
+ outlit.customer.churned(options);
1139
1182
  },
1140
1183
  [outlit]
1141
1184
  );
@@ -1145,10 +1188,17 @@ function useOutlit() {
1145
1188
  getVisitorId,
1146
1189
  setUser,
1147
1190
  clearUser,
1148
- activate,
1149
- engaged,
1150
- paid,
1151
- churned,
1191
+ user: {
1192
+ identify: userIdentify,
1193
+ activate,
1194
+ engaged,
1195
+ inactive
1196
+ },
1197
+ customer: {
1198
+ trialing,
1199
+ paid,
1200
+ churned
1201
+ },
1152
1202
  isInitialized,
1153
1203
  isTrackingEnabled,
1154
1204
  enableTracking