Skip to main content
January 5, 2022
Solved

Using javascript to pass UTMs from an inbound URL into Klaviyo via their API

  • January 5, 2022
  • 14 replies
  • 1636 views

Hello,

We are using embedded Klaviyo forms on our marketing landing pages built with Zipify in Shopify.  I want to pass UTMs from the inbound URL via hidden fields in a Klaviyo embedded form to Klaviyo.  The reason for doing this is for marketing source attribution for a Profile.  However, Klaviyo support tells me that this is not supported.  They say the best way to accomplish this is to use javascript to get the UTMs parameters and push them into Klaviyo via their API.

I have a script that gets the UTMs (Source, Campaign, Medium, Content, Term) and then pushes those to Klaviyo. I need to activate this upon Button Submit for the Klaviyo Embedded Form.  Can anyone tell me how best to trigger the script upon Button Submit?

Thanks!

Roy

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

Hi Roy,

 

The token is set by the “klaviyo.js” snippet on your site (in this case it looks like it’s injected as part of our integration), if you’re able to publish forms to the page then the token should be set correctly. In this case I think there might be a few issues with this code in terms of scoping and naming:

  1. I’d recommend updating the line
    var _learnq = _learnq || [];
    to
    var _learnq = window._learnq || [];
    It looks like it’s being re-set to an empty array (you can see this when it prints in the console as [] rather than an object) when it enters the method so pushing items to it will not produce an Identify request via our Javascript library. Instead, this will set the “local” (to this method) variable for _learnq to the object defined by our Javascript library on the “window” scope.
  2. The line that sets the utm_id variable, utm_id = kevyal[1];, is referring to “kevyal” rather than “keyval” so it throws an error in the console when it runs. Renaming it to “keyval” should fix this.

After making these changes I added the script to the console directly, submitted the form, and it looks like it worked as expected!:

 

14 replies

January 25, 2022

Hi Walid,

Setting var _learnq = window._learnq || [] worked great, thank you very much!

Roy

Problem Solver I
February 14, 2022

Hello everyone, please I will need your guidance.

Great work you all are doing.

My name is Raph, and I just started learning everything about Klaviyo, so what I do is, for every topic I cover on Klaviyo academy, I watch YouTube videos for it and also come here to see common problems and how experts here proffered solutions.

So I just finished the API integration part of the course, though I’m not a developer, but I came here to learn a few issues that can arise around API integration and I saw this thread.

Everything you all are saying looks interesting, I don’t know anything about it but I want to learn these tech advanced skills to up my tech skills in Klaviyo and be able to land good clients/jobs.

So I need you to advice me.

To know how to solve problems like this, what tech skills do you think I need to start learning?

I just started learning HTML and CSS, do you think that when I’m done learning that, I will be able to solve complex problems like this?

I will be hoping to hear from anyone who can guide me with a few words.

Thank you very much for reading, hoping to get great responses from you all.

Raph.

David To
Klaviyo Employee
Klaviyo Employee
February 16, 2022

Hey @Mg_Raph,

As a non-developer, I believe learning HTML and CSS is a great start! Learning these two languages would offer a great starting point to understanding many of the basic logics in a variety of other languages such as Javascript, PHP, Python, etc. 

While HTML, CSS, and JavaScripts of considered front-end language, to get a better understanding of how APIs work you’ll want gain a better grasp on PHP, Python, Java, or Ruby as they are categorized as programming/back-end language. 

David

Problem Solver I
March 27, 2022

Thank you very much David. I’m doing pretty well learning Html and CSS. Hoping by the end of this week I will be doing Javascript. I’m really grateful for your guidance.