Select a snippet format

  • How-to guide
  • Published Jul 01, 2025

The RUM JavaScript—whether automatically injected or manually inserted into your web application—consists of two key components:

  • Monitoring code: The JavaScript code that provides RUM capabilities such as capturing user actions.
  • Configuration: The application configuration that is initially used by the monitoring code. It is updated later via the RUM beacon response in case of configuration changes.

Dynatrace RUM provides several snippet formats that integrate these components into your pages in different ways, each tailored to meet specific requirements.

This page offers guidance to help you choose the snippet format that best meets your requirements, followed by a detailed description of each format.

Recommendations for selecting the snippet format

For most use cases, we recommend the following:

If you want to leverage the subresource integrity (SRI) browser feature to ensure that the monitoring code hasn't been altered, use OneAgent JavaScript tag with SRI for manual insertion and automatic injection.

To avoid parse-blocking execution of the monitoring code, configure the Script execution option of your selected snippet format to async or defer. Instructions for configuring this option are provided in the documentation for each individual snippet format below. Keep in mind that while the monitoring code is not yet fully loaded and initialized, certain timings and user actions will be lost.

Available snippet formats

JavaScript tag links to an external file that includes both the monitoring code and the configuration. JavaScript tag is only available for manual insertion.

Updates

The short cache duration used for the external file ensures regular automatic updates, making JavaScript tag an ideal choice if you don't want to take care of updating the inserted snippet after configuration changes.

Monitoring code source

The external file is loaded from the Dynatrace CDN.

Cache duration

The external file containing monitoring code and configuration is updated according to its cache duration, which is one hour by default and can be configured. The available values are low—a few hours or days—to ensure the configuration is updated regularly. The cache duration specifies how long browsers can cache the file. The Dynatrace CDN caches it for one hour.

To configure the cache duration

  1. Go to Web.
  2. Select the application that you want to configure.
  3. In the upper-right corner of the application overview page, select More () > Edit.
  4. From the application settings, select Injection > Manual insertion.
  5. In the JavaScript tag section, use the dropdown under Cache monitoring code and configuration for to select the required cache duration.
Script execution

By default, the monitoring code is loaded and executed synchronously by the browser. To avoid parse-blocking behavior, you can configure the addition of the async or defer attributes.

  • With the async attribute, the monitoring code is loaded in parallel with page parsing and executed immediately once it’s available.
  • With the defer attribute, the monitoring code is also loaded in parallel, but execution is deferred until after the page has finished parsing.

With both attributes, certain timings and user actions will be lost while the monitoring code is not yet fully loaded and initialized.

To configure script execution

  1. Go to Web.
  2. Select the application that you want to configure.
  3. In the upper-right corner of the application overview page, select More () > Edit.
  4. From the application settings, select Injection > Manual insertion.
  5. In the JavaScript tag section, set Script execution attribute to async, defer, or No attribute.
  6. Copy the snippet and insert it into your page.

When fetching the JavaScript tag via the API, you can control script execution by passing a parameter. For details, see GET JavaScript tag.

Addition of the crossorigin="anonymous" attribute

🟢 Enabled by default

The external script referenced by JavaScript tag is served from the Dynatrace CDN, resulting in a cross-origin request. To enable the collection of detailed JavaScript error messages and W3C resource timings, you need to include the crossorigin="anonymous" attribute in the script tag.

To enable the addition of the crossorigin="anonymous" attribute

  1. Go to Web.
  2. Select the application that you want to configure.
  3. In the upper-right corner of the application overview page, select More () > Edit.
  4. From the application settings, select Injection > Manual insertion.
  5. In the JavaScript tag section, enable Add the crossorigin=anonymous attribute.
  6. Copy the snippet and insert it into your page.

When fetching the JavaScript tag via the API, you can control the addition of the crossorigin="anonymous" attribute by passing a parameter. For details, see GET JavaScript tag.

Related tags
Digital Experience