Expand my Community achievements bar.

Join us for the next Community Q&A Coffee Break on Tuesday April 23, 2024 with Eric Matisoff, Principal Evangelist, Analytics & Data Science, who will join us to discuss all the big news and announcements from Summit 2024!
SOLVED

Adobe Analytics | Track API Responses & JavaScript Errors

Avatar

Level 2

Anyone know the best way to track website API responses & Javascript errors within Adobe Launch? We want to record into eVars

1 Accepted Solution

Avatar

Correct answer by
Level 8

@Trystan_Colwyn- - If your API/request has a callback/response, I would suggest one of the following:

  • Push the information to your data layer (assuming you're using an event-driven data layer)
  • Use a direct call rule (DCR) that can be triggered directly in your callback
  • In your callback, trigger a custom JS event that you can listen for in Launch

All of the above options let you pass any information that is important to you.

For JS errors, I'd make the same suggestions. The only difference is the tracking event is triggered from your try/catch rather than an API callback/response.

View solution in original post

3 Replies

Avatar

Correct answer by
Level 8

@Trystan_Colwyn- - If your API/request has a callback/response, I would suggest one of the following:

  • Push the information to your data layer (assuming you're using an event-driven data layer)
  • Use a direct call rule (DCR) that can be triggered directly in your callback
  • In your callback, trigger a custom JS event that you can listen for in Launch

All of the above options let you pass any information that is important to you.

For JS errors, I'd make the same suggestions. The only difference is the tracking event is triggered from your try/catch rather than an API callback/response.

Avatar

Level 2

Thanks @Brian_Johnson_ !

 

dataLayer/directCall approach would be ideal, however we currently have some short term DEV challenges

 

Could you share more detail of your callback suggestion?  Maybe a particular example listening to a fetch API response? 

Avatar

Level 8

@Trystan_Colwyn- - Using the first fetch() example here:

fetch('./api/some.json')
  .then(
    function(response) {
      if (response.status !== 200) {
        console.log('Looks like there was a problem. Status Code: ' +
          response.status);
        return;
      }

      // Examine the text in the response
      response.json().then(function(data) {
        console.log(data);
      });
    }
  )
  .catch(function(err) {
    console.log('Fetch Error :-S', err);
  });

... I see three places you might want to capture the data:

  1. Inside the if (response.status !== 200) {} conditional
  2. Inside the response.json().then() logic
  3. Inside the .catch()

For all three of those, you could fire off a direct call rule, passing a payload with whatever information you want to capture. Something like _satellite.track("fetch_tracker", { "api_name": "some.json", "status": "success" });