20 Nov 2023 09:43 AM
Hi,
i would like to find out if i have a JavaScript function (e.g. submitSentiments()) that trigger both an XHR request and a custom action, how will the actions be captured/recorded in Dynatrace?
Would it be a case of:
1) 2 actions? 1 XHR action, 1 custom action or
2) 1 root action with one XHR request and 1 custom action group together since they are trigger by the same button click.
function submitSentiment(value) {
//XHR action
fetch('https://jsonplaceholder.typicode.com/submit')
.then(response => response.json())
.then(data => {})
.catch(error => {});
//Custom action
var action = window.dtrum.enterAction('Submit sentiment');
window.dtrum.leaveAction(action);
}
Thanks.
Solved! Go to Solution.
20 Nov 2023 09:53 AM - edited 20 Nov 2023 09:54 AM
Hi @Weilin1
Given a JavaScript submitSentiment(value) function that triggers both an XHR request and a custom action, Dynatrace is likely to register these actions as follows:
Dynatrace sees them as two separate actions because they are conceptually different - one is a network request to the server and the other is a custom action defined in the application.
There may still be an option two:
In this option, Dynatrace groups the actions together because they are part of a single sequence of user interactions, providing a holistic view of what happens when a user performs a specific action (e.g. clicking a button that triggers a submitSentiment).
Hope it helps😊
Radek
20 Nov 2023 10:09 AM
Hi Radek,
Thanks for the explanation. It really helpful.
I am hoping that it will be option 1, that Dynatrace see them as 2 different actions.
But i am also afraid that option 2 might happen. Hence how can i prevent option 2 from happening?
Thanks.
20 Nov 2023 10:15 AM
What you can do is make sure that the custom action and the XHR request are defined as separate actions in the code. This includes clearly separating blocks of code and ensuring they are called independently. Additionally, assign unique identifiers or names to each action. This should help:)
20 Nov 2023 10:27 AM
Would something like this work?
function submitSentiment(value) {
//Custom action
var action = window.dtrum.enterAction('Submit sentiment');
window.dtrum.leaveAction(action);
//XHR action
fetch('https://jsonplaceholder.typicode.com/submit')
.then(response => response.json())
.then(data => {
var action = dtrum.enterXhrAction('xhr', 3,'https://jsonplaceholder.typicode.com/submit');
dtrum.leaveXhrAction(action);
})
.catch(error => {});
}
Is this what you mean by defined as separate actions?
Thanks
20 Nov 2023 11:35 AM
Yes, it looks good