Sets a String value for the specified attribute. Updates the value of the attribute if it already exists. The maximum number of attributes that can be added is 5.
metric.putAttribute('user_role', 'admin');
Name of the attribute. Max length is 40 chars.
Value of the attribute. Max length is 100 chars.
Sets the httpResponse code of the request.
const response = await fetch(url);
metric.setHttpResponseCode(response.status);
This is required for every request, if you do not provide this your metric will not be captured.
Value must be greater than 0. Set to null to remove. Invalid usage will be logged natively.
Content type of the response e.g. text/html or application/json.
const response = await fetch(url);
metric.setResponsePayloadSize(response.headers.get('Content-Type'));
Valid string of MIME type. Set to null to remove. Invalid usage will be logged natively.
Marks the end time of the response and queues the network request metric on the device for transmission. Does nothing if already stopped.
const metric = firebase.perf().newHttpMetric('https://api.com/login', 'POST');
await metric.start();
metric.putAttribute('user_role', 'admin');
await metric.stop();
Metric used to collect data for network requests/responses. A new instance must be used for every request/response.