Documentation
    Preparing search index...

    Public API for the RUM browser SDK.

    See RUM Browser Monitoring Setup for further information.

    interface RumGlobal {
        addAction: (name: string, context?: object) => void;
        addDurationVital: (name: string, options: AddDurationVitalOptions) => void;
        addError: (error: unknown, context?: object) => void;
        addFeatureFlagEvaluation: (key: string, value: any) => void;
        addTiming: (name: string, time?: number) => void;
        clearAccount: () => void;
        clearUser: () => void;
        getAccount: () => Context;
        getGlobalContext: () => Context;
        getInitConfiguration: () => undefined | RumInitConfiguration;
        getSessionReplayLink: () => undefined | string;
        getUser: () => Context;
        init: (initConfiguration: RumInitConfiguration) => void;
        onReady: (callback: () => void) => void;
        removeAccountProperty: (key: string) => void;
        removeGlobalContextProperty: (key: any) => void;
        removeUserProperty: (key: any) => void;
        setAccount: (newAccount: Account) => void;
        setAccountProperty: (key: string, property: any) => void;
        setGlobalContext: (context: Context) => void;
        setGlobalContextProperty: (key: any, value: any) => void;
        setTrackingConsent: (trackingConsent: TrackingConsent) => void;
        setUserProperty: (key: any, property: any) => void;
        setViewContext: (context: Context) => void;
        setViewContextProperty: (key: string, value: any) => void;
        setViewName: (name: string) => void;
        startDurationVital: (
            name: string,
            options?: DurationVitalOptions,
        ) => DurationVitalReference;
        startSessionReplayRecording: (options?: StartRecordingOptions) => void;
        stopDurationVital: (
            nameOrRef: string | DurationVitalReference,
            options?: DurationVitalOptions,
        ) => void;
        stopSessionReplayRecording: () => void;
        version: string;
        clearGlobalContext(): void;
        getViewContext(): Context;
        setUser(newUser: User & { id: string }): void;
        setUser(newUser: User): void;
        startView(nameOrOptions?: string | ViewOptions): void;
        stopSession(): void;
    }

    Hierarchy (View Summary)

    Index

    Account

    clearAccount: () => void

    Clear all account information

    Type declaration

      • (): void
      • Returns void

        Clear all account information

    getAccount: () => Context

    Get account information

    Type declaration

    removeAccountProperty: (key: string) => void

    Remove an account property

    Type declaration

      • (key: string): void
      • Parameters

        • key: string

          Key of the property to remove

        Returns void

    setAccount: (newAccount: Account) => void

    Set account information to all events, stored in @account

    Type declaration

      • (newAccount: Account): void
      • Parameters

        • newAccount: Account

          Account information

        Returns void

    setAccountProperty: (key: string, property: any) => void

    Set or update the account property, stored in @account.<key>

    Type declaration

      • (key: string, property: any): void
      • Parameters

        • key: string

          Key of the property

        • property: any

          Value of the property

        Returns void

    Custom Actions

    addAction: (name: string, context?: object) => void

    Add a custom action, stored in @action

    See Send RUM Custom Actions for further information.

    Type declaration

      • (name: string, context?: object): void
      • Parameters

        • name: string

          Name of the action

        • Optionalcontext: object

          Context of the action

        Returns void

    Custom Errors

    addError: (error: unknown, context?: object) => void

    Add a custom error, stored in @error.

    See Send RUM Custom Actions for further information.

    Type declaration

      • (error: unknown, context?: object): void
      • Parameters

        • error: unknown

          Error. Favor sending a Javascript Error to have a stack trace attached to the error event.

        • Optionalcontext: object

          Context of the error

        Returns void

    Custom Timings

    addTiming: (name: string, time?: number) => void

    Add a custom timing relative to the start of the current view, stored in @view.custom_timings.<timing_name>

    Note: passing a relative time is discouraged since it is actually used as-is but displayed relative to the view start. We currently don't provide a way to retrieve the view start time, so it can be challenging to provide a timing relative to the view start. see https://github.com/DataDog/browser-sdk/issues/2552

    Type declaration

      • (name: string, time?: number): void
      • Parameters

        • name: string

          Name of the custom timing

        • Optionaltime: number

          Epoch timestamp of the custom timing (if not set, will use current time)

        Returns void

    Global Context

    getGlobalContext: () => Context

    Get the global Context

    See Global context for further information.

    removeGlobalContextProperty: (key: any) => void

    Remove a global context property

    See Global context for further information.

    setGlobalContext: (context: Context) => void

    Set the global context information to all events, stored in @context See Global context for further information.

    Type declaration

      • (context: Context): void
      • Parameters

        Returns void

    setGlobalContextProperty: (key: any, value: any) => void

    Set or update a global context property, stored in @context.<key>

    See Global context for further information.

    Type declaration

      • (key: any, value: any): void
      • Parameters

        • key: any

          Key of the property

        • value: any

          Value of the property

        Returns void

    Init

    getInitConfiguration: () => undefined | RumInitConfiguration

    Get the init configuration

    init: (initConfiguration: RumInitConfiguration) => void

    Init the RUM browser SDK.

    See RUM Browser Monitoring Setup for further information.

    Type declaration

    datadogRum.init({
    applicationId: '<DATADOG_APPLICATION_ID>',
    clientToken: '<DATADOG_CLIENT_TOKEN>',
    site: '<DATADOG_SITE>',
    // service: 'my-web-application',
    // env: 'production',
    // version: '1.0.0',
    sessionSampleRate: 100,
    sessionReplaySampleRate: 100,
    trackResources: true,
    trackLongTasks: true,
    trackUserInteractions: true,
    })

    Other

    addFeatureFlagEvaluation: (key: string, value: any) => void

    Add a feature flag evaluation, stored in @feature_flags.<feature_flag_key>

    We recommend enabling the intake request compression when using feature flags compressIntakeRequests: true.

    See Feature Flag Tracking for further information.

    Type declaration

      • (key: string, value: any): void
      • Parameters

        • key: string

          The key of the feature flag.

        • value: any

          The value of the feature flag.

        Returns void

    onReady: (callback: () => void) => void

    For CDN async setup: Early RUM API calls must be wrapped in the window.DD_RUM.onReady() callback. This ensures the code only gets executed once the SDK is properly loaded.

    See CDN async setup for further information.

    version: string

    Version of the Logs browser SDK

    Session

    Session Replay

    getSessionReplayLink: () => undefined | string

    Get the Session Replay Link.

    See Connect Session Replay To Your Third-Party Tools for further information.

    startSessionReplayRecording: (options?: StartRecordingOptions) => void

    Start Session Replay recording. Enable to conditionally start the recording, use the startSessionReplayRecordingManually:true init parameter and call startSessionReplayRecording()

    See Browser Session Replay for further information.

    stopSessionReplayRecording: () => void

    Stop Session Replay recording.

    See Browser Session Replay for further information.

    Tracking Consent

    setTrackingConsent: (trackingConsent: TrackingConsent) => void

    Set the tracking consent of the current user.

    Data will be sent only if it is set to "granted". This value won't be stored by the library across page loads: you will need to call this method or set the appropriate trackingConsent field in the init() method at each page load.

    If this method is called before the init() method, the provided value will take precedence over the one provided as initialization parameter.

    See User tracking consent for further information.

    Type declaration

    User

    clearUser: () => void

    Clear all user information

    See User session for further information.

    getUser: () => Context

    Get user information

    See User session for further information.

    Type declaration

    removeUserProperty: (key: any) => void

    Remove a user property

    Type declaration

      • (key: any): void
      • Parameters

        • key: any

          Key of the property to remove

        Returns void

    User session for further information.

    setUserProperty: (key: any, property: any) => void

    Set or update the user property, stored in @usr.<key>

    See User session for further information.

    Type declaration

      • (key: any, property: any): void
      • Parameters

        • key: any

          Key of the property

        • property: any

          Value of the property

        Returns void

    View

    setViewContext: (context: Context) => void

    Set View Context.

    Enable to manually set the context of the current view.

    Type declaration

      • (context: Context): void
      • Parameters

        • context: Context

          Context of the view

        Returns void

    setViewContextProperty: (key: string, value: any) => void

    Set View Context Property.

    Enable to manually set a property of the context of the current view.

    Type declaration

      • (key: string, value: any): void
      • Parameters

        • key: string

          key of the property

        • value: any

          value of the property

        Returns void

    setViewName: (name: string) => void

    Set View Name.

    Enable to manually change the name of the current view. See Override default RUM view names for further information.

    Type declaration

      • (name: string): void
      • Parameters

        • name: string

          Name of the view

        Returns void

    • Start a view manually. Enable to manual start a view, use trackViewsManually: true init parameter and call startView() to create RUM views and be aligned with how you’ve defined them in your SPA application routing.

      See Override default RUM view names for further information.

      Parameters

      • OptionalnameOrOptions: string | ViewOptions

        Name or options (name, service, version) for the view

      Returns void

    Vital

    addDurationVital: (name: string, options: AddDurationVitalOptions) => void

    Add a custom duration vital

    Type declaration

    startDurationVital: (
        name: string,
        options?: DurationVitalOptions,
    ) => DurationVitalReference

    Start a custom duration vital.

    If you plan to have multiple durations for the same vital, you should use the reference returned by this method.

    Type declaration

    stopDurationVital: (
        nameOrRef: string | DurationVitalReference,
        options?: DurationVitalOptions,
    ) => void

    Stop a custom duration vital

    Type declaration