Solved

Using API to update Profile Properties not working

  • 18 May 2021
  • 3 replies
  • 694 views

Badge +2

Hi,

I’m trying to add a custom property to a profile, but I can’t get it to work.  In fact I can’t even get the built in properties to work.  I’m sure it’s something simple, but I’m stumped at the moment.

When I run the following code:

var _learnq = _learnq || [];_learnq.push(['identify', {    '$email' : 'name@gmail.com',    '$first_name' : 'First',    '$last_name' : 'Last',    'test' : 'test'}]);

and then run some code to add it to a List I would expect to see these additional parameters in the Profile in the Klaviyo dashboard, but the additional parameters aren’t there.  I get the confirmation email for the double opt-in list, and then the Profile appears in the list, but without the standard first_ and last_name or the ‘test’ custom parameter.

Any ideas what I’m doing wrong?

Cheers,

Crac

icon

Best answer by Caractacus Downes 19 May 2021, 11:05

View original

3 replies

Userlevel 4
Badge +11

@Caractacus Downes your code looks fine. Are you getting anything returned when you run it? I tried it in the console on a test site of mine and it worked:

 

Running the code in the console
The profile in my test account in Klaviyo

 

Badge +2

Hi,

I’ve identified the problem, but I’m not sure I understand it.

I had thought the identify call was running but ignoring the custom properties.  Actually it wasn’t working at all, and the profile was being created by a second (server-side) call subscribing the profile to a List.

So, the thing that fixed the initial (client-side) identity call was removing

var _learnq = _learnq || [];

With that line gone it works fine and adds the custom properties as expected.

Any ideas why this should be the case?

Cheers,

Crac

Userlevel 4
Badge +11

@Caractacus Downes glad you were able to get it working! It sounds like what was happening was that the _learnq object was already defined globally on your page since you have included our klaviyo.js code. The identify snippet may have been scoped such that it was creating a new _learnq variable instead of using the globally defined one.

Once you took out the line that created a local _learnq variable (as a simple array), the script was able to use the globally defined _learnq object. Hope that makes sense!

Reply