beforeSend (Data Interception and Modification)¶
The RUM SDK executes the beforeSend method before sending each piece of data. By customizing the implementation of this method, you can achieve the following operations:
- Modify parts of the data
- Intercept the data being sent
beforeSend provides two parameters:
event is the object generated by the SDK that collects various metric data. For specific information about context, refer to the table below:
| EVENT TYPE | CONTEXT |
|---|---|
| View | Location |
| Action | Event |
| Resource (XHR) | XMLHttpRequest, PerformanceResourceTiming |
| Resource (Fetch) | Reqeust, Response, PerformanceResourceTiming |
| Resource (Other) | PerformanceResourceTiming |
| Error | Error |
| Long Task | PerformanceLongTaskTiming |
Modifying Parts of the Data¶
window.DATAFLUX_RUM &&
window.DATAFLUX_RUM.init({
...,
beforeSend: (event, context) => {
if (event.type === 'resource' && event.resource.type === 'fetch') {
// Add the response headers of the request to the original data
event.context = {...event.context, responseHeaders: context.response.headers}
}
},
...
});
Note
beforeSend can only modify data fields allowed by the SDK. Modifications outside these fields will be ignored.
The fields that the SDK allows to modify are listed in the table below:
| Property | Type | Description |
|---|---|---|
view.url |
string | Page URL |
view.referrer |
string | Page Referrer |
resource.url |
string | Resource URL |
error.message |
string | Error Message |
error.resource.url |
string | Error Resource URL |
context |
string | Global custom content, e.g., content added via addAction, addError. |
Intercepting Data to be Sent¶
You can intercept unwanted data by returning true or false from the beforeSend method.
trueindicates this piece of data should be reported.falseindicates this piece of data should be ignored and not reported.