Unable to write custom properties to profiles using Identify API

  • 14 January 2022
  • 2 replies



I’m trying to take the UTMs passed in by the referring URL into custom properties on a profile.  My site is on Shopify so it’s tightly integrated with Klaviyo. 

I’m having a problem trying to save the utm_id from the referring URL using _learnq.push in an EventListener for a Submit button on a Klaviyo embedded form. _learnq is populated correctly in the debugger and returns 1 (screenshots attached). The Custom Properties are setup with default values on the embedded form (screenshot attached).

_learnq.push([‘indentify’, { 

   '$email' : e.detail.metaData["$email"],
   '$first_name' : e.detail.metaData["$first_name"],
   'Campaign ID' : utm_id

Campaign ID is not coming through to the profile, even though _learnq.push is returning 1. 

Any help would be greatly appreciated!



P.S. the referring URL is



Best answer by retention 14 January 2022, 18:56

View original

2 replies

Userlevel 7
Badge +29

@Roy J. - Not sure if this is the issue, but you had a typo in your parameter ‘identify” in your code snippet.  Try fixing that if it that works?

_learnq.push([‘indentify’, { 

   '$email' : e.detail.metaData["$email"],
   '$first_name' : e.detail.metaData["$first_name"],
   'Campaign ID' : utm_id


Possibly a better way to do this - all Klaviyo Signup Forms (embedded or popup/flyout) has a post-submit event klaviyoForms that you can listen to instead of looking for your general Submit button.  You may want to try that as there may be a race condition of the form being submitted before your event listener has time to pass the data to Klaviyo.  

The event invokes a few types that might be helpful (all in their doc, link below), but listed here to help others:

This event fires when a popup or flyout form initially displays on a page
This event fires when an embedded form loads on a page
This event fires when a visitor closes a form
This event fires when a visitor clicks a button on a form that is set to redirect them to a URL 
This event fires when a visitor submits the main conversion action of a form (e.g., the first email or SMS subscription action), and will only fire once per form 
This event fires when each step is submitted, and can fire multiple times per form 


See the documentation here for more info:


Hope this helps!


HI Joseph,

Thank you for your reply and for catching that typo.  I corrected that typo and am still having the problem.  I read the documentation link that you posted and that is the structure that I was already using.  Here is my entire code for the EventListener,

var event = new CustomEvent("klaviyoForms", {
  detail: {
    type: 'submit',
    formId: ‘FORMID',
    companyId: 'PUBLICKEY',
    metaData: {
      g: 'LISTID',
      $email: '',

 window.addEventListener("klaviyoForms", function(e) {
  if (e.detail.type == 'submit') {
    var _learnq = _learnq || [];
    var self = window.location.toString();
    var querystring = self.split("?");
    if (querystring.length > 1) {
      var pairs = querystring[1].split("&");
      var utm_id;
      for (i in pairs) {
        var keyval = pairs[i].split("=");
        switch (keyval[0]) {
          case 'utm_id':
            utm_id = kevyal[1];
        } // switch
      } // for

      _learnq.push(['identify', {
        '$email' : e.detail.metaData["$email"],
        '$first_name' : e.detail.metaData["$first_name"],
        'Campaign ID' : utm_id


    } // if
  } // if
}); // addEventListener

Can you see any other issues with this code?  

My Landing Page builder places this code at the top of the page, could that be an issue? I saw this instruction in the documentation → 

  • If you're using Shopify, paste the snippet into your theme.liquid file on a new line above the closing </body> tag. Note that if you are using custom product pages, you may need to add this snippet to a different theme file, or to your individual custom product pages.

Lastly, has your company implemented anything similar to this for UTM top of funnel marketing source attribution?  I would love to get this working and happy to hire someone to finish it.