Klaviyo Form not working - using API


(Tudor Pangal) #1

I set up this optin form on a clickfunnels page following these instructions:

Unfortunately, after signing up, people aren’t getting added to the list.

Klaviyo support told me that I need to have the following on the optin page:

Should I be using that code if I’m integrating using a API key?

Is there anything that I’m missing? Is there any other reason why my form isn’t working?

Thanks!


(sin) #2

Thank you for posting about this @tudor really appreciate bringing that issue to my sight once again… almost forgot about the whole thing… I believe maybe at some point Klaviyo maybe made some change to their API which prevented the old plugin to not work, and since it has been quite long time never used them I had no clue at all.

Will be working on a solution to that will update you today.


(Tudor Pangal) #3

Yassine thanks so much for getting back to me.

Appreciate your looking into this. :smile:

Tudor


(Tudor Pangal) #4

Hello Yassine,
I was wondering if you had a chance to look at the code.
Any idea if it’s something that can be fixed soon. or should I look for another tool to make this work?
Really appreciate your help. :slight_smile:
Thanks!


(Marta) #5

Hi Yassine! I just wanted to check with you - I setup the plugin to send the info to Klaviyo but none of my tests worked. Since I just installed it for the first time, I can’t say if there is a problem because something got changed since plugin got written or I did something wrong. I followed instructions, they are pretty straight forward. So, just wanted to double-check - are you aware of any changes? Thank you!


(alex) #6

Hey Yassine. You can use the Klaviyo external subscribe link rather than the api which will not expose the private api Key. Let me know if this works for all

<script>
function send_to_klaviyo() {
var email="", fname="", lname="", phone="", city="", state="", country="", zip="";

    var emailbox = document.getElementsByName("email")[0];
if (emailbox == null)
return; // no email :o
email = emailbox.value;

var fnamebox = document.getElementsByName("first_name")[0];
if (fnamebox != null)
fname = fnamebox.value;

var lnamebox = document.getElementsByName("last_name")[0];
if (lnamebox != null)
lname = lnamebox.value;

var phonebox = document.getElementsByName("phone")[0];
if (phonebox != null)
phone = phonebox.value;

var citybox = document.getElementsByName("city")[0];
if (citybox != null)
city = citybox.value;

var statebox = document.getElementsByName("state")[0];
if (statebox != null)
state = statebox.value;

var countrybox = document.getElementsByName("country")[0];
if (countrybox != null)
country = countrybox.value;

var zipbox = document.getElementsByName("zip")[0];
if (zipbox != null)
zip = zipbox.value;

    var settings = {
        "async": true,
        "crossDomain": true,
        "url": "https://manage.kmail-lists.com/subscriptions/external/subscribe",
        "method": "POST",
        "headers": {
            "content-type": "application/x-www-form-urlencoded",
            "cache-control": "no-cache"
        },
        "data": {
            "g": "LISTID",
            "$fields": "first_name,last_name,phone,city,state,country,zip,source",
            "email": email,
            "$first_name": fname,
            "$last_name": lname,
            "state": state,
            "country": country,
            "zip":zip,
            "$source": "clickfunnels"
        }
    };

    $.ajax(settings).done(function (response) {
        console.log(response);
    });
}

window.addEventListener("load", function() {
var divs = document.getElementsByTagName("div");
for (i = 0; i < divs.length; i++)
{
var div = divs[i];
if (div.getAttribute("data-title") == "optin button" || div.getAttribute("data-de-type") == "button") {
div.onclick = function() {
// Send the lead to Klaviyo
send_to_klaviyo();
};
}
}
});

</script>

(sin) #7

Hi there,

I’ve gone ahead and updated the Plugin code :slight_smile: to make it fix the issues it had, check the updated instructions at: