@databuddy/sdk 2.3.29 → 2.4.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/README.md +1 -2
- package/dist/core/index.d.mts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.mjs +1 -1
- package/dist/node/index.d.mts +34 -80
- package/dist/node/index.d.ts +34 -80
- package/dist/node/index.mjs +12 -244
- package/dist/react/index.d.mts +4 -47
- package/dist/react/index.d.ts +4 -47
- package/dist/react/index.mjs +21 -103
- package/dist/shared/@databuddy/{sdk.BsF1xr6_.d.ts → sdk.DOtKE9NQ.d.mts} +7 -13
- package/dist/shared/@databuddy/{sdk.BsF1xr6_.d.mts → sdk.DOtKE9NQ.d.ts} +7 -13
- package/dist/shared/@databuddy/sdk.GM10R1Kp.mjs +46 -0
- package/dist/shared/@databuddy/{sdk.urY7MmVr.mjs → sdk.P9GHqNXr.mjs} +1 -1
- package/dist/shared/@databuddy/sdk.Ugr1p2j9.mjs +601 -0
- package/dist/shared/@databuddy/sdk.rnu91OSC.d.mts +81 -0
- package/dist/shared/@databuddy/sdk.rnu91OSC.d.ts +81 -0
- package/dist/vue/index.d.mts +8 -28
- package/dist/vue/index.d.ts +8 -28
- package/dist/vue/index.mjs +29 -65
- package/package.json +8 -23
- package/dist/ai/vercel/index.d.mts +0 -236
- package/dist/ai/vercel/index.d.ts +0 -236
- package/dist/ai/vercel/index.mjs +0 -708
- package/dist/shared/@databuddy/sdk.CALvx07o.mjs +0 -208
- package/dist/shared/@databuddy/sdk.CdLp6SQb.d.mts +0 -132
- package/dist/shared/@databuddy/sdk.CdLp6SQb.d.ts +0 -132
- package/dist/shared/@databuddy/sdk.DE24-JrU.mjs +0 -559
package/dist/react/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { D as DatabuddyConfig } from '../shared/@databuddy/sdk.
|
|
2
|
-
export {
|
|
1
|
+
import { D as DatabuddyConfig } from '../shared/@databuddy/sdk.DOtKE9NQ.mjs';
|
|
2
|
+
export { f as clear, g as flush, h as getAnonymousId, i as getSessionId, j as getTracker, k as getTrackingIds, l as getTrackingParams, m as isTrackerAvailable, t as track, o as trackError } from '../shared/@databuddy/sdk.DOtKE9NQ.mjs';
|
|
3
3
|
import React, { ReactNode } from 'react';
|
|
4
|
-
import { F as FlagsConfig, a as
|
|
4
|
+
import { F as FlagsConfig, a as FlagState, b as FlagsContext } from '../shared/@databuddy/sdk.rnu91OSC.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* React/Next.js component that injects the Databuddy tracking script.
|
|
@@ -38,7 +38,6 @@ import { F as FlagsConfig, a as FeatureState, b as FlagState, c as FlagsContext
|
|
|
38
38
|
* <Databuddy
|
|
39
39
|
* clientId="your-client-id"
|
|
40
40
|
* trackWebVitals
|
|
41
|
-
* trackScrollDepth
|
|
42
41
|
* trackOutgoingLinks
|
|
43
42
|
* />
|
|
44
43
|
* ```
|
|
@@ -59,56 +58,14 @@ declare function Databuddy(props: DatabuddyConfig): null;
|
|
|
59
58
|
interface FlagsProviderProps extends FlagsConfig {
|
|
60
59
|
children: ReactNode;
|
|
61
60
|
}
|
|
62
|
-
/**
|
|
63
|
-
* Flags provider component
|
|
64
|
-
* Creates a manager instance and provides flag methods to children
|
|
65
|
-
*/
|
|
66
61
|
declare function FlagsProvider({ children, ...config }: FlagsProviderProps): React.JSX.Element;
|
|
67
|
-
/**
|
|
68
|
-
* Access the full flags context
|
|
69
|
-
* @example
|
|
70
|
-
* const { isOn, getFlag, refresh } = useFlags();
|
|
71
|
-
*/
|
|
72
62
|
declare function useFlags(): FlagsContext;
|
|
73
63
|
/**
|
|
74
|
-
* Get a flag's full state with loading/error handling
|
|
75
64
|
* @example
|
|
76
65
|
* const flag = useFlag("my-feature");
|
|
77
66
|
* if (flag.loading) return <Skeleton />;
|
|
78
67
|
* return flag.on ? <NewFeature /> : <OldFeature />;
|
|
79
68
|
*/
|
|
80
69
|
declare function useFlag(key: string): FlagState;
|
|
81
|
-
/**
|
|
82
|
-
* Simple feature check - returns { on, loading, value, variant }
|
|
83
|
-
* @example
|
|
84
|
-
* const { on, loading } = useFeature("dark-mode");
|
|
85
|
-
* if (loading) return <Skeleton />;
|
|
86
|
-
* return on ? <DarkTheme /> : <LightTheme />;
|
|
87
|
-
*/
|
|
88
|
-
declare function useFeature(key: string): FeatureState;
|
|
89
|
-
/**
|
|
90
|
-
* Boolean-only feature check with default value
|
|
91
|
-
* Useful for SSR-safe rendering where you need a boolean immediately
|
|
92
|
-
* @example
|
|
93
|
-
* const isDarkMode = useFeatureOn("dark-mode", false);
|
|
94
|
-
* return isDarkMode ? <DarkTheme /> : <LightTheme />;
|
|
95
|
-
*/
|
|
96
|
-
declare function useFeatureOn(key: string, defaultValue?: boolean): boolean;
|
|
97
|
-
/**
|
|
98
|
-
* Get a flag's typed value
|
|
99
|
-
* @example
|
|
100
|
-
* const maxItems = useFlagValue("max-items", 10);
|
|
101
|
-
* const theme = useFlagValue<"light" | "dark">("theme", "light");
|
|
102
|
-
*/
|
|
103
|
-
declare function useFlagValue<T extends boolean | string | number = boolean>(key: string, defaultValue?: T): T;
|
|
104
|
-
/**
|
|
105
|
-
* Get variant for A/B testing
|
|
106
|
-
* @example
|
|
107
|
-
* const variant = useVariant("checkout-experiment");
|
|
108
|
-
* if (variant === "control") return <OldCheckout />;
|
|
109
|
-
* if (variant === "treatment-a") return <NewCheckoutA />;
|
|
110
|
-
* return <NewCheckoutB />;
|
|
111
|
-
*/
|
|
112
|
-
declare function useVariant(key: string): string | undefined;
|
|
113
70
|
|
|
114
|
-
export { Databuddy, FlagsProvider,
|
|
71
|
+
export { Databuddy, FlagsProvider, useFlag, useFlags };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { D as DatabuddyConfig } from '../shared/@databuddy/sdk.
|
|
2
|
-
export {
|
|
1
|
+
import { D as DatabuddyConfig } from '../shared/@databuddy/sdk.DOtKE9NQ.js';
|
|
2
|
+
export { f as clear, g as flush, h as getAnonymousId, i as getSessionId, j as getTracker, k as getTrackingIds, l as getTrackingParams, m as isTrackerAvailable, t as track, o as trackError } from '../shared/@databuddy/sdk.DOtKE9NQ.js';
|
|
3
3
|
import React, { ReactNode } from 'react';
|
|
4
|
-
import { F as FlagsConfig, a as
|
|
4
|
+
import { F as FlagsConfig, a as FlagState, b as FlagsContext } from '../shared/@databuddy/sdk.rnu91OSC.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* React/Next.js component that injects the Databuddy tracking script.
|
|
@@ -38,7 +38,6 @@ import { F as FlagsConfig, a as FeatureState, b as FlagState, c as FlagsContext
|
|
|
38
38
|
* <Databuddy
|
|
39
39
|
* clientId="your-client-id"
|
|
40
40
|
* trackWebVitals
|
|
41
|
-
* trackScrollDepth
|
|
42
41
|
* trackOutgoingLinks
|
|
43
42
|
* />
|
|
44
43
|
* ```
|
|
@@ -59,56 +58,14 @@ declare function Databuddy(props: DatabuddyConfig): null;
|
|
|
59
58
|
interface FlagsProviderProps extends FlagsConfig {
|
|
60
59
|
children: ReactNode;
|
|
61
60
|
}
|
|
62
|
-
/**
|
|
63
|
-
* Flags provider component
|
|
64
|
-
* Creates a manager instance and provides flag methods to children
|
|
65
|
-
*/
|
|
66
61
|
declare function FlagsProvider({ children, ...config }: FlagsProviderProps): React.JSX.Element;
|
|
67
|
-
/**
|
|
68
|
-
* Access the full flags context
|
|
69
|
-
* @example
|
|
70
|
-
* const { isOn, getFlag, refresh } = useFlags();
|
|
71
|
-
*/
|
|
72
62
|
declare function useFlags(): FlagsContext;
|
|
73
63
|
/**
|
|
74
|
-
* Get a flag's full state with loading/error handling
|
|
75
64
|
* @example
|
|
76
65
|
* const flag = useFlag("my-feature");
|
|
77
66
|
* if (flag.loading) return <Skeleton />;
|
|
78
67
|
* return flag.on ? <NewFeature /> : <OldFeature />;
|
|
79
68
|
*/
|
|
80
69
|
declare function useFlag(key: string): FlagState;
|
|
81
|
-
/**
|
|
82
|
-
* Simple feature check - returns { on, loading, value, variant }
|
|
83
|
-
* @example
|
|
84
|
-
* const { on, loading } = useFeature("dark-mode");
|
|
85
|
-
* if (loading) return <Skeleton />;
|
|
86
|
-
* return on ? <DarkTheme /> : <LightTheme />;
|
|
87
|
-
*/
|
|
88
|
-
declare function useFeature(key: string): FeatureState;
|
|
89
|
-
/**
|
|
90
|
-
* Boolean-only feature check with default value
|
|
91
|
-
* Useful for SSR-safe rendering where you need a boolean immediately
|
|
92
|
-
* @example
|
|
93
|
-
* const isDarkMode = useFeatureOn("dark-mode", false);
|
|
94
|
-
* return isDarkMode ? <DarkTheme /> : <LightTheme />;
|
|
95
|
-
*/
|
|
96
|
-
declare function useFeatureOn(key: string, defaultValue?: boolean): boolean;
|
|
97
|
-
/**
|
|
98
|
-
* Get a flag's typed value
|
|
99
|
-
* @example
|
|
100
|
-
* const maxItems = useFlagValue("max-items", 10);
|
|
101
|
-
* const theme = useFlagValue<"light" | "dark">("theme", "light");
|
|
102
|
-
*/
|
|
103
|
-
declare function useFlagValue<T extends boolean | string | number = boolean>(key: string, defaultValue?: T): T;
|
|
104
|
-
/**
|
|
105
|
-
* Get variant for A/B testing
|
|
106
|
-
* @example
|
|
107
|
-
* const variant = useVariant("checkout-experiment");
|
|
108
|
-
* if (variant === "control") return <OldCheckout />;
|
|
109
|
-
* if (variant === "treatment-a") return <NewCheckoutA />;
|
|
110
|
-
* return <NewCheckoutB />;
|
|
111
|
-
*/
|
|
112
|
-
declare function useVariant(key: string): string | undefined;
|
|
113
70
|
|
|
114
|
-
export { Databuddy, FlagsProvider,
|
|
71
|
+
export { Databuddy, FlagsProvider, useFlag, useFlags };
|
package/dist/react/index.mjs
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import { detectClientId } from '../core/index.mjs';
|
|
4
4
|
export { clear, flush, getAnonymousId, getSessionId, getTracker, getTrackingIds, getTrackingParams, isTrackerAvailable, track, trackError } from '../core/index.mjs';
|
|
5
|
-
import { i as isScriptInjected, c as createScript } from '../shared/@databuddy/sdk.
|
|
6
|
-
import React, {
|
|
7
|
-
import { B as BrowserFlagStorage
|
|
8
|
-
import { l as logger } from '../shared/@databuddy/sdk.
|
|
5
|
+
import { i as isScriptInjected, c as createScript } from '../shared/@databuddy/sdk.P9GHqNXr.mjs';
|
|
6
|
+
import React, { useMemo, useRef, useEffect, useSyncExternalStore, useContext, createContext } from 'react';
|
|
7
|
+
import { B as BrowserFlagStorage } from '../shared/@databuddy/sdk.GM10R1Kp.mjs';
|
|
8
|
+
import { B as BrowserFlagsManager, l as logger } from '../shared/@databuddy/sdk.Ugr1p2j9.mjs';
|
|
9
9
|
|
|
10
10
|
function Databuddy(props) {
|
|
11
11
|
const clientId = detectClientId(props.clientId);
|
|
@@ -25,66 +25,32 @@ function Databuddy(props) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
const FlagsReactContext = createContext(null);
|
|
28
|
-
function
|
|
28
|
+
function toFlagState(result, isLoading, isPending) {
|
|
29
29
|
if (isPending) {
|
|
30
|
-
return {
|
|
31
|
-
on: false,
|
|
32
|
-
enabled: false,
|
|
33
|
-
status: "pending",
|
|
34
|
-
loading: true,
|
|
35
|
-
isLoading: true,
|
|
36
|
-
isReady: false
|
|
37
|
-
};
|
|
30
|
+
return { on: false, status: "pending", loading: true };
|
|
38
31
|
}
|
|
39
32
|
if (isLoading || !result) {
|
|
40
|
-
return {
|
|
41
|
-
on: false,
|
|
42
|
-
enabled: false,
|
|
43
|
-
status: "loading",
|
|
44
|
-
loading: true,
|
|
45
|
-
isLoading: true,
|
|
46
|
-
isReady: false
|
|
47
|
-
};
|
|
33
|
+
return { on: false, status: "loading", loading: true };
|
|
48
34
|
}
|
|
49
35
|
const status = result.reason === "ERROR" ? "error" : "ready";
|
|
50
36
|
return {
|
|
51
37
|
on: result.enabled,
|
|
52
|
-
enabled: result.enabled,
|
|
53
38
|
status,
|
|
54
39
|
loading: false,
|
|
55
|
-
isLoading: false,
|
|
56
|
-
isReady: true,
|
|
57
40
|
value: result.value,
|
|
58
41
|
variant: result.variant
|
|
59
42
|
};
|
|
60
43
|
}
|
|
61
44
|
function FlagsProvider({ children, ...config }) {
|
|
62
|
-
const storeRef = useRef({ flags: {}, isReady: false });
|
|
63
|
-
const listenersRef = useRef(/* @__PURE__ */ new Set());
|
|
64
45
|
const manager = useMemo(() => {
|
|
65
46
|
const storage = config.skipStorage ? void 0 : new BrowserFlagStorage();
|
|
66
|
-
return new
|
|
67
|
-
config,
|
|
68
|
-
storage,
|
|
69
|
-
onFlagsUpdate: (flags) => {
|
|
70
|
-
storeRef.current = { ...storeRef.current, flags };
|
|
71
|
-
for (const listener of listenersRef.current) {
|
|
72
|
-
listener();
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
onReady: () => {
|
|
76
|
-
storeRef.current = { ...storeRef.current, isReady: true };
|
|
77
|
-
for (const listener of listenersRef.current) {
|
|
78
|
-
listener();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
});
|
|
47
|
+
return new BrowserFlagsManager({ config, storage });
|
|
82
48
|
}, [config.clientId]);
|
|
83
49
|
const prevConfigRef = useRef(config);
|
|
84
50
|
useEffect(() => {
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
if (
|
|
51
|
+
const prev = prevConfigRef.current;
|
|
52
|
+
const changed = prev.apiUrl !== config.apiUrl || prev.isPending !== config.isPending || prev.user?.userId !== config.user?.userId || prev.user?.email !== config.user?.email || prev.environment !== config.environment || prev.disabled !== config.disabled || prev.autoFetch !== config.autoFetch || prev.cacheTtl !== config.cacheTtl || prev.staleTime !== config.staleTime;
|
|
53
|
+
if (changed) {
|
|
88
54
|
prevConfigRef.current = config;
|
|
89
55
|
manager.updateConfig(config);
|
|
90
56
|
}
|
|
@@ -94,39 +60,29 @@ function FlagsProvider({ children, ...config }) {
|
|
|
94
60
|
manager.destroy();
|
|
95
61
|
};
|
|
96
62
|
}, [manager]);
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
listenersRef.current.delete(callback);
|
|
102
|
-
};
|
|
103
|
-
},
|
|
104
|
-
[]
|
|
63
|
+
const store = useSyncExternalStore(
|
|
64
|
+
manager.subscribe,
|
|
65
|
+
manager.getSnapshot,
|
|
66
|
+
manager.getSnapshot
|
|
105
67
|
);
|
|
106
|
-
const getSnapshot = useMemo(() => () => storeRef.current, []);
|
|
107
|
-
const store = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
108
68
|
const contextValue = useMemo(
|
|
109
69
|
() => ({
|
|
110
|
-
// Cleaner API: getFlag returns FlagState
|
|
111
70
|
getFlag: (key) => {
|
|
112
71
|
const result = store.flags[key];
|
|
113
72
|
const managerState = manager.isEnabled(key);
|
|
114
|
-
return
|
|
73
|
+
return toFlagState(
|
|
115
74
|
result,
|
|
116
|
-
managerState.
|
|
75
|
+
managerState.loading,
|
|
117
76
|
config.isPending ?? false
|
|
118
77
|
);
|
|
119
78
|
},
|
|
120
|
-
// Simple boolean check
|
|
121
79
|
isOn: (key) => {
|
|
122
80
|
const result = store.flags[key];
|
|
123
81
|
if (result) {
|
|
124
82
|
return result.enabled;
|
|
125
83
|
}
|
|
126
|
-
|
|
127
|
-
return state.enabled;
|
|
84
|
+
return manager.isEnabled(key).on;
|
|
128
85
|
},
|
|
129
|
-
// Get typed value
|
|
130
86
|
getValue: (key, defaultValue) => {
|
|
131
87
|
const result = store.flags[key];
|
|
132
88
|
if (result) {
|
|
@@ -134,22 +90,11 @@ function FlagsProvider({ children, ...config }) {
|
|
|
134
90
|
}
|
|
135
91
|
return manager.getValue(key, defaultValue);
|
|
136
92
|
},
|
|
137
|
-
// Async fetch
|
|
138
93
|
fetchFlag: (key) => manager.getFlag(key),
|
|
139
94
|
fetchAllFlags: () => manager.fetchAllFlags(),
|
|
140
95
|
updateUser: (user) => manager.updateUser(user),
|
|
141
96
|
refresh: (forceClear = false) => manager.refresh(forceClear),
|
|
142
|
-
isReady: store.isReady
|
|
143
|
-
// Deprecated: kept for backwards compatibility
|
|
144
|
-
isEnabled: (key) => {
|
|
145
|
-
const result = store.flags[key];
|
|
146
|
-
const managerState = manager.isEnabled(key);
|
|
147
|
-
return createFlagState(
|
|
148
|
-
result,
|
|
149
|
-
managerState.isLoading,
|
|
150
|
-
config.isPending ?? false
|
|
151
|
-
);
|
|
152
|
-
}
|
|
97
|
+
isReady: store.isReady
|
|
153
98
|
}),
|
|
154
99
|
[manager, store, config.isPending]
|
|
155
100
|
);
|
|
@@ -160,8 +105,7 @@ function useFlags() {
|
|
|
160
105
|
if (!context) {
|
|
161
106
|
logger.warn("useFlags called outside FlagsProvider");
|
|
162
107
|
return {
|
|
163
|
-
|
|
164
|
-
getFlag: () => createFlagState(void 0, false, false),
|
|
108
|
+
getFlag: () => toFlagState(void 0, false, false),
|
|
165
109
|
isOn: () => false,
|
|
166
110
|
getValue: (_key, defaultValue) => defaultValue ?? false,
|
|
167
111
|
fetchFlag: async () => ({
|
|
@@ -185,31 +129,5 @@ function useFlag(key) {
|
|
|
185
129
|
const { getFlag } = useFlags();
|
|
186
130
|
return getFlag(key);
|
|
187
131
|
}
|
|
188
|
-
function useFeature(key) {
|
|
189
|
-
const flag = useFlag(key);
|
|
190
|
-
return {
|
|
191
|
-
on: flag.on,
|
|
192
|
-
loading: flag.loading,
|
|
193
|
-
status: flag.status,
|
|
194
|
-
value: flag.value,
|
|
195
|
-
variant: flag.variant
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
function useFeatureOn(key, defaultValue = false) {
|
|
199
|
-
const { isOn, isReady } = useFlags();
|
|
200
|
-
const flag = useFlag(key);
|
|
201
|
-
if (flag.loading || !isReady) {
|
|
202
|
-
return defaultValue;
|
|
203
|
-
}
|
|
204
|
-
return isOn(key);
|
|
205
|
-
}
|
|
206
|
-
function useFlagValue(key, defaultValue) {
|
|
207
|
-
const { getValue } = useFlags();
|
|
208
|
-
return getValue(key, defaultValue);
|
|
209
|
-
}
|
|
210
|
-
function useVariant(key) {
|
|
211
|
-
const flag = useFlag(key);
|
|
212
|
-
return flag.variant;
|
|
213
|
-
}
|
|
214
132
|
|
|
215
|
-
export { Databuddy, FlagsProvider,
|
|
133
|
+
export { Databuddy, FlagsProvider, useFlag, useFlags };
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
* apiUrl="https://basket.databuddy.cc"
|
|
9
9
|
* trackWebVitals
|
|
10
10
|
* trackErrors
|
|
11
|
-
* trackScrollDepth
|
|
12
11
|
* samplingRate={0.5}
|
|
13
12
|
* />
|
|
14
13
|
* ```
|
|
@@ -18,7 +17,7 @@ interface DatabuddyConfig {
|
|
|
18
17
|
* Your Databuddy project client ID.
|
|
19
18
|
* If not provided, will automatically detect from NEXT_PUBLIC_DATABUDDY_CLIENT_ID environment variable.
|
|
20
19
|
* Get this from your Databuddy dashboard.
|
|
21
|
-
* Example:
|
|
20
|
+
* Example: UUID-style or short public id (dashboard client ID).
|
|
22
21
|
*/
|
|
23
22
|
clientId?: string;
|
|
24
23
|
/**
|
|
@@ -71,10 +70,6 @@ interface DatabuddyConfig {
|
|
|
71
70
|
* Track user interactions (default: false).
|
|
72
71
|
*/
|
|
73
72
|
trackInteractions?: boolean;
|
|
74
|
-
/**
|
|
75
|
-
* Track scroll depth (default: false).
|
|
76
|
-
*/
|
|
77
|
-
trackScrollDepth?: boolean;
|
|
78
73
|
/**
|
|
79
74
|
* Track page performance metrics (default: true).
|
|
80
75
|
*/
|
|
@@ -93,7 +88,7 @@ interface DatabuddyConfig {
|
|
|
93
88
|
*/
|
|
94
89
|
samplingRate?: number;
|
|
95
90
|
/**
|
|
96
|
-
* Enable retries for failed requests (default:
|
|
91
|
+
* Enable retries for failed requests (default: true).
|
|
97
92
|
*/
|
|
98
93
|
enableRetries?: boolean;
|
|
99
94
|
/**
|
|
@@ -193,19 +188,18 @@ interface EventProperties extends BaseEventProperties {
|
|
|
193
188
|
*/
|
|
194
189
|
interface EventTypeMap {
|
|
195
190
|
screen_view: {
|
|
191
|
+
page_count?: number;
|
|
196
192
|
time_on_page?: number;
|
|
197
193
|
scroll_depth?: number;
|
|
198
194
|
interaction_count?: number;
|
|
199
|
-
has_exit_intent?: boolean;
|
|
200
|
-
is_bounce?: 0 | 1;
|
|
201
195
|
};
|
|
202
196
|
page_exit: {
|
|
197
|
+
path?: string;
|
|
198
|
+
timestamp?: number;
|
|
203
199
|
time_on_page: number;
|
|
204
200
|
scroll_depth: number;
|
|
205
201
|
interaction_count: number;
|
|
206
|
-
has_exit_intent: boolean;
|
|
207
202
|
page_count: number;
|
|
208
|
-
is_bounce: 0 | 1;
|
|
209
203
|
};
|
|
210
204
|
button_click: {
|
|
211
205
|
button_text?: string;
|
|
@@ -583,5 +577,5 @@ declare function getTrackingIds(urlParams?: URLSearchParams): {
|
|
|
583
577
|
*/
|
|
584
578
|
declare function getTrackingParams(urlParams?: URLSearchParams): string;
|
|
585
579
|
|
|
586
|
-
export {
|
|
587
|
-
export type { BaseEventProperties as B, DatabuddyConfig as D,
|
|
580
|
+
export { clear as f, flush as g, getAnonymousId as h, getSessionId as i, getTracker as j, getTrackingIds as k, getTrackingParams as l, isTrackerAvailable as m, trackCustomEvent as n, trackError as o, track as t };
|
|
581
|
+
export type { BaseEventProperties as B, DatabuddyConfig as D, EventName as E, PropertiesForEvent as P, ScreenViewFunction as S, TrackFunction as T, DataAttributes as a, DatabuddyTracker as b, EventProperties as c, EventTypeMap as d, SetGlobalPropertiesFunction as e };
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
* apiUrl="https://basket.databuddy.cc"
|
|
9
9
|
* trackWebVitals
|
|
10
10
|
* trackErrors
|
|
11
|
-
* trackScrollDepth
|
|
12
11
|
* samplingRate={0.5}
|
|
13
12
|
* />
|
|
14
13
|
* ```
|
|
@@ -18,7 +17,7 @@ interface DatabuddyConfig {
|
|
|
18
17
|
* Your Databuddy project client ID.
|
|
19
18
|
* If not provided, will automatically detect from NEXT_PUBLIC_DATABUDDY_CLIENT_ID environment variable.
|
|
20
19
|
* Get this from your Databuddy dashboard.
|
|
21
|
-
* Example:
|
|
20
|
+
* Example: UUID-style or short public id (dashboard client ID).
|
|
22
21
|
*/
|
|
23
22
|
clientId?: string;
|
|
24
23
|
/**
|
|
@@ -71,10 +70,6 @@ interface DatabuddyConfig {
|
|
|
71
70
|
* Track user interactions (default: false).
|
|
72
71
|
*/
|
|
73
72
|
trackInteractions?: boolean;
|
|
74
|
-
/**
|
|
75
|
-
* Track scroll depth (default: false).
|
|
76
|
-
*/
|
|
77
|
-
trackScrollDepth?: boolean;
|
|
78
73
|
/**
|
|
79
74
|
* Track page performance metrics (default: true).
|
|
80
75
|
*/
|
|
@@ -93,7 +88,7 @@ interface DatabuddyConfig {
|
|
|
93
88
|
*/
|
|
94
89
|
samplingRate?: number;
|
|
95
90
|
/**
|
|
96
|
-
* Enable retries for failed requests (default:
|
|
91
|
+
* Enable retries for failed requests (default: true).
|
|
97
92
|
*/
|
|
98
93
|
enableRetries?: boolean;
|
|
99
94
|
/**
|
|
@@ -193,19 +188,18 @@ interface EventProperties extends BaseEventProperties {
|
|
|
193
188
|
*/
|
|
194
189
|
interface EventTypeMap {
|
|
195
190
|
screen_view: {
|
|
191
|
+
page_count?: number;
|
|
196
192
|
time_on_page?: number;
|
|
197
193
|
scroll_depth?: number;
|
|
198
194
|
interaction_count?: number;
|
|
199
|
-
has_exit_intent?: boolean;
|
|
200
|
-
is_bounce?: 0 | 1;
|
|
201
195
|
};
|
|
202
196
|
page_exit: {
|
|
197
|
+
path?: string;
|
|
198
|
+
timestamp?: number;
|
|
203
199
|
time_on_page: number;
|
|
204
200
|
scroll_depth: number;
|
|
205
201
|
interaction_count: number;
|
|
206
|
-
has_exit_intent: boolean;
|
|
207
202
|
page_count: number;
|
|
208
|
-
is_bounce: 0 | 1;
|
|
209
203
|
};
|
|
210
204
|
button_click: {
|
|
211
205
|
button_text?: string;
|
|
@@ -583,5 +577,5 @@ declare function getTrackingIds(urlParams?: URLSearchParams): {
|
|
|
583
577
|
*/
|
|
584
578
|
declare function getTrackingParams(urlParams?: URLSearchParams): string;
|
|
585
579
|
|
|
586
|
-
export {
|
|
587
|
-
export type { BaseEventProperties as B, DatabuddyConfig as D,
|
|
580
|
+
export { clear as f, flush as g, getAnonymousId as h, getSessionId as i, getTracker as j, getTrackingIds as k, getTrackingParams as l, isTrackerAvailable as m, trackCustomEvent as n, trackError as o, track as t };
|
|
581
|
+
export type { BaseEventProperties as B, DatabuddyConfig as D, EventName as E, PropertiesForEvent as P, ScreenViewFunction as S, TrackFunction as T, DataAttributes as a, DatabuddyTracker as b, EventProperties as c, EventTypeMap as d, SetGlobalPropertiesFunction as e };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const isBrowser = typeof window !== "undefined" && typeof localStorage !== "undefined";
|
|
2
|
+
const STORAGE_KEY = "db-flags";
|
|
3
|
+
const DEFAULT_TTL = 24 * 60 * 60 * 1e3;
|
|
4
|
+
class BrowserFlagStorage {
|
|
5
|
+
ttl;
|
|
6
|
+
constructor(ttl = DEFAULT_TTL) {
|
|
7
|
+
this.ttl = ttl;
|
|
8
|
+
}
|
|
9
|
+
getAll() {
|
|
10
|
+
if (!isBrowser) {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
const raw = localStorage.getItem(STORAGE_KEY);
|
|
15
|
+
if (!raw) {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
const blob = JSON.parse(raw);
|
|
19
|
+
if (Date.now() - blob.savedAt > this.ttl) {
|
|
20
|
+
localStorage.removeItem(STORAGE_KEY);
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
return blob.flags;
|
|
24
|
+
} catch {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
setAll(flags) {
|
|
29
|
+
if (!isBrowser) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const blob = { flags, savedAt: Date.now() };
|
|
34
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(blob));
|
|
35
|
+
} catch {
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
clear() {
|
|
39
|
+
if (!isBrowser) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
localStorage.removeItem(STORAGE_KEY);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { BrowserFlagStorage as B };
|