<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: The difference between addEnterActionListener() vs addLeaveActionListener() in Real User Monitoring</title>
    <link>https://community.dynatrace.com/t5/Real-User-Monitoring/The-difference-between-addEnterActionListener-vs/m-p/230093#M5499</link>
    <description>&lt;P&gt;I believe i might have figured out why.&amp;nbsp;&lt;/P&gt;&lt;P&gt;When using&amp;nbsp;addLeaveActionListener(), it is triggered after an action has ended.&lt;/P&gt;&lt;P&gt;In my example, because my removeLeaveActionListener() is placed after the action, it was never triggered.&lt;/P&gt;&lt;P&gt;Hence whenever an action has ended (in my case the 3 actions in&amp;nbsp;&lt;SPAN&gt;submitSentiments()), it will trigger the addStringProperties() as the listener was never removed.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var property_name_str;

function actionPropertyToXHR() {

property_name_str = {property_name:"Agree"};
dtrum.addLeaveActionListener(addStringProperties);

fetch('https://jsonplaceholder.typicode.com/posts', {
method:'POST',
body:JSON.stringify({
title:'foo',
body:'bar',
userId:1,
}),
headers: {
'Content-type':'application/json; charset=UTF-8',
},
})
.then((response) =&amp;gt; response.json())
.then((json) =&amp;gt; console.log(json));

dtrum.removeLeaveActionListener(addStringProperties);
}

