You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`react-tracking` is best used as a `@decorator()` using the [babel decorators plugin](https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy).
61
64
62
-
The decorator can be used on React Classes and on methods within those classes. If you use it on methods within these classes, make sure to decorate the class as well.
65
+
The decorator can be used on React Classes and on methods within those classes. If you use it on methods within these classes, make sure to decorate the class as well.
Will dispatch the following data (assuming no other tracking data in context from the rest of the app):
168
167
169
-
170
168
```
171
169
{
172
170
event: 'pageDataReady',
@@ -176,7 +174,7 @@ Will dispatch the following data (assuming no other tracking data in context fro
176
174
177
175
### Top level `options.process`
178
176
179
-
When there's a need to implicitly dispatch an event with some data for *every* component, you can define an `options.process` function. This function should be declared once, at some top-level component. It will get called with each component's tracking data as the only argument. The returned object from this function will be merged with all the tracking context data and dispatched in `componentDidMount()`. If a falsy value is returned (`false`, `null`, `undefined`, ...), nothing will be dispatched.
177
+
When there's a need to implicitly dispatch an event with some data for _every_ component, you can define an `options.process` function. This function should be declared once, at some top-level component. It will get called with each component's tracking data as the only argument. The returned object from this function will be merged with all the tracking context data and dispatched in `componentDidMount()`. If a falsy value is returned (`false`, `null`, `undefined`, ...), nothing will be dispatched.
180
178
181
179
A common use case for this is to dispatch a `pageview` event for every component in the application that has a `page` property on its `trackingData`:
182
180
@@ -198,13 +196,13 @@ When `Page2` mounts, nothing will be dispatched.
198
196
199
197
### Tracking Asynchronous Methods
200
198
201
-
Asynchronous methods (methods that return promises) can also be tracked when the method has resolved or rejects a promise. This is handled transparently, so simply decorating a asynchronous method the same way as a normal method will make the tracking call _after_ the promise is resolved or rejected.
199
+
Asynchronous methods (methods that return promises) can also be tracked when the method has resolved or rejects a promise. This is handled transparently, so simply decorating an asynchronous method the same way as a normal method will make the tracking call _after_ the promise is resolved or rejected.
202
200
203
201
```js
204
202
// ...
205
203
@track()
206
204
asynchandleEvent() {
207
-
awaitasyncCall(); // returns a promise
205
+
returnawaitasyncCall(); // returns a promise
208
206
}
209
207
// ...
210
208
```
@@ -229,31 +227,25 @@ import track from 'react-tracking';
@@ -350,4 +339,3 @@ This library simply merges the tracking data objects together (as it flows throu
350
339
### TypeScript Support
351
340
352
341
You can get the type definitions for React Tracking from DefinitelyTyped using `@types/react-tracking`. For an always up-to-date example of syntax, you should consult [the react-tracking type tests](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-tracking/test/react-tracking-with-types-tests.tsx).
0 commit comments