@trackunit/react-core-hooks 0.2.228 → 0.2.229
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/index.cjs.js +23 -1
- package/index.esm.js +24 -2
- package/package.json +1 -1
- package/src/analytics/AnalyticsProvider.d.ts +2 -2
package/index.cjs.js
CHANGED
|
@@ -47,7 +47,29 @@ const useAnalytics = (events) => {
|
|
|
47
47
|
if (!context) {
|
|
48
48
|
throw new Error("useAnalytics must be used within an AnalyticsProvider");
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
const logEvent = React.useMemo(() => logEventWithDescription(context.logEvent, events), [context.logEvent, events]);
|
|
51
|
+
return {
|
|
52
|
+
...context,
|
|
53
|
+
logEvent,
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
// Automatically append the description from the event type
|
|
57
|
+
const logEventWithDescription = (logEvent, events) => {
|
|
58
|
+
return (eventName, details, nameSupplement) => {
|
|
59
|
+
const event = events === null || events === void 0 ? void 0 : events[eventName];
|
|
60
|
+
const eventDescription = event === null || event === void 0 ? void 0 : event.description;
|
|
61
|
+
// Include description in the details object.
|
|
62
|
+
const detailsWithDescription = {
|
|
63
|
+
eventDescription,
|
|
64
|
+
...details,
|
|
65
|
+
};
|
|
66
|
+
if (nameSupplement) {
|
|
67
|
+
logEvent(eventName, detailsWithDescription, nameSupplement);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
logEvent(eventName, detailsWithDescription);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
51
73
|
};
|
|
52
74
|
|
|
53
75
|
const AssetSortingContext = React.createContext(null);
|
package/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { createContext, useContext, useState, useCallback,
|
|
2
|
+
import { createContext, useContext, useMemo, useState, useCallback, useEffect } from 'react';
|
|
3
3
|
import { jsx } from 'react/jsx-runtime';
|
|
4
4
|
import { AssetRuntime, CustomerRuntime, EventRuntime, ParamsRuntime, SiteRuntime } from '@trackunit/iris-app-runtime-core';
|
|
5
5
|
import { filterByMultiple } from '@trackunit/shared-utils';
|
|
@@ -27,7 +27,29 @@ const useAnalytics = (events) => {
|
|
|
27
27
|
if (!context) {
|
|
28
28
|
throw new Error("useAnalytics must be used within an AnalyticsProvider");
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
const logEvent = useMemo(() => logEventWithDescription(context.logEvent, events), [context.logEvent, events]);
|
|
31
|
+
return {
|
|
32
|
+
...context,
|
|
33
|
+
logEvent,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
// Automatically append the description from the event type
|
|
37
|
+
const logEventWithDescription = (logEvent, events) => {
|
|
38
|
+
return (eventName, details, nameSupplement) => {
|
|
39
|
+
const event = events === null || events === void 0 ? void 0 : events[eventName];
|
|
40
|
+
const eventDescription = event === null || event === void 0 ? void 0 : event.description;
|
|
41
|
+
// Include description in the details object.
|
|
42
|
+
const detailsWithDescription = {
|
|
43
|
+
eventDescription,
|
|
44
|
+
...details,
|
|
45
|
+
};
|
|
46
|
+
if (nameSupplement) {
|
|
47
|
+
logEvent(eventName, detailsWithDescription, nameSupplement);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
logEvent(eventName, detailsWithDescription);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
31
53
|
};
|
|
32
54
|
|
|
33
55
|
const AssetSortingContext = createContext(null);
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EventDictionary, IAnalyticsContext } from "@trackunit/react-core-contexts-api";
|
|
2
2
|
export declare const AnalyticsContext: import("react").Context<IAnalyticsContext<Record<string, never>> | null>;
|
|
3
3
|
export declare const AnalyticsContextProvider: import("react").Provider<IAnalyticsContext<Record<string, never>> | null>;
|
|
4
4
|
/**
|
|
@@ -17,4 +17,4 @@ export declare const AnalyticsContextProvider: import("react").Provider<IAnalyti
|
|
|
17
17
|
* logEvent("Login", { loginPage: "New Manager" });
|
|
18
18
|
* @see {@link IAnalyticsContext}
|
|
19
19
|
*/
|
|
20
|
-
export declare const useAnalytics: <TEvents extends
|
|
20
|
+
export declare const useAnalytics: <TEvents extends EventDictionary = never>(events: TEvents) => IAnalyticsContext<TEvents>;
|