Skip to content

Commit 55e65fd

Browse files
committed
feat(withTracking): Listen to onChange event listener
- get value for input element - add value property to userInteractionResource only when the value is present
1 parent 8942d0b commit 55e65fd

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/library/user-analytics/lib/resources/userInteractionResource.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ export namespace UserInteraction {
3333
export const TYPE = "UserInteraction";
3434

3535
export type Action =
36-
| "onClick";
36+
| "onClick"
37+
| "onChange"
3738

3839
export interface Tracker {
3940
action: Action;

src/library/user-analytics/react/components/withTracking.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export function withTracking (
2828
tracker: UserInteraction.Tracker,
2929
) {
3030
const targetNode = e.target as HTMLElement;
31+
const value = getValueFromNode(e);
3132
const userInteractionResource = UserInteraction.generateResource(
3233
dataContext.app,
3334
tracker.action,
@@ -40,7 +41,9 @@ export function withTracking (
4041
target: targetNode.nodeName || e.currentTarget.nodeName,
4142
innerHTML: targetNode.innerHTML,
4243
innerText: targetNode.innerText,
43-
value: "",
44+
...(value && {
45+
value,
46+
}),
4447
},
4548
},
4649
tracker.data,
@@ -66,3 +69,12 @@ export function withTracking (
6669
);
6770
};
6871
};
72+
73+
function getValueFromNode(e: React.SyntheticEvent) {
74+
75+
if (e.currentTarget.nodeName === "INPUT") {
76+
const currentTarget = e.target as HTMLInputElement;
77+
return currentTarget.value
78+
}
79+
}
80+

0 commit comments

Comments
 (0)