DataDog send custom data from RUM

2.1k views Asked by At

I need to send the screen resolution from the user's device through DataDog. As it is easy to get window.screen.width and window.screen.height values, I have no clear idea how to send the values. My idea is to send a custom action:

import { datadogRum } from '@datadog/browser-rum';

(function sendScreenSize() {
    datadogRum.addAction('screenSize', {
        'width': window.screen.width,
        'height': window.screen.height
    })
})();

Is there any cleaner solution?

1

There are 1 answers

2
bwest On

You could consider using beforeSend to add the width and height to the event context for view events, then you will always have that data for each view.

For your current approach, you'd want to call addAction() in response to a page load or window resize event.