Skip to main content
Contributor I
January 26, 2022
Solved

How to add marketing code to sign up form

  • January 26, 2022
  • 2 replies
  • 162 views

Hi there,

I’m trying to create a pop-up sign up form where I’m asking for customers name, email and phone number. Straight forward enough.

But I also want to record the customers marketing channel against their record if they sign up.

What is the best way to do this? 

I tried adding some custom jquery that added it to an additional form field but the inputted value kept getting overwritten when I clicked on another field.

Is there a proper way to do this with Klaviyo?

My marketing channel/code will be held in local storage.

Thanks!

This topic has been closed for replies.
Best answer by MattS

UPDATE:

Just read the documentation on Klaviyo and have achieved this by using the addEventListener custom code :)

  var _learnq = window._learnq || [];
  window.addEventListener("klaviyoForms", function(e) { 
    if (e.detail.type == 'open') {
      _learnq.push(['identify', {
      'marketing-channel' : 'test',
    }]);
 }});

I did notice that the official documentation is missing a closing curly bracket, I’ve highlighted it in yellow.

https://help.klaviyo.com/hc/en-us/articles/360003953111-How-to-Add-Custom-JavaScript-Events-to-Forms

2 replies

MattSAuthorAnswer
Contributor I
January 27, 2022

UPDATE:

Just read the documentation on Klaviyo and have achieved this by using the addEventListener custom code :)

  var _learnq = window._learnq || [];
  window.addEventListener("klaviyoForms", function(e) { 
    if (e.detail.type == 'open') {
      _learnq.push(['identify', {
      'marketing-channel' : 'test',
    }]);
 }});

I did notice that the official documentation is missing a closing curly bracket, I’ve highlighted it in yellow.

https://help.klaviyo.com/hc/en-us/articles/360003953111-How-to-Add-Custom-JavaScript-Events-to-Forms

David To
Klaviyo Employee
Klaviyo Employee
January 27, 2022

Hey @MattS,

Thanks for bringing this to our attention! I’ve surfaced this with our documentation team to get it corrected!

Glad you were able to share your findings with the rest of the Community as well!

Thanks for being a part of the Klaviyo Community!

David