Passing UTM values to iframe embedded forms | Community
Skip to main content
December 7, 2016
Question

Passing UTM values to iframe embedded forms

  • December 7, 2016
  • 4 replies
  • 12618 views

I'm currently looking to pass UTM values from URLs through hidden form fields. I'm currently testing various things and have used the script provided here​ by @Ryan Vong​ to capture the UTM values in a cookie.

It works on Marketo landing pages, but not currently on our main website, where we have Marketo forms embedded in iframes. As the form is not directly on the page, it can't 'see' the UTM values so isn't able to collect them.

I'm sure there is a workaround, but as I'm not a developer it would take me some time to figure out - I'm hoping a member of the community may already have a solution!

Thanks in advance.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

4 replies

Josh_Hill13
Level 10
December 7, 2016

Look for Sanford Whiteman 2 (FigureOne)​ 's solutions. I'd also suggest hiring a developer or asking webdev to help.

SanfordWhiteman
Level 10
December 7, 2016

A not uncommon problem, and thanks Josh for the @.

Passing the query string from the outer document to an inner IFRAME is as simple as augmenting the src of the IFRAME. However, you do not want to do this after the IFRAME has loaded, or you will cause it to reload, creating visible overhead for the lead and extraneous hits on the server. Instead, what I typically do is create a DIV container for the IFRAME on the page, with the base information hard-coded:

<div class="iframe-container" data-iframe-src="example.com/iframe.html" data-iframe-width="100%" data-iframe-height="700" data-iframe-frameborder="0"></div>

Then use JS to inject the IFRAME inside that container when we have the query string to add to the src.

Ande_Kempf
Level 2
March 1, 2018

@Sanford Whiteman​ would this work for IFRAMEs in Marketo landing pages? I'm running into a similar issue where we need to track the click within an IFRAME. Background: The IFRAME contains a quiz and there are a few variables on what content will display after x amount of questions are asked. We need to track how viewers got to the content piece from the quiz within the IFRAME. We placed JS into the IFRAME in the Marketing LP - but, either Marketo is appending the code and making it unusable or there's an error in the JS.

Would placing the IFRAME into a DIV container work for this use case?

SanfordWhiteman
Level 10
March 1, 2018

Would placing the IFRAME into a DIV container work for this use case?

Doesn't matter what the IFRAME is inside, it's still a separate document and subject the same cross-window/cross-domain security restrictions.

Is the IFRAME running under the same private parent domain as the main document (i.e. they both end with .example.com or .example.co.uk)?

Can you show me the actual URL where you have this running, with the attempt to add Munchkin to the inner IFRAME document?

Jon_Bourne-2
Level 2
December 8, 2016

Hi Ben​. I work with @Ryan​ and have also helped develop this script. Our team has been brainstorming regarding UTM tracking and reporting over the past few months, and we have rewritten this particular script from scratch to improve upon the methodolgy. (I suppose we need to update the blog post, too!)

Here is the latest version of the UTM tracking script: bit.ly/2gdKeTm

While it may not address your particular iframe use case, this version of the script is better than older versions in several ways:

  1. First, it adds the hidden form fields for you, so you don't have to add them manually on your forms.
  2. Also, the cookie is deleted upon successful form submission, so that the UTM values are logged only once.
  3. Next, the cookie domain is auto-detected so that you usually don't need to bother changing the default setting. (Note that this currently works for only a handful of TLDs. If you don't use a .com, .net, .org, .co.uk, .co or .us TLD, you'll want to set this manually at the top of the script. Hoping to include better domain detection in a future version.)
  4. Last but not least, the setup is much simpler and better explained. Your Marketo fields are easily mapped at the top of the script.

As for the iframe itself, @Sanford is correct that you can dynamically create the iframe inside a specific div and pass the query string into it. But why are you using an iframe in the first place? What are you trying to solve for? Is there a reason the default form embed code will not work directly on the page instead of using an iframe?

One final thought: the tracking script can only read cookies from the primary domain name where it is hosted. If you are hosting it, for example, in your Marketo instance at pages.example.com, the cookie created will be set for example.com rather than pages.example.com. This means that if/when the same script runs on your website at example.com, it can access the same cookie there as well. This is not true, however, when the two domains are different; the script can only read the tracking cookie for the same domain from which it was set.

(Incidentally, we're also working on a solution to merge records, known or anonymous, from different Munchkin-tracked domains into the same Marketo lead record. We have a working proof of concept, but it is not production-ready code yet. Ping me if you're interested.)

Josh​ and Sanford​​, thank you both for chiming in to help Ben.

SanfordWhiteman
Level 10
December 8, 2016
  1. Next, the cookie domain is auto-detected so that you can usually don't need to bother changing the default setting.

Jon, this functionality is broken. Recommend you read the blog posts here and here.

Jon_Bourne-2
Level 2
December 8, 2016

Sanford, you are correct in that it is insufficient to detect every possible TLD/public domain and, consequently, private domain. Regex only gets you so far. However, given that, to date, our team has controlled the installation of the script, I have not been too terribly concerned about this known issue; we usually will manually set the cookie domain when and where needed as opposed to relying on the auto-detect functionality.

That said, I appreciate the excellent research and write-ups you posted. Nice work! Since you have on your blog already granted permission for its use with appropriate attribution and copyright, I will probably include findPrivateSuffix() in the next iteration of this script.

December 8, 2016

@Josh Hill​, @Sanford Whiteman​, @Jon Bourne​ - many thanks for your helpful suggestions. I would prefer to embed the form directly on the page but it would require a lot of work editing existing pages.So will look into implementing your suggestion, Sandford.