If you are running an ecommerce store then Klaviyo is a must for your email marketing.  With very little work you should be able to create a targeted offer to your existing buyers that pays for many months of their service.

However, if you are doing any lead generating you’ll find that their forms use some javascript that creates a problem for services like LeadPages where you normally just paste the HTML optin code.  Until Klaviyo is natively integrated in to Leadpages (like it is with OptiMonk) then you can use this little script to make the magic happen.

You’ll want to install a copy of this script for each list and thank you page that you have setup.  Using your FTP server upload it your site with a name that ends in .php


  1. Line 4 – get your API key from https://www.klaviyo.com/account#api-keys-tab.  Create one and name it to something you will remember.
  2. Line 5 – get your Klaviyo list ID by clicking the List settings on the list you want people to be added to.   It will be about 6 characters long and can also be found in the URL: https://www.klaviyo.com/list/mL4Ktx/settings for example
  3. Line 6 – set the thank you page that you want to deliver people to after they optin.  Make sure it is a valid URL with the HTTP:// added to the front.
  4. Final step – in your leadpages form paste the code below.  Just change the URL for where you installed the script above.  You can delete the firstname section if you are just capturing the email address.

How it works – Basically the email is submitted to this script which then adds it to Klaviyo via the API.

If you need help with scripts like this I’d highly recommend reaching out to Norio De Sousa (TechAssassin.co) who originally created this script for me.

12 thoughts on “Using Klaviyo Forms with Lead Pages”

  1. Thank you, Darren

    This blog is a fantastic resource, Thank you! However, I recommend you make one change. I had to use a private Klaviyo API Key rather than the six digit public one you describe. Not sure if that was something that the Nepali Developer I used did due to an error on his behalf or whether your documentation requires an update? (And no I did the private API Key myself so he does not have access to it!)

    PS: How would I go about making this a secure form?


  2. Hi Darren, great workaround, worked perfectly and I actually implemented it into OptimzePress + Klaviyo.

    Do you know how could I include Last Name in the scripts as well or is this something I’d need to reach out to Norio?


  3. Hey Darren,
    I apparently costs $1,800 to have Norio implement this…

    I’m having a hard time figuring out where to place the code “in the leadpage form” on my WP’s site according to step 4.
    Am I looking for the form on my websites server or is it done from the backend of leadpages somehow?

    Hoping to be able to make this work myself.
    Just a little stuck.


  4. Darren, can you expand on this: “You’ll want to install a copy of this script for each list and thank you page that you have setup. Using your FTP server upload it your site with a name that ends in .php” I’m using a WP site and don’t really want to mess with the FTP server. If I’m installing a copy for each list, wouldn’t that need to go into Klaviyo somewhere. Regarding the thank you pages, I guess i just insert the code in the header or footer? Any help you can provide would be much appreciated…

  5. Darren
    this code works for me when using optmizepress to klaviyo

    got this from the coder and it is delivering emails to klaviyo.


    // settings
    $klaviyo_apikey = 'enter_your_key_here';
    $klaviyo_listid = 'enter_your_list_id_here';
    $goto = 'http://www.example.com/thankyou/&#039;;

    echo "”;
    // subscribe
    if (trim($_POST[’email’])) {
    $email = trim($_POST[’email’]);
    // first name?
    $first_name = (trim($_POST[‘firstname’])) ? trim($_POST[‘firstname’]) : ‘Friend’;
    // subscribe
    $array = array(
    ‘api_key’ => $klaviyo_apikey,
    ’email’ => $email,
    ‘properties’ => array(‘$first_name’ => $first_name),
    ‘confirm_optin’ => ‘false’
    $ch = curl_init();

    //set the url, number of POST vars, POST data
    curl_setopt($ch,CURLOPT_URL, ‘https://a.klaviyo.com/api/v1/list/’.$klaviyo_listid.’/members’);
    curl_setopt($ch,CURLOPT_POST, count($array));
    curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($array));

    //execute post

    $result = curl_exec($ch);

    //close connection

    // redirect

    print “”;
    // header(‘Location: ‘.$goto);

    echo “”;

    I want to thank you for posting this info here.
    it saved me days, weeks and months of research
    and hundreds of dollars of tech guy.

    thanks a lot.

Leave a Comment

Your email address will not be published.