react-event-tracking 2.0.1 → 2.0.2
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 +4 -6
- package/dist/index.cjs +3 -4
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +3 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -111,6 +111,7 @@ type SystemEvents = {
|
|
|
111
111
|
|
|
112
112
|
// analytics.ts
|
|
113
113
|
export type AnalyticsEvents = SystemEvents & {
|
|
114
|
+
// supports deeply nested event maps
|
|
114
115
|
login_screen: LoginScreenEvents
|
|
115
116
|
}
|
|
116
117
|
|
|
@@ -124,17 +125,14 @@ const LoginButton = () => {
|
|
|
124
125
|
const { track } = useTracking();
|
|
125
126
|
|
|
126
127
|
// Or narrow it down to a specific scope
|
|
127
|
-
const { track } = useTracking("login_screen");
|
|
128
|
+
const { track: track2 } = useTracking("login_screen");
|
|
128
129
|
|
|
129
130
|
const handleLogin = () => {
|
|
130
|
-
// Full path: eventName is
|
|
131
|
+
// Full path: eventName is derived from the call chain (result: "login_screen.logged_in")
|
|
131
132
|
track.login_screen.logged_in({ timePassed: 3000 });
|
|
132
133
|
|
|
133
134
|
// Narrowed path: the same result: "login_screen.logged_in":
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
// Explicit event name: first argument overrides the event name. Result is "Logged In"
|
|
137
|
-
track.logged_in("Logged In", { timePassed: 3000 })
|
|
135
|
+
track2.logged_in({ timePassed: 3000 });
|
|
138
136
|
};
|
|
139
137
|
|
|
140
138
|
return (
|
package/dist/index.cjs
CHANGED
|
@@ -163,10 +163,9 @@ function createTracker(path = [], track) {
|
|
|
163
163
|
get(_, prop) {
|
|
164
164
|
return createTracker([...path, prop], track);
|
|
165
165
|
},
|
|
166
|
-
apply(_, __, [
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
track(eventName, eventParams);
|
|
166
|
+
apply(_, __, [params]) {
|
|
167
|
+
const eventName = path.join(".");
|
|
168
|
+
track(eventName, params);
|
|
170
169
|
}
|
|
171
170
|
});
|
|
172
171
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -6,7 +6,7 @@ type EventsMap = Record<string, any>;
|
|
|
6
6
|
type AnyFunction = (...args: any[]) => any;
|
|
7
7
|
type IsLeaf<T> = T extends Record<string, any> ? (keyof T extends never ? true : T[keyof T] extends Record<string, any> ? false : true) : true;
|
|
8
8
|
type FlatTracker<T> = {
|
|
9
|
-
[K in keyof T]: IsLeaf<T[K]> extends true ? (
|
|
9
|
+
[K in keyof T]: IsLeaf<T[K]> extends true ? (params: T[K]) => void : FlatTracker<T[K]>;
|
|
10
10
|
};
|
|
11
11
|
interface TrackContextValueLegacy {
|
|
12
12
|
track(eventName: string, params?: EventParams): void;
|
package/dist/index.d.mts
CHANGED
|
@@ -6,7 +6,7 @@ type EventsMap = Record<string, any>;
|
|
|
6
6
|
type AnyFunction = (...args: any[]) => any;
|
|
7
7
|
type IsLeaf<T> = T extends Record<string, any> ? (keyof T extends never ? true : T[keyof T] extends Record<string, any> ? false : true) : true;
|
|
8
8
|
type FlatTracker<T> = {
|
|
9
|
-
[K in keyof T]: IsLeaf<T[K]> extends true ? (
|
|
9
|
+
[K in keyof T]: IsLeaf<T[K]> extends true ? (params: T[K]) => void : FlatTracker<T[K]>;
|
|
10
10
|
};
|
|
11
11
|
interface TrackContextValueLegacy {
|
|
12
12
|
track(eventName: string, params?: EventParams): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ type EventsMap = Record<string, any>;
|
|
|
6
6
|
type AnyFunction = (...args: any[]) => any;
|
|
7
7
|
type IsLeaf<T> = T extends Record<string, any> ? (keyof T extends never ? true : T[keyof T] extends Record<string, any> ? false : true) : true;
|
|
8
8
|
type FlatTracker<T> = {
|
|
9
|
-
[K in keyof T]: IsLeaf<T[K]> extends true ? (
|
|
9
|
+
[K in keyof T]: IsLeaf<T[K]> extends true ? (params: T[K]) => void : FlatTracker<T[K]>;
|
|
10
10
|
};
|
|
11
11
|
interface TrackContextValueLegacy {
|
|
12
12
|
track(eventName: string, params?: EventParams): void;
|
package/dist/index.mjs
CHANGED
|
@@ -157,10 +157,9 @@ function createTracker(path = [], track) {
|
|
|
157
157
|
get(_, prop) {
|
|
158
158
|
return createTracker([...path, prop], track);
|
|
159
159
|
},
|
|
160
|
-
apply(_, __, [
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
track(eventName, eventParams);
|
|
160
|
+
apply(_, __, [params]) {
|
|
161
|
+
const eventName = path.join(".");
|
|
162
|
+
track(eventName, params);
|
|
164
163
|
}
|
|
165
164
|
});
|
|
166
165
|
}
|