How to prevent lazy loading from messing with your iframe embedded forms

Sometimes I come across these edge cases where a solution is discovered to an obscure or tricky problem, and I just have to share it, because if there’s even just one person out there that this article saves hours of headache, it was worth my 15 minutes to write it.

Here’s the problem in a nutshell. If you are using iframe embedded Account Engagement (Pardot) forms, one nice trick that you can use is embedding variables on the url in that iframe, it will fill in hidden (or visible) fields on your form. Here’s a simple example.

This is the original form:

<iframe  src="https://info.accountengagement.com/l/1997292/2023-04-26/7vvm" width="100%" height="500" type="text/html" frameborder="0" allowTransparency="true" style="border: 0"></iframe>

This is the form’s URL altered with a Salesforce campaign ID:

<iframe  src="https://info.accountengagement.com/l/1997292/2023-04-26/7vvm&campaign=7014y000000usUfAAI" width="100%" height="500" type="text/html" frameborder="0" allowTransparency="true" style="border: 0"></iframe>

The use case here might be that we use the same form on multiple locations and want to use the campaign ID to identify a specific campaign that the form in that location is associated with.

There are other tools out there like UTMGrabber (for WordPress) and UTMSimple (for anything else) that will dynamically insert variables onto the URL such as UTMs or referral links that are held in the first party cookie, which means that you can feed all kinds of useful data into your hidden fields.

This is all well and good, and works beautifully….until it doesn’t.

If your site has a plugin or javascript running that is intended for lazy-loading of site images, it has the potential to wreak havoc with your hidden field strategy, especially if you are dynamically generating the variables on the URL.

This is because your iframes have the potential of being rewritten as follows:

<iframe  data-src="https://info.accountengagement.com/l/1997292/2023-04-26/7vvm" width="100%" height="500" type="text/html" frameborder="0" allowTransparency="true" style="border: 0" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="></iframe>

What’s happening here is that the actual URL is being renamed as data-src and the src is replaced by a base64 encoded 1×1 gif image. The effect of this is that the dynamic URL components get tacked onto the URL with the gif image. And then the javascript you use on the form to parse the URL variables (javascript that you probably got from here), well, it just won’t work, because the URL it’s trying to parse is not a normal URL.

<scripttype="text/javascript">// Parse the URLfunction getParameterByName(name){     name = name.replace(/[[]/,"[").replace(/[]]/,"]");var regex =newRegExp("[?&]"+ name +"=([^&#]*)"),         results = regex.exec(location.search);return results ===null?"": decodeURIComponent(results[1].replace(/+/g," "));}// Give the URL parameters variable namesvar source = getParameterByName('utm_source');var medium = getParameterByName('utm_medium');var campaign = getParameterByName('utm_campaign');// Put the variable names into the hidden fields in the form. document.getElementsByName("utm_source").value = source; document.getElementsByName("utm_medium").value = medium; document.getElementsByName("utm_campaign").value = campaign;

 


 

This Pardot article written by:  Bill Fetter

Unfettered Marketing

A collection of random thoughts on how people, places and things in our fascinating world connect to sales and marketing, and what we can learn from it.

Original Pardot Article: https://www.unfetteredmarketing.com/post/how-to-prevent-lazy-loading-from-messing-with-your-iframe-embedded-forms

Find more great Pardot articles at https://www.unfetteredmarketing.com/blog

Pardot Experts Blog

We have categorized all the different Pardot articles by topics.

Pardot Topic Categories

More Pardot Articles

See all posts

 


 

This Pardot article written by:  Bill Fetter

Unfettered Marketing

A collection of random thoughts on how people, places and things in our fascinating world connect to sales and marketing, and what we can learn from it.

Original Pardot Article: https://www.unfetteredmarketing.com/post/how-to-prevent-lazy-loading-from-messing-with-your-iframe-embedded-forms

Find more great Pardot articles at https://www.unfetteredmarketing.com/blog