react-event-tracking 2.0.1 → 2.0.3

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 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 automatically derived from the call chain (result: "login_screen.logged_in")
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
- 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 })
135
+ track2.logged_in({ timePassed: 3000 });
138
136
  };
139
137
 
140
138
  return (
package/dist/index.cjs CHANGED
@@ -81,7 +81,7 @@ const TrackRootComponent = ({
81
81
  const value = React.useMemo(() => {
82
82
  return new Proxy({}, {
83
83
  get(_, prop) {
84
- if (prop === track.name) return track;
84
+ if (prop === "track") return track;
85
85
  const handler = customHandlersRef.current?.[prop];
86
86
  if (typeof handler === "function") {
87
87
  return (...args) => handler(...args);
@@ -89,11 +89,11 @@ const TrackRootComponent = ({
89
89
  return void 0;
90
90
  },
91
91
  has(_, prop) {
92
- return prop === track.name || (customHandlersRef.current ? prop in customHandlersRef.current : false);
92
+ return prop === "track" || (customHandlersRef.current ? prop in customHandlersRef.current : false);
93
93
  },
94
94
  ownKeys() {
95
95
  const customKeys = customHandlersRef.current ? Object.keys(customHandlersRef.current) : [];
96
- return Array.from(/* @__PURE__ */ new Set([track.name, ...customKeys]));
96
+ return Array.from(/* @__PURE__ */ new Set(["track", ...customKeys]));
97
97
  },
98
98
  getOwnPropertyDescriptor(_, prop) {
99
99
  return {
@@ -106,16 +106,7 @@ const TrackRootComponent = ({
106
106
  return /* @__PURE__ */ React__default.createElement(TrackContext.Provider, { value }, children);
107
107
  };
108
108
  const factory = (args) => {
109
- return (props) => /* @__PURE__ */ React__default.createElement(
110
- TrackRootComponent,
111
- {
112
- onEvent: args.onEvent,
113
- filter: args.filter,
114
- transform: args.transform,
115
- customHandlers: args.customHandlers,
116
- ...props
117
- }
118
- );
109
+ return (props) => /* @__PURE__ */ React__default.createElement(TrackRootComponent, { ...args, ...props });
119
110
  };
120
111
  const TrackRoot = Object.assign(TrackRootComponent, { factory });
121
112
  const TrackProvider = ({
@@ -163,10 +154,9 @@ function createTracker(path = [], track) {
163
154
  get(_, prop) {
164
155
  return createTracker([...path, prop], track);
165
156
  },
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);
157
+ apply(_, __, [params]) {
158
+ const eventName = path.join(".");
159
+ track(eventName, params);
170
160
  }
171
161
  });
172
162
  }
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) & ((eventName: string, params: T[K]) => void) : FlatTracker<T[K]>;
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 ? ((params: T[K]) => void) & ((eventName: string, params: T[K]) => void) : FlatTracker<T[K]>;
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 ? ((params: T[K]) => void) & ((eventName: string, params: T[K]) => void) : FlatTracker<T[K]>;
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
@@ -75,7 +75,7 @@ const TrackRootComponent = ({
75
75
  const value = useMemo(() => {
76
76
  return new Proxy({}, {
77
77
  get(_, prop) {
78
- if (prop === track.name) return track;
78
+ if (prop === "track") return track;
79
79
  const handler = customHandlersRef.current?.[prop];
80
80
  if (typeof handler === "function") {
81
81
  return (...args) => handler(...args);
@@ -83,11 +83,11 @@ const TrackRootComponent = ({
83
83
  return void 0;
84
84
  },
85
85
  has(_, prop) {
86
- return prop === track.name || (customHandlersRef.current ? prop in customHandlersRef.current : false);
86
+ return prop === "track" || (customHandlersRef.current ? prop in customHandlersRef.current : false);
87
87
  },
88
88
  ownKeys() {
89
89
  const customKeys = customHandlersRef.current ? Object.keys(customHandlersRef.current) : [];
90
- return Array.from(/* @__PURE__ */ new Set([track.name, ...customKeys]));
90
+ return Array.from(/* @__PURE__ */ new Set(["track", ...customKeys]));
91
91
  },
92
92
  getOwnPropertyDescriptor(_, prop) {
93
93
  return {
@@ -100,16 +100,7 @@ const TrackRootComponent = ({
100
100
  return /* @__PURE__ */ React.createElement(TrackContext.Provider, { value }, children);
101
101
  };
102
102
  const factory = (args) => {
103
- return (props) => /* @__PURE__ */ React.createElement(
104
- TrackRootComponent,
105
- {
106
- onEvent: args.onEvent,
107
- filter: args.filter,
108
- transform: args.transform,
109
- customHandlers: args.customHandlers,
110
- ...props
111
- }
112
- );
103
+ return (props) => /* @__PURE__ */ React.createElement(TrackRootComponent, { ...args, ...props });
113
104
  };
114
105
  const TrackRoot = Object.assign(TrackRootComponent, { factory });
115
106
  const TrackProvider = ({
@@ -157,10 +148,9 @@ function createTracker(path = [], track) {
157
148
  get(_, prop) {
158
149
  return createTracker([...path, prop], track);
159
150
  },
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);
151
+ apply(_, __, [params]) {
152
+ const eventName = path.join(".");
153
+ track(eventName, params);
164
154
  }
165
155
  });
166
156
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-event-tracking",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "files": [
5
5
  "dist"
6
6
  ],