# XHR request made through a timer isn't reflecting on user actions

**URL:** <https://community.dynatrace.com/t/xhr-request-made-through-a-timer-isnt-reflecting-on-user-actions/35949>\
**Category:** Real User Monitoring\
**Tags:** user-actions\
**Created:** [July 21, 2022, 7:40pm UTC](https://community.dynatrace.com/t/xhr-request-made-through-a-timer-isnt-reflecting-on-user-actions/35949 "2022-07-21T19:40:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![KiranAIR](https://avatars.discourse-cdn.com/v4/letter/k/a8b319/32.png) [@KiranAIR](https://community.dynatrace.com/u/KiranAIR)\
**Post date:** [July 21, 2022, 7:40pm UTC](https://community.dynatrace.com/t/xhr-request-made-through-a-timer-isnt-reflecting-on-user-actions/35949/1 "2022-07-21T19:40:31Z")

</div>

I have a timer observable in angular in the following manner,

this.xyz$ = timer(1,1000\*60\*15).pipe( //Runs&nbsp; every 15 mins and makes service calls&nbsp; &nbsp; &nbsp; &nbsp; switchMap(() =\> {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return this.loadMyXHRCall();&nbsp; &nbsp; &nbsp; &nbsp; }),&nbsp; &nbsp; &nbsp; &nbsp; retry(),&nbsp; &nbsp; &nbsp; &nbsp; share(),&nbsp; &nbsp; );  
I have a panel component that initiates the subscription to this timer. I am unable to see that xhr user action when the xhr call is made via timer. If I directly call “this.loadMyXHRCall()” , this does get detected.

Am I missing any setting to be enabled?

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [July 21, 2022, 8:12pm UTC](https://community.dynatrace.com/t/xhr-request-made-through-a-timer-isnt-reflecting-on-user-actions/35949/2 "2022-07-21T20:12:10Z")

</div>

[@KiranAIR](https://community.dynatrace.com/user/53336)&nbsp; - So this XHR call is initiated **without** user input? If this is true, then it won’t be detected as user action. User action are - as the name says it - actions initiated by a user. If it’s on a background, it’s not (typically) a user action.

So if you want this XHR call detected become a user action you have several options:

- call the [dtrum api](https://www.dynatrace.com/support/doc/javascriptapi/interfaces/dtrum_types.DtrumApi.html)&nbsp;explicitly in your timer (I’d prefer doing it this way) (enterXHRaction / leaveXHRaction)
- use **cux=1** &nbsp;parameter for the RUM JavaScript as described [here](https://community.dynatrace.com/topic/86170).

---

<div class="post-metadata">

**Author:** ![KiranAIR](https://avatars.discourse-cdn.com/v4/letter/k/a8b319/32.png) [@KiranAIR](https://community.dynatrace.com/u/KiranAIR)\
**Post date:** [July 22, 2022, 4:11pm UTC](https://community.dynatrace.com/t/xhr-request-made-through-a-timer-isnt-reflecting-on-user-actions/35949/3 "2022-07-22T16:11:11Z")

</div>

Hey Julius,  
This XHR call is initiated on the panel creation. On click of a button, In

ngOnInit() on the panel where I subscribe to the timer. Unfortunately, I am injecting the script tag dynamically so that its only used in our Production Environment.  
Like below,  
&nbsp;let dynatraceScript = document.createElement(“script”);&nbsp;dynatraceScript.type = this.configService.config.dynatraceScript.type;&nbsp;dynatraceScript.crossOrigin = this.configService.config.dynatraceScript.crossOrigin;&nbsp;dynatraceScript.src = this.configService.config.dynatraceScript.src;&nbsp;document.getElementsByTagName(‘head’)[0].appendChild(dynatraceScript);  
So I am unable to call the dtrum api or dT\_ object directly.

I tried the cux=1 option, works great for subsequent calls made by the timer and also captured some extra xhr actions which weren’t done before. It still doesnt capture the first call made by the timer for me.  
E.g.,&nbsp;this.xyz$&nbsp;=&nbsp;timer(1,1000\*60\*15).pipe( //Runs&nbsp; every 15 mins and makes service calls&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;switchMap(()&nbsp;=\>&nbsp;{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;this.loadMyXHRCall();&nbsp; &nbsp; &nbsp; &nbsp; }),&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;retry(),&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;share(),&nbsp; &nbsp; );  
In the above timer, the call flow is from 0,15,30,45…and so on. I am able to catpure the call from 15,30,45 but not the first call made when subscribed to the timer at 0 with the cux option.

Thanks,  
Kiran

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [July 22, 2022, 4:51pm UTC](https://community.dynatrace.com/t/xhr-request-made-through-a-timer-isnt-reflecting-on-user-actions/35949/4 "2022-07-22T16:51:17Z")

</div>

I think if you are injecting the RUM before you are creating the panel, then you should be able to call the dtrum API just fine. You need to handle if it’s injected anyway.

For the missing first XHR I can think of two reasons:

- it’s already captured in a user action (remember - you clicked a button, so it’s initiated by a user)
- it’s some timer thing (check if [Timeout functionality](https://www.dynatrace.com/support/help/shortlink/capture-xhr-actions#enable-timed-action-support) is enabled for the Web App in Dynatrace)

---

<div class="post-metadata">

**Author:** ![KiranAIR](https://avatars.discourse-cdn.com/v4/letter/k/a8b319/32.png) [@KiranAIR](https://community.dynatrace.com/u/KiranAIR)\
**Post date:** [July 22, 2022, 7:39pm UTC](https://community.dynatrace.com/t/xhr-request-made-through-a-timer-isnt-reflecting-on-user-actions/35949/5 "2022-07-22T19:39:45Z")

</div>

Hi Julius,&nbsp;  
I will try definitely try the api, I can see the documentation for JavaScript Rum API but no examples on how to&nbsp; integrate with an application. Do I directly use dtrum or need to import it explicitly and then use? It would be great if you could redirect to any examples.

I do have timeout setting enabled. There was on other user action triggered on the panel (a call made to fetch an icon). For now, I have set that to be primary criteria for creation.

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [July 22, 2022, 8:32pm UTC](https://community.dynatrace.com/t/xhr-request-made-through-a-timer-isnt-reflecting-on-user-actions/35949/6 "2022-07-22T20:32:47Z")

</div>

If you download the package in your Dynatrace environment (go to Settings → Web and mobile monitoring → Advanced setup) it contains API docs (the same as on the web) and also examples.

You just need to check if the dtrum object is present (e.g. typeof (dtrum) !== “undefined” ) and then call the methods and it should be just fine.
