Skip to content

Commit 4ef0fa1

Browse files
committed
v2.2.1
1 parent 40d38c2 commit 4ef0fa1

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
## Installation
1010

1111
```
12-
npm install --save nytm/nyt-react-tracking#v2.2.0
12+
npm install --save nytm/nyt-react-tracking#v2.2.1
1313
```
1414

1515
(Or whatever is the [latest version](https://github.com/nytm/nyt-react-tracking/releases))

build/withTrackingComponentDecorator.js

+9-14
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,19 @@ function withTrackingComponentDecorator() {
7474

7575
var _this = (0, _possibleConstructorReturn3.default)(this, (WithTracking.__proto__ || (0, _getPrototypeOf2.default)(WithTracking)).call(this, props, context));
7676

77-
_this.getTrackingData = function (data) {
78-
return (0, _lodash2.default)({}, _this.getChildContext().tracking.data, data);
79-
};
80-
8177
_this.trackEvent = function (data) {
8278
_this.getTrackingDispatcher()(
8379
// deep-merge tracking data from context and tracking data passed in here
84-
_this.getTrackingData(data));
80+
(0, _lodash2.default)({}, _this.trackingData, data));
8581
};
8682

8783
if (context.tracking && context.tracking.process && process) {
8884
console.error('[nyt-react-tracking] options.process should be used once on top level component');
8985
}
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);
9090
return _this;
9191
}
9292

@@ -98,13 +98,9 @@ function withTrackingComponentDecorator() {
9898
}, {
9999
key: 'getChildContext',
100100
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-
105101
return {
106102
tracking: {
107-
data: (0, _lodash2.default)({}, contextData, thisTrackingData),
103+
data: (0, _lodash2.default)({}, this.contextTrackingData, this.ownTrackingData),
108104
dispatch: this.getTrackingDispatcher(),
109105
process: this.context.tracking && this.context.tracking.process || process
110106
}
@@ -113,18 +109,17 @@ function withTrackingComponentDecorator() {
113109
}, {
114110
key: 'componentDidMount',
115111
value: function componentDidMount() {
116-
var contextTrackingData = this.getTrackingData();
117112
var contextProcess = this.context.tracking && this.context.tracking.process;
118113

119114
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)));
121116
} else if (typeof contextProcess === 'function') {
122-
var processed = contextProcess(contextTrackingData);
117+
var processed = contextProcess(this.ownTrackingData);
123118
if (processed) {
124119
this.trackEvent(processed);
125120
}
126121
} else if (typeof dispatchOnMount === 'function') {
127-
this.trackEvent(dispatchOnMount(contextTrackingData));
122+
this.trackEvent(dispatchOnMount(this.trackingData));
128123
} else if (dispatchOnMount === true) {
129124
this.trackEvent();
130125
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nyt/nyt-react-tracking",
3-
"version": "2.2.0",
3+
"version": "2.2.1",
44
"description": "Declarative tracking for React apps.",
55
"author": "The New York Times",
66
"contributors": [

0 commit comments

Comments
 (0)