Closed dcloud closed 2 months ago
Noting that the at least two of the places the we see incorrect action names being recorded are on links within web componenents:
<va-alert-expandable>
has the accordion toggle that uses an anchor, and the anchor text is not recorded, but text near the anchor is<va-link>
components in the "hub links" are recording all the text in the container for the <va-link>
Talked with someone on pensions and they wired up datadogLogs in addition to RUM. I wonder if this could help uncover client-side errors generally… I'm not sure how it might help with our RUM woes
Also seeing an action on the temp Medical Records page that also appears to grab random text. Not sure where the click is for
click on Medical records COMING SOON Soon, you’ll be able to find, print, and download your medical records o [...]
My guess at this time is a click on an element within the VaBreadcrumbs
in MedicalRecords.jsx
Looing at how Datadog determines the action text function-module which has a getActionNameFromElementForStrategies
that gets run up to two times. First with priorityStrategies
and if that doesn't yield a name, then fallbackStrategies
. The fallback uses a getTextualContent
function that checks if an element has an innerText
prop. So multiple places to look at and compare to how a web component might behave differently from vanilla HTML…
If I run vets-website locally with DDG manually enabled, I can pause in various points in the Datadog code, and using that I saw that getTextualContent
gets run for the accordion, and that function tries to extract text from the <va-alert-expandable>
web component rather than the <a>
within <va-alert-expandable>
. Since that is the element
that gets inspected, it makes sense that DDG would grab the whole text inside the expanded element.
I should look at the <va-link>
elements since I'd expect that to grab the correct text because that component is a wrapper around a stock <a>
element.
Checking out the <va-link>
and seeing that computeClickActionBase
sees the event.target as the <va-link>
… event.target.textContent
and event.target.innerText
are empty strings…
The fallback strategy in Datadog RUM code will go up the DOM tree from elements to parent elements to grab text. This is what we're seeing, though I was seeing just the heading above a link…
It looks like it goes va-link -> li -> ul.mhv-c-link-list -> nav -> div.vads-l-col--12
, and the div's element.innerText
is `"My VA health benefits", and at least on localhost the recursion up the tree ends. That doesn't quite match what we've seen in staging and production where the entire div's content is in the action.
I'm not seeing those click actions appear in datadog, though my session did.
Adding data-dd-action-name
gets the Rum code to grab that value, but I still don't see actions recorded into ddg during my testing (a session is recorded but not the actions), so hard to confirm that would work in other environments
As the event flow shows, I created https://github.com/department-of-veterans-affairs/vets-design-system-documentation/issues/3001 which is to start discussion with VADS about the web components and how they interact with Datadog
To reiterate findings:
<va-link />
wraps regular <a />
link, but doesn't provide link text via innerText
or other DOM methods. Since that component is a wrapper around a normal HTML anchor with a custom Google Analytics event, there is littler reason to use it when the custom event is disabled.<va-alert-expandable />
contains a <a />
link as well, but is used as a button to show/hide the expandable alert. The only immediate remediation here would be to add a data-dd-action-name
prop. Ultimately, the component-library needs to fix the issues with the component not providing the text of the clickable link-buttonTickets spawned from this investigation:
@wesrowe @LynneJohnson224 This is ready to be closed
Closing
Description
Spawned from https://github.com/department-of-veterans-affairs/va.gov-team/issues/86178, we have a few open support tickets with Datadog support because we are seeing issues with
User story
As a Cartography team member, I want Datadog RUM to record actions accurately and reliably
Notes
DDG support requests:
Prior investigation
Notes from prior work:
Possible tasks:
Acceptance criteria