Solved

Access Klaviyo email addresses in Javascript to pass to Lucky Orange

  • 27 June 2022
  • 5 replies
  • 483 views

Badge +2

The new version of the Lucky Orange service (visual user tracking, event tracking, heatmaps, etc.) allows me to add custom data to tie a Lucky Orange profile to other external profile stores.

I’d like to set a user’s Lucky Orange session email address to whatever has been captured by Klaviyo.

I’m really struggling to do this. I’ve found the following API endpoint:

     https://developers.klaviyo.com/en/reference/get-profile#exchange

But it would require exposing a private key to run in client-side Javascript (obvi a no-go).

I’m on a Shopify store, so I can’t run much code server-side to access this data securely.

Do I have any options here?

icon

Best answer by Wear Skinnys 28 June 2022, 01:44

View original

5 replies

Badge

No need to mess with the GET API or anything like that. You can read the user’s email address out of the Klaviyo cookie, and then use that in your Lucky Orange code. 

 

Basically if the cookie exists, grab the email address and use that as your identification variable. Do you have someone on your team familiar with javascript that can code that up for you? 

Badge +2

No need to mess with the GET API or anything like that. You can read the user’s email address out of the Klaviyo cookie, and then use that in your Lucky Orange code. 

 

Basically if the cookie exists, grab the email address and use that as your identification variable. Do you have someone on your team familiar with javascript that can code that up for you? 

 

I don’t think this works anymore, per the below comment from a Klaviyo rep (which is why I was testing going down the GET API path)...

  

Hi Klaviyo

I can not make this code work anymore. This line just gives me “undefined” right now. Has anything changed?

var kl_email = _learnq.identify().$email

  

Hi @Dasost,

...

This is due to some security changes we recently put into place. Previously, our email-to-website tracking included a base64 encoded parameter with email and public api key included in it. This was called the _ke parameter. We have since switched to using an exchange id, or _kx  parameter on these urls, which is a hashed user id that only Klaviyo can decode which is far more secure than the previous method. What this means in practice is that _learnq.identify().$email will no longer work since we do not expose a raw email address to the cookie.

 

When I print the _learnq.identify() object to the console log, it also no longer shows $email as an available variable:

 

This is in contrast to how it apparently looked a year ago:

 

Thus… I’m still left trying to find a way to do this. It’s wild to me they won’t let us access it. It’s integration-crushing.

Badge

Ahh, I’m sorry, I didn’t realize that this had changed recently and wasn’t available anymore. That does make things much more complicated. 

Badge +1

@Wear Skinnys have you managed to find any solution for this problem?
also, i’m confused on how is it even possible to make an API if you don’t have any information on the klaviyo profile (as it’s securely hashed as you mentioned in your replies)...

Badge +2

@Wear Skinnys have you managed to find any solution for this problem?
also, i’m confused on how is it even possible to make an API if you don’t have any information on the klaviyo profile (as it’s securely hashed as you mentioned in your replies)...

 

No! It ended up being very frustrating. I got to a 75% solution by just grabbing events from multiple places where emails might be captured (e.g., when someone spins a Wheelio, when Shopify shows an order confirmation, etc.) but it’s messy and buggy.

The server side API of Klaviyo likely exposes the emails (for use by apps that actually natively integrate and can open a server-side connection)…

But nothing on the browser/client side (Javascript) that would be useful by other tracking apps in the stack that don’t otherwise already integrate with Klaviyo.

Reply