How to create event that track the success response of the APIs?
The user performed an action say clicked a button, which is associated to an API call, then how can I track whether the response of the API was success or failure?
Creating events on APIs response
Hey
One option you could try is setting up an event listener on your page to send network requests that errored in as a custom event. You could try adding the below code immediately at the end of your FullStory snippet, but before the closing </script>
 tag (I would not recommend setting this up to track every single successful call, as there could potentially be a lot of custom events that would be especially noisy in your sessions): Â
(function () { var a = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function () { this.addEventListener( "readystatechange", function () { if (this.readyState === XMLHttpRequest.DONE) { var a = window[window._fs_namespace]; if (!a) return console.warn("FullStory not found"); var d = this.status; 0 === d || (200 >= d && 500 >= d) || ((d = { status_int: this.status, statusText_str: this.statusText, responseURL_str: this.responseURL, }), a.event("AJAX call", d)); } }, !1 ); a.apply(this, arguments); }; })(); window.addEventListener("request", function (a) { null !== window[window._fs_namespace] ? FS.event("AJAX call", { message: a.message, filename: a.filename }) : console.warn( "Attempted to send " + eventName + " to FullStory but no FS equivalent found on page" ); });
Â
Iâd also like to mention that network errors (anything in the 4xx-5xx range) are already captured as an event in FS and indexed for search, so the example code above would/could lead to a duplicate (see screenshot) depending on what status code range you configured.Â

Please let me know if you have any other questions as Iâd be happy to help!Â
Reply
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.