Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Analytics | Track API Responses & JavaScript Errors

Trystan_Colwyn-
Level 2
Level 2

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

3 Replies
Brian_Johnson_
Community Advisor
Community Advisor

@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.

Trystan_Colwyn-
Level 2
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? 

Brian_Johnson_
Community Advisor
Community Advisor

@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" });