XHR gets cancelled / link_click Event

Hi, my problem is related to Error NS_BINDING_ABORTED, events are not send - #4 by Denis.

We track link_clicks with stape tag. Right after the event is triggered, the user (of course) navigates to a new page.

We see that very often the stape xhr-call is being cancelled (status cancelled in network tab). Also the event doesn’t reach the server. Sometimes the event is tagged as cancelled in the network tab, but still reaches the server.

We did not find a solution for this problem. But our data is inaccurate. Any ideas?

Hi @simon_reu,

This problem is a classic one.

There are 2 possible feasible solutions:

  1. Use the Use fetch instead of XMLHttpRequest (for POST requests only) option for the link_click events. Sometimes you might still see the event being cancelled in the Network tab, however, the browser is still trying to send the request under the hood using some other mechanisms specifically designed for cases like this, trying to ensure that it will be delivered to the server even if the page is being unloaded.
    Bear in mind that, if on sGTM these link_click events fire tags that set cookies or produce 3rd party cookie syncing requests back to the browser, they won’t work because the request won’t be processed by the browser.

  2. A more complicated approach that only works if the next page after the click is controlled by you.
    Instead of firing the link_click event when the action occurs, you save the information in a cookie or Storage (localStorage or sessionStorage) and fire the tag on the next page using this saved information.

Your proposed solution seems to work! Thanks a lot!

1 Like

Hi @giovaniortolani while the solution works for link_clicks we now have a problem with another tag. The event fires shortly before a redirect to a new page. We fire a GA4 Server Call and a Stape Data Tag call (v8) with fetch being checked. The GA4 Call reaches the server all the time, the data tag call doesn’t. I do not see the request in the network-tab. I put now put the stape data tag to highest priority. But sill only the GA4 Server call reaches the server. Any further ideas?

Hi @simon_reu.

Is Request Type configured as POST in this other tag? The fetch option only works with POST.

GA4 can use Service Workers to dispatch the network requests to the sGTM endpoint, so they can outlive the page unload.
The Data Tag does not offer this functionality, as it increases it size and complexity.

So you never never see the Data Tag event being dispatched and reaching the server? Or is it intermittent? If possible, DM me the webpage where this event triggers so I can check.

An alternative, is implementing the second option I mentioned earlier.

  1. A more complicated approach that only works if the next page after the click is controlled by you.
    Instead of firing the link_click event when the action occurs, you save the information in a cookie or Storage (localStorage or sessionStorage) and fire the tag on the next page using this saved information.