Professor Sloth

Free web performance master class

Learn about web performance and how to make your site faster, delivered straight to your inbox.

API Reference

This is the developer reference guide to the APIs and behavior of the Request Metrics Browser Agent.

This is the developer reference guide to the APIs and behavior of the Request Metrics Browser Agent.


Table of Contents


RM

Added in 1.0.0

The top level namespace for Request Metrics.


RM.addMetadata(pageMetadata)

Added in 1.12.0

  • pageMetadata <Object>
    • [key] <String> Map of metadata key-value strings to be stored with this page view
  • Returns: void

Add a key-value pair of data that will describe the page, events, and errors captured during this page view. You can use this to track any arbitrary data that is interesting for you, such as the server environment, application code version, or whether the user is part of a test group.

If the metadata key already exists, it will be updated with the new value.

Warning: If you send sensitive data, or data that may make the user identifiable, you must obtain consent from the end-user in compliance with local regulation. See End User Data for more.

Example

RM.addMetadata({
  "sessionId": "abc123456",
  "paymentsVersion": "1.24.6",
  "test_headlines": "variant-1b"
});

RM.identify(userId, [userMetadata])

Added in 1.12.0

  • userId <String> Identification string for the user relevant to you. This could be a UUID, name, email address, or however you identify users.
  • userMetadata <Object>
    • name <String> Special metadata key that will override the display value in the Request Metrics interface.
    • email <String> Special metadata key that will provide a mailto link in the Request Metrics interface.
    • [key] <String> Any key-value combination of strings to be stored as metadata.
  • Returns: void

Identifies the current session as part of a known user and adopts all the previous activity in the session.

See Identifying Users.

Warning: If you send sensitive data, or data that may make the user identifiable, you must obtain consent from the end-user in compliance with local regulation. See End User Data for more.

Example

RM.identify("usr_448273eaf76d", {
  "name": "Jane Austin",
  "email": "jane@example.com",
  "plan": "professional",
  "vip": "yes"
});

RM.install(options)

Added in 1.0.0

  • options <Object>
    • token <String> Required. Your application token provided by the Request Metrics interface.
    • urlGroup <String> Optional. Name of the URL Group to associate data with.
    • ingestUrl <String> Optional. URL to send data. You have to provide this with Domain Forwarding or dedicated hosting.
  • Returns: void

Installs the agent into the browser environment, starting the observation of user events, network calls, and JavaScript errors. No data is transmitted until the install method has been called.

Install may only be called once.

Example

RM.install({
  "token": "abcdef:123456"
});

RM.sendEvent(eventName, [eventMetadata])

Added in 1.12.0

  • eventName <String> Name of the custom event to track
  • eventMetadata <Object>
    • [key] <String> Any key-value combination of strings to be stored as metadata.
  • Returns: void

Send a custom user event to be part of this session.

Warning: If you send sensitive data, or data that may make the user identifiable, you must obtain consent from the end-user in compliance with local regulation. See End User Data for more.

Example

RM.sendEvent("Watch Video", {
  "videoId": "1234"
});

RM.setUrlGroup(urlGroupName)

Added in 2.2.0

  • urlGroupName <String> Name of the URL Group to associate data with.
  • Returns: void

Specifies the URL Group that this page load should be associated with.

Example

RM.setUrlGroup("Product Details Page - Video");

RM.track(error, [errorMetadata])

Added in 1.12.0, errorMetadata in 1.13.0

  • error <Error> Instance of an Error to track with this session.
  • errorMetadata <Object>
    • [key] <String> Any key-value combination of strings to be stored as metadata.
  • Returns: void

Send a custom error event.

Example

try {
  doSomethingInYourApp();
} catch(e) {
  RM.track(e, { isHandled: "yes" });
}

RM.version

Added in 1.0.0

  • <String>

Version number of the current running Browser Agent.

Did you like this?
Found a mistake? Let us know!