Skip to main content
Solved

Klaviyo and GTM variable undefined

  • July 1, 2024
  • 1 reply
  • 62 views

Forum|alt.badge.img

Using the same tag below I can collect e-mails in Klaviyo. When trying to save the first_name to the profile it’s showing undefined. Any advise would be appreciated.

Thanks!

First name Listener Tag - triggers on DOM Ready

  `<script>
  (function () {
  var element = document.querySelector('input[name="firstname"]') 

   element.addEventListener("blur", function(e) {
  dataLayer.push({
                      'event': 'first_name', 
                    'first_name': e.target.value                   
              });
  }, true);
})();  
</script>`

Klaviyo Tracking Tag - triggers on custom event > all custom events

 `<script
  async type="text/javascript"
  src="//static.klaviyo.com/onsite/js/klaviyo.js?company_id=$$$$$"
  ></script>

<script>
  var _learnq = _learnq || [];
   _learnq.push(['identify', {
    '$email' : '{{dlv - email}}',
    '$first_name' : '{{dlv - first_name}}'
  }]);
 </script>`

Tag Assistant Data Layer

   `{
   event: "gtm.load",
   gtm: {
   uniqueEventId: 21,
   start: 1719803388240,
   element: "HTMLDivElement: html.html_boxed.responsive.av-preloader" +
         "-enabled.av-default-lightbox.html_header_top.html_logo_" +
         "left.html_main_nav_header.html_menu_right.html_large.ht" +
         "ml_header_sticky.html_header_shrinking_disabled.html_mo" +
         "bile_menu_tablet.html_header_searchicon_disabled.html_c" +
         "ontent_align_center.html_header_unstick_top.html_header" +
         "_stretch_disabled.html_av-overlay-side.html_av-overlay-" +
         "side-classic.html_av-submenu-noclone.html_entry_id_154." +
         "av-cookies-no-cookie-consent.av-no-preview.html_text_me" +
         "nu_active.avia_desktop.js_active.avia_transform.avia_tr" +
         "ansform3d.avia-webkit.avia-webkit-83.avia-chrome.avia-c" +
         "hrome-83 > body.page-template-default.page.page-id-154." +
         "rtl_columns.boxed.quattrocento.lora.theme-enfold.woocom" +
         "merce-js#top > div#wrap_all > div.all_colors#main > div" +
         ".avia-section.main_color.avia-section-default.avia-no-b" +
         "order-styling.avia-bg-style-scroll.avia-builder-el-1.el" +
         "_after_av_section.el_before_av_section.container_wrap.f" +
         "ullsize#av_section_2 > div.container",
   elementClasses: "container",
   elementId: "",
   elementTarget: "",
   triggers: "3,4,5",
   elementUrl: ""
  },
  first_name: "dwdwdwd",
  email: "wdwd@fwefef"
    }`

Expecting first name variable to show in Klaviyo. Showing as undefined.

Best answer by Kim Strauch

Hey @HardingB, my best hunch here is that it’s possible at the point you’re calling identify, the value of first_name is undefined? You might try adding some logging and/or checking the network tab to confirm the payload that is being sent over to Klaviyo’s /client/profiles API. Is the first_name not being provided or set to “undefined” there?

 

View original
Did this topic or the replies in the thread help you find an answer to your question?

1 reply

Kim Strauch
Klaviyo Employee
Forum|alt.badge.img+9
  • Klaviyo Employee
  • 91 replies
  • Answer
  • July 9, 2024

Hey @HardingB, my best hunch here is that it’s possible at the point you’re calling identify, the value of first_name is undefined? You might try adding some logging and/or checking the network tab to confirm the payload that is being sent over to Klaviyo’s /client/profiles API. Is the first_name not being provided or set to “undefined” there?