@outlit/browser 1.4.3 → 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.
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +59 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -7
- 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 +62 -6
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +65 -8
- 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 +62 -6
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/index.mjs +65 -8
- 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,18 @@ 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
|
+
customerTraits: options.customerTraits,
|
|
833
|
+
traits: options.traits
|
|
824
834
|
};
|
|
825
835
|
if (hadNoUser) {
|
|
826
836
|
this.flushPendingStageEvents();
|
|
@@ -831,6 +841,8 @@ var Outlit = class {
|
|
|
831
841
|
referrer: document.referrer,
|
|
832
842
|
email: options.email,
|
|
833
843
|
userId: options.userId,
|
|
844
|
+
customerId: options.customerId,
|
|
845
|
+
customerTraits: options.customerTraits,
|
|
834
846
|
traits: options.traits
|
|
835
847
|
});
|
|
836
848
|
this.enqueue(event);
|
|
@@ -872,7 +884,13 @@ var Outlit = class {
|
|
|
872
884
|
*/
|
|
873
885
|
applyUser(identity) {
|
|
874
886
|
this.currentUser = identity;
|
|
875
|
-
this.identify({
|
|
887
|
+
this.identify({
|
|
888
|
+
email: identity.email,
|
|
889
|
+
userId: identity.userId,
|
|
890
|
+
traits: identity.traits,
|
|
891
|
+
customerId: identity.customerId,
|
|
892
|
+
customerTraits: identity.customerTraits
|
|
893
|
+
});
|
|
876
894
|
this.flushPendingStageEvents();
|
|
877
895
|
}
|
|
878
896
|
/**
|
|
@@ -940,13 +958,18 @@ var Outlit = class {
|
|
|
940
958
|
console.warn("[Outlit] Tracking not enabled. Call enableTracking() first.");
|
|
941
959
|
return;
|
|
942
960
|
}
|
|
961
|
+
try {
|
|
962
|
+
(0, import_core3.validateCustomerIdentity)(options.customerId, options.stripeCustomerId);
|
|
963
|
+
} catch (error) {
|
|
964
|
+
console.warn("[Outlit]", error instanceof Error ? error.message : error);
|
|
965
|
+
return;
|
|
966
|
+
}
|
|
943
967
|
const event = (0, import_core3.buildBillingEvent)({
|
|
944
968
|
url: window.location.href,
|
|
945
969
|
referrer: document.referrer,
|
|
946
970
|
status,
|
|
947
971
|
customerId: options.customerId,
|
|
948
972
|
stripeCustomerId: options.stripeCustomerId,
|
|
949
|
-
domain: options.domain,
|
|
950
973
|
properties: options.properties
|
|
951
974
|
});
|
|
952
975
|
this.enqueue(event);
|
|
@@ -1062,12 +1085,46 @@ var Outlit = class {
|
|
|
1062
1085
|
this.flush();
|
|
1063
1086
|
}, this.flushInterval);
|
|
1064
1087
|
}
|
|
1088
|
+
getPayloadUserIdentity() {
|
|
1089
|
+
if (!this.currentUser) {
|
|
1090
|
+
return void 0;
|
|
1091
|
+
}
|
|
1092
|
+
const { email, userId } = this.currentUser;
|
|
1093
|
+
if (!email && !userId) {
|
|
1094
|
+
return void 0;
|
|
1095
|
+
}
|
|
1096
|
+
return {
|
|
1097
|
+
...email && { email },
|
|
1098
|
+
...userId && { userId }
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
getPayloadCustomerIdentity() {
|
|
1102
|
+
if (!this.currentUser) {
|
|
1103
|
+
return void 0;
|
|
1104
|
+
}
|
|
1105
|
+
const { customerId } = this.currentUser;
|
|
1106
|
+
if (!customerId) {
|
|
1107
|
+
return void 0;
|
|
1108
|
+
}
|
|
1109
|
+
return {
|
|
1110
|
+
...customerId && { customerId }
|
|
1111
|
+
};
|
|
1112
|
+
}
|
|
1065
1113
|
async sendEvents(events) {
|
|
1066
1114
|
if (events.length === 0) return;
|
|
1067
1115
|
if (!this.visitorId) return;
|
|
1068
|
-
const userIdentity = this.
|
|
1116
|
+
const userIdentity = this.getPayloadUserIdentity();
|
|
1117
|
+
const customerIdentity = this.getPayloadCustomerIdentity();
|
|
1069
1118
|
const sessionId = this.sessionTracker?.getSessionId();
|
|
1070
|
-
const payload = (0, import_core3.buildIngestPayload)(
|
|
1119
|
+
const payload = (0, import_core3.buildIngestPayload)(
|
|
1120
|
+
this.visitorId,
|
|
1121
|
+
"client",
|
|
1122
|
+
events,
|
|
1123
|
+
userIdentity,
|
|
1124
|
+
sessionId,
|
|
1125
|
+
void 0,
|
|
1126
|
+
customerIdentity
|
|
1127
|
+
);
|
|
1071
1128
|
const url = `${this.apiHost}/api/i/v1/${this.publicKey}/events`;
|
|
1072
1129
|
try {
|
|
1073
1130
|
if (typeof navigator !== "undefined" && navigator.sendBeacon) {
|
|
@@ -1216,7 +1273,6 @@ function OutlitProvider(props) {
|
|
|
1216
1273
|
}
|
|
1217
1274
|
|
|
1218
1275
|
// src/react/hooks.ts
|
|
1219
|
-
var import_react2 = require("react");
|
|
1220
1276
|
function useOutlit() {
|
|
1221
1277
|
const { outlit, isInitialized, isTrackingEnabled, enableTracking, disableTracking } = (0, import_react2.useContext)(OutlitContext);
|
|
1222
1278
|
const track = (0, import_react2.useCallback)(
|