react-event-tracking 1.0.8 → 1.0.9
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 +18 -0
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ A convenient React context for tracking analytics events.
|
|
|
19
19
|
* [Multiple Trackers & Factory](#multiple-trackers--factory)
|
|
20
20
|
* [Filtering Events](#filtering-events)
|
|
21
21
|
* [Transforming Events](#transforming-events)
|
|
22
|
+
* [TypeScript Generics Support](#typescript-generics-support)
|
|
22
23
|
- [Best Practices](#best-practices)
|
|
23
24
|
- [Built-in Hooks](#built-in-hooks)
|
|
24
25
|
* [useMountEvent](#usemountevent)
|
|
@@ -164,6 +165,23 @@ const AmpltitudeUS = TrackRoot.factory(
|
|
|
164
165
|
);
|
|
165
166
|
```
|
|
166
167
|
|
|
168
|
+
### TypeScript Generics Support
|
|
169
|
+
|
|
170
|
+
`TrackProvider` supports generics for strict typing of the passed parameters.
|
|
171
|
+
|
|
172
|
+
```tsx
|
|
173
|
+
interface PageParams {
|
|
174
|
+
screenId: string;
|
|
175
|
+
isAuthorized: boolean;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const MyPage = () => (
|
|
179
|
+
<TrackProvider<PageParams> params={{ screenId: 'main', isAuthorized: true }}>
|
|
180
|
+
<Content />
|
|
181
|
+
</TrackProvider>
|
|
182
|
+
);
|
|
183
|
+
```
|
|
184
|
+
|
|
167
185
|
## Best Practices
|
|
168
186
|
|
|
169
187
|
A common pattern is to layer data from global to specific. Here is how parameters merge:
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { PropsWithChildren } from 'react';
|
|
3
3
|
|
|
4
|
-
type EventParams = Record<string, any
|
|
4
|
+
type EventParams<T extends Record<string, any> = Record<string, any>> = T;
|
|
5
5
|
interface TrackContextValue {
|
|
6
6
|
sendEvent(eventName: string, params?: EventParams): void;
|
|
7
7
|
sendEvent(event: EventObject): void;
|
|
@@ -26,8 +26,8 @@ type TrackRootProps = PropsWithChildren<{
|
|
|
26
26
|
declare const TrackRoot: (({ onEvent, children, filter, transform }: TrackRootProps) => react_jsx_runtime.JSX.Element) & {
|
|
27
27
|
factory: (onEvent: (eventName: string, params?: EventParams) => void, filter?: EventFilter, transform?: EventTransformer) => (props: Omit<TrackRootProps, "onEvent" | "filter" | "transform">) => react_jsx_runtime.JSX.Element;
|
|
28
28
|
};
|
|
29
|
-
declare const TrackProvider: ({ params, children }: PropsWithChildren<{
|
|
30
|
-
params: EventParams
|
|
29
|
+
declare const TrackProvider: <T extends Record<string, any>>({ params, children }: PropsWithChildren<{
|
|
30
|
+
params: EventParams<T>;
|
|
31
31
|
}>) => react_jsx_runtime.JSX.Element;
|
|
32
32
|
|
|
33
33
|
declare function useMountEvent(eventName: string, params?: EventParams): void;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { PropsWithChildren } from 'react';
|
|
3
3
|
|
|
4
|
-
type EventParams = Record<string, any
|
|
4
|
+
type EventParams<T extends Record<string, any> = Record<string, any>> = T;
|
|
5
5
|
interface TrackContextValue {
|
|
6
6
|
sendEvent(eventName: string, params?: EventParams): void;
|
|
7
7
|
sendEvent(event: EventObject): void;
|
|
@@ -26,8 +26,8 @@ type TrackRootProps = PropsWithChildren<{
|
|
|
26
26
|
declare const TrackRoot: (({ onEvent, children, filter, transform }: TrackRootProps) => react_jsx_runtime.JSX.Element) & {
|
|
27
27
|
factory: (onEvent: (eventName: string, params?: EventParams) => void, filter?: EventFilter, transform?: EventTransformer) => (props: Omit<TrackRootProps, "onEvent" | "filter" | "transform">) => react_jsx_runtime.JSX.Element;
|
|
28
28
|
};
|
|
29
|
-
declare const TrackProvider: ({ params, children }: PropsWithChildren<{
|
|
30
|
-
params: EventParams
|
|
29
|
+
declare const TrackProvider: <T extends Record<string, any>>({ params, children }: PropsWithChildren<{
|
|
30
|
+
params: EventParams<T>;
|
|
31
31
|
}>) => react_jsx_runtime.JSX.Element;
|
|
32
32
|
|
|
33
33
|
declare function useMountEvent(eventName: string, params?: EventParams): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { PropsWithChildren } from 'react';
|
|
3
3
|
|
|
4
|
-
type EventParams = Record<string, any
|
|
4
|
+
type EventParams<T extends Record<string, any> = Record<string, any>> = T;
|
|
5
5
|
interface TrackContextValue {
|
|
6
6
|
sendEvent(eventName: string, params?: EventParams): void;
|
|
7
7
|
sendEvent(event: EventObject): void;
|
|
@@ -26,8 +26,8 @@ type TrackRootProps = PropsWithChildren<{
|
|
|
26
26
|
declare const TrackRoot: (({ onEvent, children, filter, transform }: TrackRootProps) => react_jsx_runtime.JSX.Element) & {
|
|
27
27
|
factory: (onEvent: (eventName: string, params?: EventParams) => void, filter?: EventFilter, transform?: EventTransformer) => (props: Omit<TrackRootProps, "onEvent" | "filter" | "transform">) => react_jsx_runtime.JSX.Element;
|
|
28
28
|
};
|
|
29
|
-
declare const TrackProvider: ({ params, children }: PropsWithChildren<{
|
|
30
|
-
params: EventParams
|
|
29
|
+
declare const TrackProvider: <T extends Record<string, any>>({ params, children }: PropsWithChildren<{
|
|
30
|
+
params: EventParams<T>;
|
|
31
31
|
}>) => react_jsx_runtime.JSX.Element;
|
|
32
32
|
|
|
33
33
|
declare function useMountEvent(eventName: string, params?: EventParams): void;
|