This page describes the API provided by the RUM JavaScript. For the API to retrieve the RUM JavaScript for manual insertion, refer to RUM manual insertion tags API.
Dynatrace RUM includes a powerful JavaScript API that lets you customize and enhance web frontend monitoring for your applications. On top of everything the RUM JavaScript captures automatically, the API lets you report your own events, enrich sessions with additional context, take manual control of user actions, and build automated tests around the data your application sends. Read on to learn about its capabilities, the on-page JavaScript API, the npm package, and the companion Playwright testing framework.
The JavaScript API is called from your own application code and offers the following capabilities.
sendEvent.sendSessionPropertyEvent.identifyUser.sendExceptionEvent so internally handled failures still surface in monitoring.addEventModifier to adjust or filter RUM events on the fly.dynatrace.userActions namespace.interactions.sendKeyPressEvent to report key press interactions that aren't automatically detected by standard key press capturing.The API comes with comprehensive reference documentation covering everything above in detail, with API signatures, TypeScript types, practical use cases, and copy-paste examples to help you get started quickly.
The online reference always reflects the latest version of the @dynatrace/rum-javascript-sdk npm package. For older versions, use the Markdown docs in the package's docs/ directory.
There are two ways to work with the API. Both expose the same capabilities but differ in how you call them.
The on-page API and the npm package let you customize and enrich monitoring once the RUM JavaScript is on the page—they don't replace its addition via automatic injection or manual insertion; see Initial setup for web frontends.
The on-page JavaScript API is provided by the dynatrace global object that the RUM JavaScript exposes directly on your page. Use it for quick, in-page instrumentation, or if you don't have—or don't want—a build step.
@dynatrace/rum-javascript-sdk npm package The @dynatrace/rum-javascript-sdk npm package is a typed, safe wrapper around the same API for applications built with a bundler and TypeScript. It makes the on-page API easier and safer to call.
Reach for the SDK instead of the on-page API if:
The following table summarizes the key differences.
| On-page JavaScript API | npm package | |
|---|---|---|
How you access it | The | An |
Best for | Quick in-page snippets and apps without a build step | Applications built with a bundler and TypeScript |
Type safety | None, since | Full TypeScript type definitions included |
When the RUM JavaScript isn't loaded | You must guard every call yourself ( | The synchronous API is a safe no-op; the asynchronous ( |
The API ships a companion Playwright testing framework, @dynatrace/rum-javascript-sdk-playwright, so you can verify in CI that your application sends exactly the RUM events you expect.
It provides a Playwright fixture that connects to your Dynatrace environment, injects the correct RUM JavaScript for your application, and exposes expect-style assertions on the events the RUM JavaScript sends:
import { test, expect } from "@dynatrace/rum-javascript-sdk-playwright";test("reports the component event", async ({ page, dynatraceTesting }) => {await page.goto("https://your-app.example.com");await page.getByText("Explore data").first().click();await dynatraceTesting.expectToHaveSentEvent(expect.objectContaining({ "event_properties.component_rendered": "Data" }));});
Setup requires an API token with the Read RUM manual insertion tags permission, your environment URL, and your application ID. For a full walkthrough, see Dynatrace RUM JavaScript Testing Framework for Playwright.