Skip to main content

Hi all,

 

I would just like to ask for assistance. I am using Klaviyo’s JS API track() to track our events. I’ve added a callback function to the track() method to be able to identify if it’s success or not by creating a log file .

if (typeof klaviyo !== 'undefined') {
// Klaviyo.track with callback for response handling
klaviyo.track(eventName, eventData, (response) => {
if (response && response.success !== false) {
// Success - write success log to server file
this.writeToServerFile(eventName, {
...eventData,
klaviyoResponse: response
}, 'success');
console.log(`✅ Klaviyo ${eventName} tracked successfully:`, response);
} else {
// Failed - write error log to server file
const error = response ? response.error : 'Unknown error';
this.writeToServerFile(eventName, {
...eventData,
klaviyoResponse: response
}, 'error', error);
console.error(`❌ Klaviyo ${eventName} tracking failed:`, error);
}
});
} else {
const error = 'Klaviyo not available';
this.writeToServerFile(eventName, eventData, 'error', error);
console.error(`❌ ${error} for ${eventName}`);
}

On top of that right before we receive a response from track(), we are creating a log file already. Therefore, I assume that for every event triggered atleast 2 files should be created:

  • Attempt log file (always created whenever we trigger the event on the website (e.g. via button click)
  • Either a success or an error log file depending on the callback response of the track() API.

However, what happens was I only able to create attempt log files. Do you have any idea why it’s failing or why I can’t receive the callback response from the track() method? Are there blockers you encountered previously?

Thank you.

Hi ​@noel.antonio,

Thanks for sending over the API call info. To make sure we’re on the same page, you’ve created a custom mechanism to send yourself a log file, correct? If so, we wouldn’t be able to speak on why it is/isn’t sending in certain situations. We can definitely look into why our API calls are failing and if they’re structured correctly, if that’s happening in any instances, however.

Am I understanding your issue correctly here, or is there something I’m missing? Thanks!