react-event-tracking 1.0.5 → 1.0.6

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.cjs CHANGED
@@ -14,6 +14,7 @@ const useTracker = () => {
14
14
  }
15
15
  return ctx;
16
16
  };
17
+ const EmptyParams = {};
17
18
  const TrackRootComponent = ({ onEvent, children, filter, transform }) => {
18
19
  const parentCtx = React.useContext(TrackContext);
19
20
  const onEventRef = useFreshRef(onEvent);
@@ -22,7 +23,7 @@ const TrackRootComponent = ({ onEvent, children, filter, transform }) => {
22
23
  const sendEvent = React.useCallback(
23
24
  (eventName, params) => {
24
25
  let localName = eventName;
25
- let localParams = params;
26
+ let localParams = params || EmptyParams;
26
27
  let shouldProcessLocal = true;
27
28
  try {
28
29
  if (filterRef.current) {
@@ -34,7 +35,7 @@ const TrackRootComponent = ({ onEvent, children, filter, transform }) => {
34
35
  }
35
36
  if (shouldProcessLocal && transformRef.current) {
36
37
  try {
37
- const paramsCopy = params ? { ...params } : params;
38
+ const paramsCopy = params ? { ...params } : EmptyParams;
38
39
  const result = transformRef.current(eventName, paramsCopy);
39
40
  localName = result.eventName;
40
41
  localParams = result.params;
package/dist/index.d.cts CHANGED
@@ -5,16 +5,16 @@ type EventParams = Record<string, any>;
5
5
  type TrackContextValue = {
6
6
  sendEvent: (eventName: string, params?: EventParams) => void;
7
7
  };
8
- type EventFilter = (eventName: string, params?: EventParams) => boolean;
8
+ type EventFilter = (eventName: string, params: EventParams) => boolean;
9
9
  type TransformedEvent = {
10
10
  eventName: string;
11
- params?: EventParams;
11
+ params: EventParams;
12
12
  };
13
- type EventTransformer = (eventName: string, params?: EventParams) => TransformedEvent;
13
+ type EventTransformer = (eventName: string, params: EventParams) => TransformedEvent;
14
14
 
15
15
  declare const useTracker: () => TrackContextValue;
16
16
  type TrackRootProps = PropsWithChildren<{
17
- onEvent: (eventName: string, params?: EventParams) => void;
17
+ onEvent: (eventName: string, params: EventParams) => void;
18
18
  filter?: EventFilter;
19
19
  transform?: EventTransformer;
20
20
  }>;
package/dist/index.d.mts CHANGED
@@ -5,16 +5,16 @@ type EventParams = Record<string, any>;
5
5
  type TrackContextValue = {
6
6
  sendEvent: (eventName: string, params?: EventParams) => void;
7
7
  };
8
- type EventFilter = (eventName: string, params?: EventParams) => boolean;
8
+ type EventFilter = (eventName: string, params: EventParams) => boolean;
9
9
  type TransformedEvent = {
10
10
  eventName: string;
11
- params?: EventParams;
11
+ params: EventParams;
12
12
  };
13
- type EventTransformer = (eventName: string, params?: EventParams) => TransformedEvent;
13
+ type EventTransformer = (eventName: string, params: EventParams) => TransformedEvent;
14
14
 
15
15
  declare const useTracker: () => TrackContextValue;
16
16
  type TrackRootProps = PropsWithChildren<{
17
- onEvent: (eventName: string, params?: EventParams) => void;
17
+ onEvent: (eventName: string, params: EventParams) => void;
18
18
  filter?: EventFilter;
19
19
  transform?: EventTransformer;
20
20
  }>;
package/dist/index.d.ts CHANGED
@@ -5,16 +5,16 @@ type EventParams = Record<string, any>;
5
5
  type TrackContextValue = {
6
6
  sendEvent: (eventName: string, params?: EventParams) => void;
7
7
  };
8
- type EventFilter = (eventName: string, params?: EventParams) => boolean;
8
+ type EventFilter = (eventName: string, params: EventParams) => boolean;
9
9
  type TransformedEvent = {
10
10
  eventName: string;
11
- params?: EventParams;
11
+ params: EventParams;
12
12
  };
13
- type EventTransformer = (eventName: string, params?: EventParams) => TransformedEvent;
13
+ type EventTransformer = (eventName: string, params: EventParams) => TransformedEvent;
14
14
 
15
15
  declare const useTracker: () => TrackContextValue;
16
16
  type TrackRootProps = PropsWithChildren<{
17
- onEvent: (eventName: string, params?: EventParams) => void;
17
+ onEvent: (eventName: string, params: EventParams) => void;
18
18
  filter?: EventFilter;
19
19
  transform?: EventTransformer;
20
20
  }>;
package/dist/index.mjs CHANGED
@@ -8,6 +8,7 @@ const useTracker = () => {
8
8
  }
9
9
  return ctx;
10
10
  };
11
+ const EmptyParams = {};
11
12
  const TrackRootComponent = ({ onEvent, children, filter, transform }) => {
12
13
  const parentCtx = useContext(TrackContext);
13
14
  const onEventRef = useFreshRef(onEvent);
@@ -16,7 +17,7 @@ const TrackRootComponent = ({ onEvent, children, filter, transform }) => {
16
17
  const sendEvent = useCallback(
17
18
  (eventName, params) => {
18
19
  let localName = eventName;
19
- let localParams = params;
20
+ let localParams = params || EmptyParams;
20
21
  let shouldProcessLocal = true;
21
22
  try {
22
23
  if (filterRef.current) {
@@ -28,7 +29,7 @@ const TrackRootComponent = ({ onEvent, children, filter, transform }) => {
28
29
  }
29
30
  if (shouldProcessLocal && transformRef.current) {
30
31
  try {
31
- const paramsCopy = params ? { ...params } : params;
32
+ const paramsCopy = params ? { ...params } : EmptyParams;
32
33
  const result = transformRef.current(eventName, paramsCopy);
33
34
  localName = result.eventName;
34
35
  localParams = result.params;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-event-tracking",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "files": [
5
5
  "dist"
6
6
  ],