@@ -74,19 +74,19 @@ function withTrackingComponentDecorator() {
74
74
75
75
var _this = ( 0 , _possibleConstructorReturn3 . default ) ( this , ( WithTracking . __proto__ || ( 0 , _getPrototypeOf2 . default ) ( WithTracking ) ) . call ( this , props , context ) ) ;
76
76
77
- _this . getTrackingData = function ( data ) {
78
- return ( 0 , _lodash2 . default ) ( { } , _this . getChildContext ( ) . tracking . data , data ) ;
79
- } ;
80
-
81
77
_this . trackEvent = function ( data ) {
82
78
_this . getTrackingDispatcher ( ) (
83
79
// deep-merge tracking data from context and tracking data passed in here
84
- _this . getTrackingData ( data ) ) ;
80
+ ( 0 , _lodash2 . default ) ( { } , _this . trackingData , data ) ) ;
85
81
} ;
86
82
87
83
if ( context . tracking && context . tracking . process && process ) {
88
84
console . error ( '[nyt-react-tracking] options.process should be used once on top level component' ) ;
89
85
}
86
+
87
+ _this . ownTrackingData = typeof trackingData === 'function' ? trackingData ( props ) : trackingData ;
88
+ _this . contextTrackingData = _this . context . tracking && _this . context . tracking . data || { } ;
89
+ _this . trackingData = ( 0 , _lodash2 . default ) ( { } , _this . contextTrackingData , _this . ownTrackingData ) ;
90
90
return _this ;
91
91
}
92
92
@@ -98,13 +98,9 @@ function withTrackingComponentDecorator() {
98
98
} , {
99
99
key : 'getChildContext' ,
100
100
value : function getChildContext ( ) {
101
- var thisTrackingData = typeof trackingData === 'function' ? trackingData ( this . props ) : trackingData ;
102
-
103
- var contextData = this . context . tracking && this . context . tracking . data || { } ;
104
-
105
101
return {
106
102
tracking : {
107
- data : ( 0 , _lodash2 . default ) ( { } , contextData , thisTrackingData ) ,
103
+ data : ( 0 , _lodash2 . default ) ( { } , this . contextTrackingData , this . ownTrackingData ) ,
108
104
dispatch : this . getTrackingDispatcher ( ) ,
109
105
process : this . context . tracking && this . context . tracking . process || process
110
106
}
@@ -113,18 +109,17 @@ function withTrackingComponentDecorator() {
113
109
} , {
114
110
key : 'componentDidMount' ,
115
111
value : function componentDidMount ( ) {
116
- var contextTrackingData = this . getTrackingData ( ) ;
117
112
var contextProcess = this . context . tracking && this . context . tracking . process ;
118
113
119
114
if ( typeof contextProcess === 'function' && typeof dispatchOnMount === 'function' ) {
120
- this . trackEvent ( ( 0 , _lodash2 . default ) ( { } , contextProcess ( contextTrackingData ) , dispatchOnMount ( contextTrackingData ) ) ) ;
115
+ this . trackEvent ( ( 0 , _lodash2 . default ) ( { } , contextProcess ( this . ownTrackingData ) , dispatchOnMount ( this . trackingData ) ) ) ;
121
116
} else if ( typeof contextProcess === 'function' ) {
122
- var processed = contextProcess ( contextTrackingData ) ;
117
+ var processed = contextProcess ( this . ownTrackingData ) ;
123
118
if ( processed ) {
124
119
this . trackEvent ( processed ) ;
125
120
}
126
121
} else if ( typeof dispatchOnMount === 'function' ) {
127
- this . trackEvent ( dispatchOnMount ( contextTrackingData ) ) ;
122
+ this . trackEvent ( dispatchOnMount ( this . trackingData ) ) ;
128
123
} else if ( dispatchOnMount === true ) {
129
124
this . trackEvent ( ) ;
130
125
}
0 commit comments