Install the Agent

Install the Agent

Install our JavaScript agent on your website to collect performance data. The agent is only 3.4 kb and async so it will have no significant impact on your page.

Installation Tutorial

Install from Our CDN

The easiest way to get started is by including the script from our CDN, which will automatically install.

<script src="https://cdn.requestmetrics.com/agent/current/rm.js"
        data-rm-token="YOUR_SITE_TOKEN" async></script>

The script will load asynchronously, so you can safely place it anywhere in your markup. Most people will add it to the <head> or at the end of the <body> tag.


Install with Google Tag Manager

It’s quick and easy to install Request Metrics with Google Tag Manager. Create a new Custom HTML Tag, and paste the following HTML into your tag configuration. Be sure to update YOUR_SITE_TOKEN.

<script src="https://cdn.requestmetrics.com/agent/current/rm.js"></script>
<script>
  window.RM && RM.install({
    token: "YOUR_SITE_TOKEN"
  });
</script>
Google Tag Manager Install

You may also want to set the “Tag Firing Options” to “Once Per Page”.

Then, add a “Trigger”. You probably want a “Initialization - All Pages” trigger, so that the script runs on every page, but your configuration may vary.

Request Metrics Tag Configuration
Request Metrics Tag Configuration

Don’t forget to save the tag and publish to your site!


Install from NPM

If you prefer to control your own destiny, you can include our npm package in your JavaScript bundle. Install it with:

npm i @request-metrics/browser-agent

Then reference the module and install it when initializing your application.

import { RM } from '@request-metrics/browser-agent';

RM.install({ token: 'YOUR_SITE_TOKEN' })

Additional Installation Patterns

The following are some common installation patterns from our customers. They are shown as CDN-based installs, but are adaptable to Google Tag Manager or NPM installations as well.

If you are subject to GDPR or other privacy regulation, you may want to get user consent before installing Request Metrics.

<script>
  function installRM() {
    if (USER_CONSENT_CONDITION) {
      window.RM && RM.install({
        token: "YOUR_SITE_TOKEN"
      });
    }
  }

  //Add call to user consent
  installRM();
</script>
<script src="https://cdn.requestmetrics.com/agent/current/rm.js" async onload="installRM()"></script>

This code snippet loads the agent asynchronously and then calls the installRM function, which will check your user consent state. If the user has not consented, nothing happens and you’ll need to call installRM again as part of your user consent logic.

There is no issue with calling RM.install multiple times.

2. Exclude URLs from Monitoring

You may want to exclude some development or testing URLs from monitoring. For example, excluding localhost URLs:

<script>
  function installRM() {
    if (location.hostname !== 'localhost') {
      window.RM && RM.install({
        token: "YOUR_SITE_TOKEN"
      });
    }
  }
</script>
<script src="https://cdn.requestmetrics.com/agent/current/rm.js" async onload="installRM()"></script>