@outlit/browser 1.4.3 → 1.4.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.
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +69 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -6
- package/dist/index.mjs.map +1 -1
- package/dist/outlit.global.js +1 -1
- package/dist/outlit.global.js.map +1 -1
- package/dist/react/index.d.mts +116 -116
- package/dist/react/index.d.ts +116 -116
- package/dist/react/index.js +72 -5
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +75 -7
- package/dist/react/index.mjs.map +1 -1
- package/dist/{tracker-CzhtZoOC.d.mts → tracker-DlHUyaah.d.mts} +3 -5
- package/dist/{tracker-CzhtZoOC.d.ts → tracker-DlHUyaah.d.ts} +3 -5
- package/dist/vue/index.d.mts +46 -46
- package/dist/vue/index.d.ts +46 -46
- package/dist/vue/index.js +72 -5
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/index.mjs +75 -7
- package/dist/vue/index.mjs.map +1 -1
- package/package.json +32 -18
package/dist/react/index.d.mts
CHANGED
|
@@ -1,122 +1,9 @@
|
|
|
1
|
+
import { BrowserTrackOptions, BrowserIdentifyOptions } from '@outlit/core';
|
|
2
|
+
export { BrowserIdentifyOptions, BrowserTrackOptions, CustomerIdentifier, ExplicitJourneyStage, TrackerConfig } from '@outlit/core';
|
|
3
|
+
import { U as UserIdentity, B as BillingOptions, O as Outlit, h as OutlitOptions } from '../tracker-DlHUyaah.mjs';
|
|
1
4
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
5
|
import * as react from 'react';
|
|
3
6
|
import { ReactNode } from 'react';
|
|
4
|
-
import { O as Outlit, U as UserIdentity, h as OutlitOptions, B as BillingOptions } from '../tracker-CzhtZoOC.mjs';
|
|
5
|
-
import { BrowserTrackOptions, BrowserIdentifyOptions } from '@outlit/core';
|
|
6
|
-
export { BrowserIdentifyOptions, BrowserTrackOptions, CustomerIdentifier, ExplicitJourneyStage, TrackerConfig } from '@outlit/core';
|
|
7
|
-
|
|
8
|
-
interface OutlitContextValue {
|
|
9
|
-
outlit: Outlit | null;
|
|
10
|
-
isInitialized: boolean;
|
|
11
|
-
isTrackingEnabled: boolean;
|
|
12
|
-
enableTracking: () => void;
|
|
13
|
-
disableTracking: () => void;
|
|
14
|
-
}
|
|
15
|
-
declare const OutlitContext: react.Context<OutlitContextValue>;
|
|
16
|
-
interface OutlitProviderBaseProps {
|
|
17
|
-
children: ReactNode;
|
|
18
|
-
/**
|
|
19
|
-
* Current user identity.
|
|
20
|
-
* When provided with email or userId, calls setUser() to identify the user.
|
|
21
|
-
* When null, undefined, or missing identity fields, calls clearUser().
|
|
22
|
-
*
|
|
23
|
-
* This is the recommended way to handle user identity in server-rendered apps:
|
|
24
|
-
* pass the user from your auth system as a prop.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```tsx
|
|
28
|
-
* // Server component (layout.tsx)
|
|
29
|
-
* const session = await auth()
|
|
30
|
-
* return (
|
|
31
|
-
* <OutlitProvider
|
|
32
|
-
* publicKey="pk_xxx"
|
|
33
|
-
* user={session?.user ? { email: session.user.email, userId: session.user.id } : null}
|
|
34
|
-
* >
|
|
35
|
-
* {children}
|
|
36
|
-
* </OutlitProvider>
|
|
37
|
-
* )
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
user?: UserIdentity | null;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Props for using a pre-existing Outlit instance.
|
|
44
|
-
* The provider will use this instance directly without creating a new one.
|
|
45
|
-
* The caller owns the instance lifecycle — shutdown() will NOT be called on unmount.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```tsx
|
|
49
|
-
* import { Outlit } from '@outlit/browser'
|
|
50
|
-
* import { OutlitProvider } from '@outlit/browser/react'
|
|
51
|
-
*
|
|
52
|
-
* const outlit = new Outlit({ publicKey: 'pk_xxx', trackPageviews: false })
|
|
53
|
-
*
|
|
54
|
-
* function App() {
|
|
55
|
-
* const user = useAuth()
|
|
56
|
-
* return (
|
|
57
|
-
* <OutlitProvider client={outlit} user={user ? { email: user.email } : null}>
|
|
58
|
-
* {children}
|
|
59
|
-
* </OutlitProvider>
|
|
60
|
-
* )
|
|
61
|
-
* }
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
type NeverOutlitOptions = {
|
|
65
|
-
[K in keyof OutlitOptions]?: never;
|
|
66
|
-
};
|
|
67
|
-
interface OutlitProviderClientProps extends OutlitProviderBaseProps, NeverOutlitOptions {
|
|
68
|
-
/** An existing Outlit instance to use. Config props are ignored when this is provided. */
|
|
69
|
-
client: Outlit;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Props for creating a new Outlit instance internally.
|
|
73
|
-
* This is the default behavior — the provider creates and owns the instance.
|
|
74
|
-
*/
|
|
75
|
-
interface OutlitProviderConfigProps extends OutlitProviderBaseProps, Omit<OutlitOptions, "trackPageviews"> {
|
|
76
|
-
client?: never;
|
|
77
|
-
/**
|
|
78
|
-
* Whether to automatically track pageviews.
|
|
79
|
-
* When true (default), tracks pageviews on route changes.
|
|
80
|
-
*/
|
|
81
|
-
trackPageviews?: boolean;
|
|
82
|
-
/**
|
|
83
|
-
* Whether to start tracking automatically on mount.
|
|
84
|
-
* Set to false if you need to wait for user consent.
|
|
85
|
-
* Call enableTracking() (from useOutlit hook) after consent is obtained.
|
|
86
|
-
* @default true
|
|
87
|
-
*/
|
|
88
|
-
autoTrack?: boolean;
|
|
89
|
-
}
|
|
90
|
-
type OutlitProviderProps = OutlitProviderClientProps | OutlitProviderConfigProps;
|
|
91
|
-
/**
|
|
92
|
-
* Outlit Provider component.
|
|
93
|
-
* Initializes the client and provides it to child components via context.
|
|
94
|
-
*
|
|
95
|
-
* Can be used in two ways:
|
|
96
|
-
*
|
|
97
|
-
* 1. **Config mode** (default): Pass `publicKey` and config options to create a new instance.
|
|
98
|
-
* 2. **Client mode**: Pass an existing `client` instance for shared imperative + React usage.
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* ```tsx
|
|
102
|
-
* // Config mode — provider creates and owns the instance
|
|
103
|
-
* <OutlitProvider publicKey="pk_xxx" trackPageviews>
|
|
104
|
-
* {children}
|
|
105
|
-
* </OutlitProvider>
|
|
106
|
-
* ```
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* ```tsx
|
|
110
|
-
* // Client mode — use an existing instance
|
|
111
|
-
* const outlit = new Outlit({ publicKey: 'pk_xxx' })
|
|
112
|
-
* outlit.track('pageview') // imperative usage
|
|
113
|
-
*
|
|
114
|
-
* <OutlitProvider client={outlit} user={user}>
|
|
115
|
-
* {children}
|
|
116
|
-
* </OutlitProvider>
|
|
117
|
-
* ```
|
|
118
|
-
*/
|
|
119
|
-
declare function OutlitProvider(props: OutlitProviderProps): react_jsx_runtime.JSX.Element;
|
|
120
7
|
|
|
121
8
|
interface UseOutlitReturn {
|
|
122
9
|
/**
|
|
@@ -247,4 +134,117 @@ declare function useTrack(): (eventName: string, properties?: BrowserTrackOption
|
|
|
247
134
|
*/
|
|
248
135
|
declare function useIdentify(): (options: BrowserIdentifyOptions) => void;
|
|
249
136
|
|
|
137
|
+
interface OutlitContextValue {
|
|
138
|
+
outlit: Outlit | null;
|
|
139
|
+
isInitialized: boolean;
|
|
140
|
+
isTrackingEnabled: boolean;
|
|
141
|
+
enableTracking: () => void;
|
|
142
|
+
disableTracking: () => void;
|
|
143
|
+
}
|
|
144
|
+
declare const OutlitContext: react.Context<OutlitContextValue>;
|
|
145
|
+
interface OutlitProviderBaseProps {
|
|
146
|
+
children: ReactNode;
|
|
147
|
+
/**
|
|
148
|
+
* Current user identity.
|
|
149
|
+
* When provided with email or userId, calls setUser() to identify the user.
|
|
150
|
+
* When null, undefined, or missing identity fields, calls clearUser().
|
|
151
|
+
*
|
|
152
|
+
* This is the recommended way to handle user identity in server-rendered apps:
|
|
153
|
+
* pass the user from your auth system as a prop.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```tsx
|
|
157
|
+
* // Server component (layout.tsx)
|
|
158
|
+
* const session = await auth()
|
|
159
|
+
* return (
|
|
160
|
+
* <OutlitProvider
|
|
161
|
+
* publicKey="pk_xxx"
|
|
162
|
+
* user={session?.user ? { email: session.user.email, userId: session.user.id } : null}
|
|
163
|
+
* >
|
|
164
|
+
* {children}
|
|
165
|
+
* </OutlitProvider>
|
|
166
|
+
* )
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
user?: UserIdentity | null;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Props for using a pre-existing Outlit instance.
|
|
173
|
+
* The provider will use this instance directly without creating a new one.
|
|
174
|
+
* The caller owns the instance lifecycle — shutdown() will NOT be called on unmount.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```tsx
|
|
178
|
+
* import { Outlit } from '@outlit/browser'
|
|
179
|
+
* import { OutlitProvider } from '@outlit/browser/react'
|
|
180
|
+
*
|
|
181
|
+
* const outlit = new Outlit({ publicKey: 'pk_xxx', trackPageviews: false })
|
|
182
|
+
*
|
|
183
|
+
* function App() {
|
|
184
|
+
* const user = useAuth()
|
|
185
|
+
* return (
|
|
186
|
+
* <OutlitProvider client={outlit} user={user ? { email: user.email } : null}>
|
|
187
|
+
* {children}
|
|
188
|
+
* </OutlitProvider>
|
|
189
|
+
* )
|
|
190
|
+
* }
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
type NeverOutlitOptions = {
|
|
194
|
+
[K in keyof OutlitOptions]?: never;
|
|
195
|
+
};
|
|
196
|
+
interface OutlitProviderClientProps extends OutlitProviderBaseProps, NeverOutlitOptions {
|
|
197
|
+
/** An existing Outlit instance to use. Config props are ignored when this is provided. */
|
|
198
|
+
client: Outlit;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Props for creating a new Outlit instance internally.
|
|
202
|
+
* This is the default behavior — the provider creates and owns the instance.
|
|
203
|
+
*/
|
|
204
|
+
interface OutlitProviderConfigProps extends OutlitProviderBaseProps, Omit<OutlitOptions, "trackPageviews"> {
|
|
205
|
+
client?: never;
|
|
206
|
+
/**
|
|
207
|
+
* Whether to automatically track pageviews.
|
|
208
|
+
* When true (default), tracks pageviews on route changes.
|
|
209
|
+
*/
|
|
210
|
+
trackPageviews?: boolean;
|
|
211
|
+
/**
|
|
212
|
+
* Whether to start tracking automatically on mount.
|
|
213
|
+
* Set to false if you need to wait for user consent.
|
|
214
|
+
* Call enableTracking() (from useOutlit hook) after consent is obtained.
|
|
215
|
+
* @default true
|
|
216
|
+
*/
|
|
217
|
+
autoTrack?: boolean;
|
|
218
|
+
}
|
|
219
|
+
type OutlitProviderProps = OutlitProviderClientProps | OutlitProviderConfigProps;
|
|
220
|
+
/**
|
|
221
|
+
* Outlit Provider component.
|
|
222
|
+
* Initializes the client and provides it to child components via context.
|
|
223
|
+
*
|
|
224
|
+
* Can be used in two ways:
|
|
225
|
+
*
|
|
226
|
+
* 1. **Config mode** (default): Pass `publicKey` and config options to create a new instance.
|
|
227
|
+
* 2. **Client mode**: Pass an existing `client` instance for shared imperative + React usage.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```tsx
|
|
231
|
+
* // Config mode — provider creates and owns the instance
|
|
232
|
+
* <OutlitProvider publicKey="pk_xxx" trackPageviews>
|
|
233
|
+
* {children}
|
|
234
|
+
* </OutlitProvider>
|
|
235
|
+
* ```
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```tsx
|
|
239
|
+
* // Client mode — use an existing instance
|
|
240
|
+
* const outlit = new Outlit({ publicKey: 'pk_xxx' })
|
|
241
|
+
* outlit.track('pageview') // imperative usage
|
|
242
|
+
*
|
|
243
|
+
* <OutlitProvider client={outlit} user={user}>
|
|
244
|
+
* {children}
|
|
245
|
+
* </OutlitProvider>
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
declare function OutlitProvider(props: OutlitProviderProps): react_jsx_runtime.JSX.Element;
|
|
249
|
+
|
|
250
250
|
export { BillingOptions, OutlitContext, type OutlitContextValue, OutlitProvider, type OutlitProviderProps, type UseOutlitReturn, UserIdentity, useIdentify, useOutlit, useTrack };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,122 +1,9 @@
|
|
|
1
|
+
import { BrowserTrackOptions, BrowserIdentifyOptions } from '@outlit/core';
|
|
2
|
+
export { BrowserIdentifyOptions, BrowserTrackOptions, CustomerIdentifier, ExplicitJourneyStage, TrackerConfig } from '@outlit/core';
|
|
3
|
+
import { U as UserIdentity, B as BillingOptions, O as Outlit, h as OutlitOptions } from '../tracker-DlHUyaah.js';
|
|
1
4
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
5
|
import * as react from 'react';
|
|
3
6
|
import { ReactNode } from 'react';
|
|
4
|
-
import { O as Outlit, U as UserIdentity, h as OutlitOptions, B as BillingOptions } from '../tracker-CzhtZoOC.js';
|
|
5
|
-
import { BrowserTrackOptions, BrowserIdentifyOptions } from '@outlit/core';
|
|
6
|
-
export { BrowserIdentifyOptions, BrowserTrackOptions, CustomerIdentifier, ExplicitJourneyStage, TrackerConfig } from '@outlit/core';
|
|
7
|
-
|
|
8
|
-
interface OutlitContextValue {
|
|
9
|
-
outlit: Outlit | null;
|
|
10
|
-
isInitialized: boolean;
|
|
11
|
-
isTrackingEnabled: boolean;
|
|
12
|
-
enableTracking: () => void;
|
|
13
|
-
disableTracking: () => void;
|
|
14
|
-
}
|
|
15
|
-
declare const OutlitContext: react.Context<OutlitContextValue>;
|
|
16
|
-
interface OutlitProviderBaseProps {
|
|
17
|
-
children: ReactNode;
|
|
18
|
-
/**
|
|
19
|
-
* Current user identity.
|
|
20
|
-
* When provided with email or userId, calls setUser() to identify the user.
|
|
21
|
-
* When null, undefined, or missing identity fields, calls clearUser().
|
|
22
|
-
*
|
|
23
|
-
* This is the recommended way to handle user identity in server-rendered apps:
|
|
24
|
-
* pass the user from your auth system as a prop.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```tsx
|
|
28
|
-
* // Server component (layout.tsx)
|
|
29
|
-
* const session = await auth()
|
|
30
|
-
* return (
|
|
31
|
-
* <OutlitProvider
|
|
32
|
-
* publicKey="pk_xxx"
|
|
33
|
-
* user={session?.user ? { email: session.user.email, userId: session.user.id } : null}
|
|
34
|
-
* >
|
|
35
|
-
* {children}
|
|
36
|
-
* </OutlitProvider>
|
|
37
|
-
* )
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
user?: UserIdentity | null;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Props for using a pre-existing Outlit instance.
|
|
44
|
-
* The provider will use this instance directly without creating a new one.
|
|
45
|
-
* The caller owns the instance lifecycle — shutdown() will NOT be called on unmount.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```tsx
|
|
49
|
-
* import { Outlit } from '@outlit/browser'
|
|
50
|
-
* import { OutlitProvider } from '@outlit/browser/react'
|
|
51
|
-
*
|
|
52
|
-
* const outlit = new Outlit({ publicKey: 'pk_xxx', trackPageviews: false })
|
|
53
|
-
*
|
|
54
|
-
* function App() {
|
|
55
|
-
* const user = useAuth()
|
|
56
|
-
* return (
|
|
57
|
-
* <OutlitProvider client={outlit} user={user ? { email: user.email } : null}>
|
|
58
|
-
* {children}
|
|
59
|
-
* </OutlitProvider>
|
|
60
|
-
* )
|
|
61
|
-
* }
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
type NeverOutlitOptions = {
|
|
65
|
-
[K in keyof OutlitOptions]?: never;
|
|
66
|
-
};
|
|
67
|
-
interface OutlitProviderClientProps extends OutlitProviderBaseProps, NeverOutlitOptions {
|
|
68
|
-
/** An existing Outlit instance to use. Config props are ignored when this is provided. */
|
|
69
|
-
client: Outlit;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Props for creating a new Outlit instance internally.
|
|
73
|
-
* This is the default behavior — the provider creates and owns the instance.
|
|
74
|
-
*/
|
|
75
|
-
interface OutlitProviderConfigProps extends OutlitProviderBaseProps, Omit<OutlitOptions, "trackPageviews"> {
|
|
76
|
-
client?: never;
|
|
77
|
-
/**
|
|
78
|
-
* Whether to automatically track pageviews.
|
|
79
|
-
* When true (default), tracks pageviews on route changes.
|
|
80
|
-
*/
|
|
81
|
-
trackPageviews?: boolean;
|
|
82
|
-
/**
|
|
83
|
-
* Whether to start tracking automatically on mount.
|
|
84
|
-
* Set to false if you need to wait for user consent.
|
|
85
|
-
* Call enableTracking() (from useOutlit hook) after consent is obtained.
|
|
86
|
-
* @default true
|
|
87
|
-
*/
|
|
88
|
-
autoTrack?: boolean;
|
|
89
|
-
}
|
|
90
|
-
type OutlitProviderProps = OutlitProviderClientProps | OutlitProviderConfigProps;
|
|
91
|
-
/**
|
|
92
|
-
* Outlit Provider component.
|
|
93
|
-
* Initializes the client and provides it to child components via context.
|
|
94
|
-
*
|
|
95
|
-
* Can be used in two ways:
|
|
96
|
-
*
|
|
97
|
-
* 1. **Config mode** (default): Pass `publicKey` and config options to create a new instance.
|
|
98
|
-
* 2. **Client mode**: Pass an existing `client` instance for shared imperative + React usage.
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* ```tsx
|
|
102
|
-
* // Config mode — provider creates and owns the instance
|
|
103
|
-
* <OutlitProvider publicKey="pk_xxx" trackPageviews>
|
|
104
|
-
* {children}
|
|
105
|
-
* </OutlitProvider>
|
|
106
|
-
* ```
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* ```tsx
|
|
110
|
-
* // Client mode — use an existing instance
|
|
111
|
-
* const outlit = new Outlit({ publicKey: 'pk_xxx' })
|
|
112
|
-
* outlit.track('pageview') // imperative usage
|
|
113
|
-
*
|
|
114
|
-
* <OutlitProvider client={outlit} user={user}>
|
|
115
|
-
* {children}
|
|
116
|
-
* </OutlitProvider>
|
|
117
|
-
* ```
|
|
118
|
-
*/
|
|
119
|
-
declare function OutlitProvider(props: OutlitProviderProps): react_jsx_runtime.JSX.Element;
|
|
120
7
|
|
|
121
8
|
interface UseOutlitReturn {
|
|
122
9
|
/**
|
|
@@ -247,4 +134,117 @@ declare function useTrack(): (eventName: string, properties?: BrowserTrackOption
|
|
|
247
134
|
*/
|
|
248
135
|
declare function useIdentify(): (options: BrowserIdentifyOptions) => void;
|
|
249
136
|
|
|
137
|
+
interface OutlitContextValue {
|
|
138
|
+
outlit: Outlit | null;
|
|
139
|
+
isInitialized: boolean;
|
|
140
|
+
isTrackingEnabled: boolean;
|
|
141
|
+
enableTracking: () => void;
|
|
142
|
+
disableTracking: () => void;
|
|
143
|
+
}
|
|
144
|
+
declare const OutlitContext: react.Context<OutlitContextValue>;
|
|
145
|
+
interface OutlitProviderBaseProps {
|
|
146
|
+
children: ReactNode;
|
|
147
|
+
/**
|
|
148
|
+
* Current user identity.
|
|
149
|
+
* When provided with email or userId, calls setUser() to identify the user.
|
|
150
|
+
* When null, undefined, or missing identity fields, calls clearUser().
|
|
151
|
+
*
|
|
152
|
+
* This is the recommended way to handle user identity in server-rendered apps:
|
|
153
|
+
* pass the user from your auth system as a prop.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```tsx
|
|
157
|
+
* // Server component (layout.tsx)
|
|
158
|
+
* const session = await auth()
|
|
159
|
+
* return (
|
|
160
|
+
* <OutlitProvider
|
|
161
|
+
* publicKey="pk_xxx"
|
|
162
|
+
* user={session?.user ? { email: session.user.email, userId: session.user.id } : null}
|
|
163
|
+
* >
|
|
164
|
+
* {children}
|
|
165
|
+
* </OutlitProvider>
|
|
166
|
+
* )
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
user?: UserIdentity | null;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Props for using a pre-existing Outlit instance.
|
|
173
|
+
* The provider will use this instance directly without creating a new one.
|
|
174
|
+
* The caller owns the instance lifecycle — shutdown() will NOT be called on unmount.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```tsx
|
|
178
|
+
* import { Outlit } from '@outlit/browser'
|
|
179
|
+
* import { OutlitProvider } from '@outlit/browser/react'
|
|
180
|
+
*
|
|
181
|
+
* const outlit = new Outlit({ publicKey: 'pk_xxx', trackPageviews: false })
|
|
182
|
+
*
|
|
183
|
+
* function App() {
|
|
184
|
+
* const user = useAuth()
|
|
185
|
+
* return (
|
|
186
|
+
* <OutlitProvider client={outlit} user={user ? { email: user.email } : null}>
|
|
187
|
+
* {children}
|
|
188
|
+
* </OutlitProvider>
|
|
189
|
+
* )
|
|
190
|
+
* }
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
type NeverOutlitOptions = {
|
|
194
|
+
[K in keyof OutlitOptions]?: never;
|
|
195
|
+
};
|
|
196
|
+
interface OutlitProviderClientProps extends OutlitProviderBaseProps, NeverOutlitOptions {
|
|
197
|
+
/** An existing Outlit instance to use. Config props are ignored when this is provided. */
|
|
198
|
+
client: Outlit;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Props for creating a new Outlit instance internally.
|
|
202
|
+
* This is the default behavior — the provider creates and owns the instance.
|
|
203
|
+
*/
|
|
204
|
+
interface OutlitProviderConfigProps extends OutlitProviderBaseProps, Omit<OutlitOptions, "trackPageviews"> {
|
|
205
|
+
client?: never;
|
|
206
|
+
/**
|
|
207
|
+
* Whether to automatically track pageviews.
|
|
208
|
+
* When true (default), tracks pageviews on route changes.
|
|
209
|
+
*/
|
|
210
|
+
trackPageviews?: boolean;
|
|
211
|
+
/**
|
|
212
|
+
* Whether to start tracking automatically on mount.
|
|
213
|
+
* Set to false if you need to wait for user consent.
|
|
214
|
+
* Call enableTracking() (from useOutlit hook) after consent is obtained.
|
|
215
|
+
* @default true
|
|
216
|
+
*/
|
|
217
|
+
autoTrack?: boolean;
|
|
218
|
+
}
|
|
219
|
+
type OutlitProviderProps = OutlitProviderClientProps | OutlitProviderConfigProps;
|
|
220
|
+
/**
|
|
221
|
+
* Outlit Provider component.
|
|
222
|
+
* Initializes the client and provides it to child components via context.
|
|
223
|
+
*
|
|
224
|
+
* Can be used in two ways:
|
|
225
|
+
*
|
|
226
|
+
* 1. **Config mode** (default): Pass `publicKey` and config options to create a new instance.
|
|
227
|
+
* 2. **Client mode**: Pass an existing `client` instance for shared imperative + React usage.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```tsx
|
|
231
|
+
* // Config mode — provider creates and owns the instance
|
|
232
|
+
* <OutlitProvider publicKey="pk_xxx" trackPageviews>
|
|
233
|
+
* {children}
|
|
234
|
+
* </OutlitProvider>
|
|
235
|
+
* ```
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```tsx
|
|
239
|
+
* // Client mode — use an existing instance
|
|
240
|
+
* const outlit = new Outlit({ publicKey: 'pk_xxx' })
|
|
241
|
+
* outlit.track('pageview') // imperative usage
|
|
242
|
+
*
|
|
243
|
+
* <OutlitProvider client={outlit} user={user}>
|
|
244
|
+
* {children}
|
|
245
|
+
* </OutlitProvider>
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
declare function OutlitProvider(props: OutlitProviderProps): react_jsx_runtime.JSX.Element;
|
|
249
|
+
|
|
250
250
|
export { BillingOptions, OutlitContext, type OutlitContextValue, OutlitProvider, type OutlitProviderProps, type UseOutlitReturn, UserIdentity, useIdentify, useOutlit, useTrack };
|
package/dist/react/index.js
CHANGED
|
@@ -28,6 +28,9 @@ __export(react_exports, {
|
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(react_exports);
|
|
30
30
|
|
|
31
|
+
// src/react/hooks.ts
|
|
32
|
+
var import_react2 = require("react");
|
|
33
|
+
|
|
31
34
|
// src/react/provider.tsx
|
|
32
35
|
var import_react = require("react");
|
|
33
36
|
|
|
@@ -816,11 +819,19 @@ var Outlit = class {
|
|
|
816
819
|
console.warn("[Outlit] Tracking not enabled. Call enableTracking() first.");
|
|
817
820
|
return;
|
|
818
821
|
}
|
|
822
|
+
if (!options.email && !options.userId) {
|
|
823
|
+
console.warn("[Outlit] identify requires email or userId");
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
819
826
|
if (options.email || options.userId) {
|
|
820
827
|
const hadNoUser = !this.currentUser;
|
|
821
828
|
this.currentUser = {
|
|
822
829
|
email: options.email,
|
|
823
|
-
userId: options.userId
|
|
830
|
+
userId: options.userId,
|
|
831
|
+
customerId: options.customerId,
|
|
832
|
+
customerDomain: options.customerDomain,
|
|
833
|
+
customerTraits: options.customerTraits,
|
|
834
|
+
traits: options.traits
|
|
824
835
|
};
|
|
825
836
|
if (hadNoUser) {
|
|
826
837
|
this.flushPendingStageEvents();
|
|
@@ -831,6 +842,9 @@ var Outlit = class {
|
|
|
831
842
|
referrer: document.referrer,
|
|
832
843
|
email: options.email,
|
|
833
844
|
userId: options.userId,
|
|
845
|
+
customerId: options.customerId,
|
|
846
|
+
customerDomain: options.customerDomain,
|
|
847
|
+
customerTraits: options.customerTraits,
|
|
834
848
|
traits: options.traits
|
|
835
849
|
});
|
|
836
850
|
this.enqueue(event);
|
|
@@ -872,7 +886,14 @@ var Outlit = class {
|
|
|
872
886
|
*/
|
|
873
887
|
applyUser(identity) {
|
|
874
888
|
this.currentUser = identity;
|
|
875
|
-
this.identify({
|
|
889
|
+
this.identify({
|
|
890
|
+
email: identity.email,
|
|
891
|
+
userId: identity.userId,
|
|
892
|
+
traits: identity.traits,
|
|
893
|
+
customerId: identity.customerId,
|
|
894
|
+
customerDomain: identity.customerDomain,
|
|
895
|
+
customerTraits: identity.customerTraits
|
|
896
|
+
});
|
|
876
897
|
this.flushPendingStageEvents();
|
|
877
898
|
}
|
|
878
899
|
/**
|
|
@@ -940,11 +961,23 @@ var Outlit = class {
|
|
|
940
961
|
console.warn("[Outlit] Tracking not enabled. Call enableTracking() first.");
|
|
941
962
|
return;
|
|
942
963
|
}
|
|
964
|
+
try {
|
|
965
|
+
(0, import_core3.validateCustomerIdentity)(
|
|
966
|
+
options.customerId,
|
|
967
|
+
options.customerDomain,
|
|
968
|
+
options.domain,
|
|
969
|
+
options.stripeCustomerId
|
|
970
|
+
);
|
|
971
|
+
} catch (error) {
|
|
972
|
+
console.warn("[Outlit]", error instanceof Error ? error.message : error);
|
|
973
|
+
return;
|
|
974
|
+
}
|
|
943
975
|
const event = (0, import_core3.buildBillingEvent)({
|
|
944
976
|
url: window.location.href,
|
|
945
977
|
referrer: document.referrer,
|
|
946
978
|
status,
|
|
947
979
|
customerId: options.customerId,
|
|
980
|
+
customerDomain: options.customerDomain,
|
|
948
981
|
stripeCustomerId: options.stripeCustomerId,
|
|
949
982
|
domain: options.domain,
|
|
950
983
|
properties: options.properties
|
|
@@ -1062,12 +1095,47 @@ var Outlit = class {
|
|
|
1062
1095
|
this.flush();
|
|
1063
1096
|
}, this.flushInterval);
|
|
1064
1097
|
}
|
|
1098
|
+
getPayloadUserIdentity() {
|
|
1099
|
+
if (!this.currentUser) {
|
|
1100
|
+
return void 0;
|
|
1101
|
+
}
|
|
1102
|
+
const { email, userId } = this.currentUser;
|
|
1103
|
+
if (!email && !userId) {
|
|
1104
|
+
return void 0;
|
|
1105
|
+
}
|
|
1106
|
+
return {
|
|
1107
|
+
...email && { email },
|
|
1108
|
+
...userId && { userId }
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
getPayloadCustomerIdentity() {
|
|
1112
|
+
if (!this.currentUser) {
|
|
1113
|
+
return void 0;
|
|
1114
|
+
}
|
|
1115
|
+
const { customerId, customerDomain } = this.currentUser;
|
|
1116
|
+
if (!customerId && !customerDomain) {
|
|
1117
|
+
return void 0;
|
|
1118
|
+
}
|
|
1119
|
+
return {
|
|
1120
|
+
...customerId && { customerId },
|
|
1121
|
+
...customerDomain && { customerDomain }
|
|
1122
|
+
};
|
|
1123
|
+
}
|
|
1065
1124
|
async sendEvents(events) {
|
|
1066
1125
|
if (events.length === 0) return;
|
|
1067
1126
|
if (!this.visitorId) return;
|
|
1068
|
-
const userIdentity = this.
|
|
1127
|
+
const userIdentity = this.getPayloadUserIdentity();
|
|
1128
|
+
const customerIdentity = this.getPayloadCustomerIdentity();
|
|
1069
1129
|
const sessionId = this.sessionTracker?.getSessionId();
|
|
1070
|
-
const payload = (0, import_core3.buildIngestPayload)(
|
|
1130
|
+
const payload = (0, import_core3.buildIngestPayload)(
|
|
1131
|
+
this.visitorId,
|
|
1132
|
+
"client",
|
|
1133
|
+
events,
|
|
1134
|
+
userIdentity,
|
|
1135
|
+
sessionId,
|
|
1136
|
+
void 0,
|
|
1137
|
+
customerIdentity
|
|
1138
|
+
);
|
|
1071
1139
|
const url = `${this.apiHost}/api/i/v1/${this.publicKey}/events`;
|
|
1072
1140
|
try {
|
|
1073
1141
|
if (typeof navigator !== "undefined" && navigator.sendBeacon) {
|
|
@@ -1216,7 +1284,6 @@ function OutlitProvider(props) {
|
|
|
1216
1284
|
}
|
|
1217
1285
|
|
|
1218
1286
|
// src/react/hooks.ts
|
|
1219
|
-
var import_react2 = require("react");
|
|
1220
1287
|
function useOutlit() {
|
|
1221
1288
|
const { outlit, isInitialized, isTrackingEnabled, enableTracking, disableTracking } = (0, import_react2.useContext)(OutlitContext);
|
|
1222
1289
|
const track = (0, import_react2.useCallback)(
|