react-event-tracking 1.0.7 → 1.0.8
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 +23 -19
- package/dist/index.d.cts +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +23 -19
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,19 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
6
6
|
|
|
7
7
|
const React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
8
8
|
|
|
9
|
+
function parseEventArgs(eventNameOrObject, eventParams) {
|
|
10
|
+
if (typeof eventNameOrObject === "object") {
|
|
11
|
+
return {
|
|
12
|
+
eventName: eventNameOrObject.eventName,
|
|
13
|
+
params: eventNameOrObject.params
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
eventName: eventNameOrObject,
|
|
18
|
+
params: eventParams
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
9
22
|
const TrackContext = React__default.createContext(null);
|
|
10
23
|
const useTracker = () => {
|
|
11
24
|
const ctx = React.useContext(TrackContext);
|
|
@@ -21,15 +34,10 @@ const TrackRootComponent = ({ onEvent, children, filter, transform }) => {
|
|
|
21
34
|
const filterRef = useFreshRef(filter);
|
|
22
35
|
const transformRef = useFreshRef(transform);
|
|
23
36
|
function sendEvent(eventNameOrObject, eventParams) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
incomingParams = eventNameOrObject.params;
|
|
29
|
-
} else {
|
|
30
|
-
eventName = eventNameOrObject;
|
|
31
|
-
incomingParams = eventParams;
|
|
32
|
-
}
|
|
37
|
+
const { eventName, params: incomingParams } = parseEventArgs(
|
|
38
|
+
eventNameOrObject,
|
|
39
|
+
eventParams
|
|
40
|
+
);
|
|
33
41
|
let localName = eventName;
|
|
34
42
|
let localParams = incomingParams || EmptyParams;
|
|
35
43
|
let shouldProcessLocal = true;
|
|
@@ -86,15 +94,10 @@ const TrackProvider = ({
|
|
|
86
94
|
const ctx = useTracker();
|
|
87
95
|
const paramsRef = useFreshRef(params);
|
|
88
96
|
function sendEvent(eventNameOrObject, eventParams) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
incomingParams = eventNameOrObject.params;
|
|
94
|
-
} else {
|
|
95
|
-
eventName = eventNameOrObject;
|
|
96
|
-
incomingParams = eventParams;
|
|
97
|
-
}
|
|
97
|
+
const { eventName, params: incomingParams } = parseEventArgs(
|
|
98
|
+
eventNameOrObject,
|
|
99
|
+
eventParams
|
|
100
|
+
);
|
|
98
101
|
const currentParams = paramsRef.current;
|
|
99
102
|
ctx.sendEvent(eventName, {
|
|
100
103
|
...currentParams,
|
|
@@ -111,9 +114,10 @@ function useFreshRef(data) {
|
|
|
111
114
|
return ref;
|
|
112
115
|
}
|
|
113
116
|
|
|
114
|
-
function useMountEvent(
|
|
117
|
+
function useMountEvent(eventNameOrObject, eventParams) {
|
|
115
118
|
const { sendEvent } = useTracker();
|
|
116
119
|
const counterRef = React.useRef(0);
|
|
120
|
+
const { eventName, params } = parseEventArgs(eventNameOrObject, eventParams);
|
|
117
121
|
React.useEffect(() => {
|
|
118
122
|
if (counterRef.current > 0) {
|
|
119
123
|
return;
|
package/dist/index.d.cts
CHANGED
|
@@ -31,5 +31,6 @@ declare const TrackProvider: ({ params, children }: PropsWithChildren<{
|
|
|
31
31
|
}>) => react_jsx_runtime.JSX.Element;
|
|
32
32
|
|
|
33
33
|
declare function useMountEvent(eventName: string, params?: EventParams): void;
|
|
34
|
+
declare function useMountEvent(event: EventObject): void;
|
|
34
35
|
|
|
35
36
|
export { TrackProvider, TrackRoot, useMountEvent, useTracker };
|
package/dist/index.d.mts
CHANGED
|
@@ -31,5 +31,6 @@ declare const TrackProvider: ({ params, children }: PropsWithChildren<{
|
|
|
31
31
|
}>) => react_jsx_runtime.JSX.Element;
|
|
32
32
|
|
|
33
33
|
declare function useMountEvent(eventName: string, params?: EventParams): void;
|
|
34
|
+
declare function useMountEvent(event: EventObject): void;
|
|
34
35
|
|
|
35
36
|
export { TrackProvider, TrackRoot, useMountEvent, useTracker };
|
package/dist/index.d.ts
CHANGED
|
@@ -31,5 +31,6 @@ declare const TrackProvider: ({ params, children }: PropsWithChildren<{
|
|
|
31
31
|
}>) => react_jsx_runtime.JSX.Element;
|
|
32
32
|
|
|
33
33
|
declare function useMountEvent(eventName: string, params?: EventParams): void;
|
|
34
|
+
declare function useMountEvent(event: EventObject): void;
|
|
34
35
|
|
|
35
36
|
export { TrackProvider, TrackRoot, useMountEvent, useTracker };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import React, { useContext, useCallback, useMemo, useRef, useEffect } from 'react';
|
|
2
2
|
|
|
3
|
+
function parseEventArgs(eventNameOrObject, eventParams) {
|
|
4
|
+
if (typeof eventNameOrObject === "object") {
|
|
5
|
+
return {
|
|
6
|
+
eventName: eventNameOrObject.eventName,
|
|
7
|
+
params: eventNameOrObject.params
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
eventName: eventNameOrObject,
|
|
12
|
+
params: eventParams
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
3
16
|
const TrackContext = React.createContext(null);
|
|
4
17
|
const useTracker = () => {
|
|
5
18
|
const ctx = useContext(TrackContext);
|
|
@@ -15,15 +28,10 @@ const TrackRootComponent = ({ onEvent, children, filter, transform }) => {
|
|
|
15
28
|
const filterRef = useFreshRef(filter);
|
|
16
29
|
const transformRef = useFreshRef(transform);
|
|
17
30
|
function sendEvent(eventNameOrObject, eventParams) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
incomingParams = eventNameOrObject.params;
|
|
23
|
-
} else {
|
|
24
|
-
eventName = eventNameOrObject;
|
|
25
|
-
incomingParams = eventParams;
|
|
26
|
-
}
|
|
31
|
+
const { eventName, params: incomingParams } = parseEventArgs(
|
|
32
|
+
eventNameOrObject,
|
|
33
|
+
eventParams
|
|
34
|
+
);
|
|
27
35
|
let localName = eventName;
|
|
28
36
|
let localParams = incomingParams || EmptyParams;
|
|
29
37
|
let shouldProcessLocal = true;
|
|
@@ -80,15 +88,10 @@ const TrackProvider = ({
|
|
|
80
88
|
const ctx = useTracker();
|
|
81
89
|
const paramsRef = useFreshRef(params);
|
|
82
90
|
function sendEvent(eventNameOrObject, eventParams) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
incomingParams = eventNameOrObject.params;
|
|
88
|
-
} else {
|
|
89
|
-
eventName = eventNameOrObject;
|
|
90
|
-
incomingParams = eventParams;
|
|
91
|
-
}
|
|
91
|
+
const { eventName, params: incomingParams } = parseEventArgs(
|
|
92
|
+
eventNameOrObject,
|
|
93
|
+
eventParams
|
|
94
|
+
);
|
|
92
95
|
const currentParams = paramsRef.current;
|
|
93
96
|
ctx.sendEvent(eventName, {
|
|
94
97
|
...currentParams,
|
|
@@ -105,9 +108,10 @@ function useFreshRef(data) {
|
|
|
105
108
|
return ref;
|
|
106
109
|
}
|
|
107
110
|
|
|
108
|
-
function useMountEvent(
|
|
111
|
+
function useMountEvent(eventNameOrObject, eventParams) {
|
|
109
112
|
const { sendEvent } = useTracker();
|
|
110
113
|
const counterRef = useRef(0);
|
|
114
|
+
const { eventName, params } = parseEventArgs(eventNameOrObject, eventParams);
|
|
111
115
|
useEffect(() => {
|
|
112
116
|
if (counterRef.current > 0) {
|
|
113
117
|
return;
|