Skip to main content

Hey,
I would like to know if it’s possible to send “track” and “identify” in the same call using the Javascript API.

The reason behind this question is the following issue that I’ve encountered:


In case you want to identify and track a user within the same event e.g. a dataLayer push, two separate _learnq calls don’t work unless you introduce some sort of timeout because the exchange id from the identify call will not be available fast enough and before the next call fires.
 

Hi @THahn,

Welcome to the Community.

 

This seems like a classic case of race condition with identify & track where if both calls are made in quick succession, then no event is recorded. 

To avoid this, you will want to use _learnq.identify() instead of _learnq.push() and use a callback function as shown below:

function onIdentifyCompleteCallback () {
_learnq.track("Test Event");
}

_learnq.identify(identifyProperties, undefined, undefined, onIdentifyCompleteCallback)

You will need to identify the customer before you can use the track API call. The Identify API is mentioned in the same section as the Track API: https://www.klaviyo.com/docs#identify

 

Hope that helped,

Alex


Thanks @alex.hong!
It would be really great if the documentation would be up-to-date because I could only find the _learnq.push() method, e.g. here https://developers.klaviyo.com/en/docs/identify-api-reference

Best,
Tristan


Reply