0

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?

DVA
  • 33
  • 5

1 Answers1

2

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.

bwest
  • 9,182
  • 3
  • 28
  • 58
  • Well I am interested to get things only once, I just want to know how many users are using 4k monitors or tablets. Thanks for the tip. – DVA May 04 '22 at 16:04
  • In that case, to reduce the amount of data you're storing, you could only invoke `addAction` if the resolution is greater than however many pixels wide 4k is. But for your case, you could also use a regular count metric and submit via API or SDK rather than tracking this in RUM. https://docs.datadoghq.com/api/latest/metrics/#submit-metrics or https://docs.datadoghq.com/integrations/node/#metric-collection might help – bwest May 04 '22 at 17:35