function addStringProperties(actionId) {
window.dtrum.addActionProperties(actionId, null, null, property_name_str, null);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Instead if i were to place the removeLeaveActionListener() in the addStringProperties() function, it will remove the listener and is working as expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var property_name_str;

function actionPropertyToXHR() {

property_name_str = {property_name:"Agree"};
dtrum.addLeaveActionListener(addStringProperties);

fetch('https://jsonplaceholder.typicode.com/posts', {
method:'POST',
body:JSON.stringify({
title:'foo',
body:'bar',
userId:1,
}),
headers: {
'Content-type':'application/json; charset=UTF-8',
},
})
.then((response) =&amp;gt; response.json())
.then((json) =&amp;gt; console.log(json));
}

function addStringProperties(actionId) {
window.dtrum.addActionProperties(actionId, null, null, property_name_str, null);
dtrum.removeLeaveActionListener(addStringProperties);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 29 Nov 2023 01:06:01 GMT</pubDate>
    <dc:creator>Weilin1</dc:creator>
    <dc:date>2023-11-29T01:06:01Z</dc:date>
    <item>
      <title>The difference between addEnterActionListener() vs addLeaveActionListener()</title>
      <link>https://community.dynatrace.com/t5/Real-User-Monitoring/The-difference-between-addEnterActionListener-vs/m-p/230078#M5498</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Like to check if anyone has explore the RUM JavaScript API on addEnterActionListener() vs addLeaveActionListener()?&lt;/P&gt;&lt;P data-unlink="true"&gt;According to the &lt;A href="https://www.dynatrace.com/support/doc/javascriptapi/interfaces/dtrum_types.DtrumApi.html" target="_self"&gt;documentation&lt;/A&gt;,&amp;nbsp;addEnterActionListener() is&amp;nbsp;&lt;SPAN&gt;called while entering an action, which I understand and have managed to get the expected outcome, but addLeaveActionListener() is slightly complicated to me.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P data-unlink="true"&gt;&lt;SPAN&gt;addLeaveActionListener() is called when leaving an action and is used&amp;nbsp;to hook into the out of the box action closing event. On what type of circumstances should i be using it?&lt;/SPAN&gt;&lt;/P&gt;&lt;P data-unlink="true"&gt;&lt;SPAN&gt;In the below example, when i called&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;actionPropertyToXHR() follow by submitSentiments() function, the function to add string action property addStringProperties() get called 3 times after&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;addRatingToAction().&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P data-unlink="true"&gt;&lt;FONT face="inherit"&gt;I &lt;/FONT&gt;suspected&lt;FONT face="inherit"&gt;&amp;nbsp;the 3 calls was because in&amp;nbsp;&lt;SPAN&gt;submitSentiments() there are 3 actions (2XHR action 1 custom action). but why would it be triggered when i did include removeLeaveActionListener()?&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var rating_long;

function submitSentiments(value) {
var rating = +value;
// XHR Request
fetch('https://dummyjson.com/products/1')
.then(response =&amp;gt; response.json())
.then(data =&amp;gt; {

rating_long = { sentiment_rating:rating };
window.dtrum.addEnterActionListener(addRatingToAction);

var submtitSentiment = window.dtrum.enterAction('Submit Sentiment');
window.dtrum.leaveAction(submtitSentiment);

window.dtrum.removeEnterActionListener(addRatingToAction);

})

}

function addRatingToAction(actionId) {
window.dtrum.addActionProperties(actionId, rating_long, null, null, null);
}

var property_name_str;

function actionPropertyToXHR() {

property_name_str = {property_name:"Agree"};
dtrum.addLeaveActionListener(addStringProperties);

fetch('https://jsonplaceholder.typicode.com/posts', {
method:'POST',
body:JSON.stringify({
title:'foo',
body:'bar',
userId:1,
}),
headers: {
'Content-type':'application/json; charset=UTF-8',
},
})
.then((response) =&amp;gt; response.json())
.then((json) =&amp;gt; console.log(json));

dtrum.removeLeaveActionListener(addStringProperties);
}

function addStringProperties(actionId) {
window.dtrum.addActionProperties(actionId, null, null, property_name_str, null);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 10:05:00 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Real-User-Monitoring/The-difference-between-addEnterActionListener-vs/m-p/230078#M5498</guid>
      <dc:creator>Weilin1</dc:creator>
      <dc:date>2023-11-28T10:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: The difference between addEnterActionListener() vs addLeaveActionListener()</title>
      <link>https://community.dynatrace.com/t5/Real-User-Monitoring/The-difference-between-addEnterActionListener-vs/m-p/230093#M5499</link>
      <description>&lt;P&gt;I believe i might have figured out why.&amp;nbsp;&lt;/P&gt;&lt;P&gt;When using&amp;nbsp;addLeaveActionListener(), it is triggered after an action has ended.&lt;/P&gt;&lt;P&gt;In my example, because my removeLeaveActionListener() is placed after the action, it was never triggered.&lt;/P&gt;&lt;P&gt;Hence whenever an action has ended (in my case the 3 actions in&amp;nbsp;&lt;SPAN&gt;submitSentiments()), it will trigger the addStringProperties() as the listener was never removed.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var property_name_str;

function actionPropertyToXHR() {

property_name_str = {property_name:"Agree"};
dtrum.addLeaveActionListener(addStringProperties);

fetch('https://jsonplaceholder.typicode.com/posts', {
method:'POST',
body:JSON.stringify({
title:'foo',
body:'bar',
userId:1,
}),
headers: {
'Content-type':'application/json; charset=UTF-8',
},
})
.then((response) =&amp;gt; response.json())
.then((json) =&amp;gt; console.log(json));

dtrum.removeLeaveActionListener(addStringProperties);
}

function addStringProperties(actionId) {
window.dtrum.addActionProperties(actionId, null, null, property_name_str, null);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Instead if i were to place the removeLeaveActionListener() in the addStringProperties() function, it will remove the listener and is working as expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var property_name_str;

function actionPropertyToXHR() {

property_name_str = {property_name:"Agree"};
dtrum.addLeaveActionListener(addStringProperties);

fetch('https://jsonplaceholder.typicode.com/posts', {
method:'POST',
body:JSON.stringify({
title:'foo',
body:'bar',
userId:1,
}),
headers: {
'Content-type':'application/json; charset=UTF-8',
},
})
.then((response) =&amp;gt; response.json())
.then((json) =&amp;gt; console.log(json));
}

function addStringProperties(actionId) {
window.dtrum.addActionProperties(actionId, null, null, property_name_str, null);
dtrum.removeLeaveActionListener(addStringProperties);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2023 01:06:01 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Real-User-Monitoring/The-difference-between-addEnterActionListener-vs/m-p/230093#M5499</guid>
      <dc:creator>Weilin1</dc:creator>
      <dc:date>2023-11-29T01:06:01Z</dc:date>
    </item>
  </channel>
</rss>

