react-event-tracking 2.0.0 → 2.0.1
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 +12 -1
- package/dist/index.cjs +4 -3
- 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 +4 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -120,12 +120,23 @@ export const useTracking = createReactEventTrackingHook<AnalyticsEvents>();
|
|
|
120
120
|
2. Use it in your components:
|
|
121
121
|
```tsx
|
|
122
122
|
const LoginButton = () => {
|
|
123
|
+
// You can use the full tracker
|
|
123
124
|
const { track } = useTracking();
|
|
125
|
+
|
|
126
|
+
// Or narrow it down to a specific scope
|
|
127
|
+
const { track } = useTracking("login_screen");
|
|
124
128
|
|
|
125
129
|
const handleLogin = () => {
|
|
126
|
-
//
|
|
130
|
+
// Full path: eventName is automatically derived from the call chain (result: "login_screen.logged_in")
|
|
127
131
|
track.login_screen.logged_in({ timePassed: 3000 });
|
|
132
|
+
|
|
133
|
+
// Narrowed path: the same result: "login_screen.logged_in":
|
|
134
|
+
track.logged_in({ timePassed: 3000 });
|
|
135
|
+
|
|
136
|
+
// Explicit event name: first argument overrides the event name. Result is "Logged In"
|
|
137
|
+
track.logged_in("Logged In", { timePassed: 3000 })
|
|
128
138
|
};
|
|
139
|
+
|
|
129
140
|
return (
|
|
130
141
|
<button onClick={handleLogin}>
|
|
131
142
|
Login with Google
|
package/dist/index.cjs
CHANGED
|
@@ -163,9 +163,10 @@ function createTracker(path = [], track) {
|
|
|
163
163
|
get(_, prop) {
|
|
164
164
|
return createTracker([...path, prop], track);
|
|
165
165
|
},
|
|
166
|
-
apply(_, __, [params]) {
|
|
167
|
-
|
|
168
|
-
|
|
166
|
+
apply(_, __, [name, params]) {
|
|
167
|
+
let eventParams = typeof name === "object" ? name : params;
|
|
168
|
+
const eventName = typeof name === "object" ? path.join(".") : name;
|
|
169
|
+
track(eventName, eventParams);
|
|
169
170
|
}
|
|
170
171
|
});
|
|
171
172
|
}
|
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 ? (params: T[K]) => void : FlatTracker<T[K]>;
|
|
9
|
+
[K in keyof T]: IsLeaf<T[K]> extends true ? ((params: T[K]) => void) & ((eventName: string, 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 ? (params: T[K]) => void : FlatTracker<T[K]>;
|
|
9
|
+
[K in keyof T]: IsLeaf<T[K]> extends true ? ((params: T[K]) => void) & ((eventName: string, 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 ? (params: T[K]) => void : FlatTracker<T[K]>;
|
|
9
|
+
[K in keyof T]: IsLeaf<T[K]> extends true ? ((params: T[K]) => void) & ((eventName: string, 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,9 +157,10 @@ function createTracker(path = [], track) {
|
|
|
157
157
|
get(_, prop) {
|
|
158
158
|
return createTracker([...path, prop], track);
|
|
159
159
|
},
|
|
160
|
-
apply(_, __, [params]) {
|
|
161
|
-
|
|
162
|
-
|
|
160
|
+
apply(_, __, [name, params]) {
|
|
161
|
+
let eventParams = typeof name === "object" ? name : params;
|
|
162
|
+
const eventName = typeof name === "object" ? path.join(".") : name;
|
|
163
|
+
track(eventName, eventParams);
|
|
163
164
|
}
|
|
164
165
|
});
|
|
165
166
|
}
|