Create more targeted onsite experiences with the new Klaviyo JS object

Profile photo of author Jon Palmer
Image of new Klaviyo JavaScript object.

Klaviyo has released a new JavaScript (JS) object that supports callbacks and promises, giving brands that leverage our APIs more visibility into when updates have been made to Klaviyo’s system. This gives you more control over the timing of  customer-facing onsite experiences, such as the triggering of a sign-up form.  

The challenge

Callbacks or Promises-JS Object

All brands that track shoppers’ activity on their website and pass that data to Klaviyo have installed a JS object — either through the integration between their ecommerce platform and Klaviyo, or by manually adding a code snippet to their site. For the last ten years, the JS object that has tracked shopper activity and triggered sign-up forms is  _learnq.

While most brands are able to accomplish all of their use cases for triggering onsite experiences with _learnq and the the setting available in Klaviyo’s form builder, there are some brands with development resources that want to go deeper.

Where _learnq has fallen short for those brands is that it does not notify you when Klaviyo completes an action. So if you wanted to, for example, wait to show a form on your website until Klaviyo lets you know that we have identified a shopper, or wait to redirect a shopper until you know Klaviyo has updated their profile with their birthday or first name, you didn’t have that flexibility. But through the use of callbacks or promises, brands can trigger onsite experiences based on notifications from Klaviyo APIs, making these more customized marketing strategies possible. 

The solution

New JavaScript Object

While _learnq has served brands that use Klaviyo well for a long time, we are excited to announce that a new JS object is now available that supports all the same functionality as its predecessor but also supports callbacks and promises. In addition, this new JS object also supports custom sign up form triggers, so you can launch a pop-up as a result of a shopper clicking a button or a link on your website.

All new Klaviyo customers will get the new JS object automatically during onboarding, and brands that want to take advantage of this new functionality can update the Klaviyo code snippet on your site. If you don’t care about callbacks or promises, then no action is required. Klaviyo will continue to support the original _learnq JS object.

Getting started

If you want to take advantage of this new functionality, and you’re ready to get started, replace the existing Klaviyo code on your website with the new JS object. You will then be able to utilize callbacks to trigger events — such as showing a pop-up or redirecting shoppers to a thank you page — when Klaviyo actions such as identifying or tracking site visitors have been completed.

Check out the guide on how to update the Klaviyo JS object on your website.