88import { DataContext } from '../contexts/dataContext' ;
99
1010type TrackerProps = {
11- context ?: string ,
11+ dataContext ?: UserInteraction . DataContext ;
1212 origin ?: string ,
1313 trackers : UserInteraction . Tracker [ ]
1414} & Object < any > ;
@@ -18,10 +18,13 @@ export function withTracking (
1818) {
1919 return function Fn ( props : TrackerProps ) {
2020 let eventHandlers : Object < any > = { } ;
21- const { trackers, ...originalProps } = props ;
21+ const { trackers, origin , dataContext : dataContextFromProps , ...originalProps } = props ;
2222
23- const dataContext = useContext ( DataContext ) ;
24- const context = props . context ? props . context : dataContext . context ;
23+ let dataContext = useContext ( DataContext ) ;
24+
25+ if ( dataContextFromProps ) {
26+ dataContext = dataContextFromProps
27+ }
2528
2629 function trackUserInteraction (
2730 e : React . SyntheticEvent ,
@@ -33,8 +36,10 @@ export function withTracking (
3336 dataContext . app ,
3437 tracker . action ,
3538 {
36- context,
37- origin : originalProps . origin || "" ,
39+ context : dataContext . context ,
40+ ...( originalProps . origin && {
41+ origin : originalProps . origin
42+ } ) ,
3843 component : Component . displayName || Component . name ,
3944 element : {
4045 currentTarget : e . currentTarget . nodeName ,
@@ -63,7 +68,7 @@ export function withTracking (
6368
6469 return (
6570 < Component
66- { ...props }
71+ { ...originalProps }
6772 { ...eventHandlers }
6873 />
6974 ) ;
0 commit comments