Stellaxius Knowledge Center
  • Home
  • About Us
    • Our Team
    • Our Responsibility
      • Equality
    • Certifications
  • Services
    • Salesforce Consulting and Implementation
    • Salesforce Assessment
    • Software Development and Systems Integration
    • Process and Business Analysis
    • Program and Project Management
    • MuleSoft Integration
    • Data & Analytics
  • Success Stories
  • Careers
  • Blog
Contact us
Blog Home
Blog Categories:
  • Salesforce
    • CPQ
    • Net Zero Cloud
    • Release Notes
    • Sales Cloud
    • Salesforce Certifications
    • Service Cloud
  • Analytics &
    AI
    • Data Analysis
    • Einstein
  • Business Analysis &
    Implementation
  • Integration &
    Mulesoft
  • Marketing
    • Account Engagement
      (Pardot)
    • Marketing Automation
  • People &
    Culture
    • Human resources
    • Social Responsibility
  • Development
No Result
View All Result
Blog Home
Blog Categories:
  • Salesforce
    • CPQ
    • Net Zero Cloud
    • Release Notes
    • Sales Cloud
    • Salesforce Certifications
    • Service Cloud
  • Analytics &
    AI
    • Data Analysis
    • Einstein
  • Business Analysis &
    Implementation
  • Integration &
    Mulesoft
  • Marketing
    • Account Engagement
      (Pardot)
    • Marketing Automation
  • People &
    Culture
    • Human resources
    • Social Responsibility
  • Development
No Result
View All Result
Stellaxius Knowledge Center
Home Marketing Account Engagement (Pardot)

Rebuilding the Pardot iFrame Script To Collect More and Better Data

When collecting data from forms with Salesforce Pardot, you don't always have to stick to Pardot's basic delivered information. You can go the extra mile, by rebuilding Pardot iFrame script to collect more and better data about your conversions! Find how in this post!

Alexandre DuartebyAlexandre Duarte
16th September 2020 - Updated on 13th March 2023
in Account Engagement (Pardot), Development
1
A A
0
Pardot iframe
14
SHARES
1.4k
VIEWS
Share on LinkedInShare on XShare on FacebookShare on Whatsapp

One of the main functions of Pardot is to capture the data users give us in forms, such as website forms, and make the most out of it in Pardot/Salesforce. In this post, I will explain to you how to take this data collection process to the next level! How? Telling you all about how to capture additional information related to the page where your forms are inserted, such as parts of the title, parts of the URL, among others. So, along with you, I will recreate the default Pardot iFrame script to be inserted into your pages so they can transfer data from the page where the iFrame is inserted to the iFrame Script, and finally to Pardot. Shall we start?

 

Rebuilding the Padot iFrame Script

A standard Pardot iFrame script provided to be implemented on your pages has this format:

<iframe src="https://go.pardot.com/l/xxxxxx/xxxx-xx-xx/xxxxx" width="100%" height="500" type="text/html" frameborder="0" allowTransparency="true" style="border: 0"></iframe>

The problem with the standard Pardot script is the transition of data between the page where the iframe is inserted and Pardot’s backend would violate browsers’ security rules, thus preventing us from capturing the data we want from the page. So, how can we solve this? Firstly, by rebuilding the iFrame script in JavaScript, collect the data we want from the page, and only then, transform it into an iFrame, with the data already inserted in the script via UTM. It sounds complicated, but I will do my best to make it clearer and easy to understand!

1st Part: Base Script

Below we have a base script, where we just assemble the iFrame with the fields that are sent by Pardot. You can see below that the variable “formUrl” transits the form link generated by Pardot and then the rest of the iFrame is assembled in the “document.write”, including at the end the variable “formUrl” that inserts the form link in the iFrame body.

<!-- iFrame Form -->
<script type="text/javascript">
  /* START - Mount the iFrame and capture the fields */
  var formUrl = "https://go.yourbusiness.com/l/xxxxx/xxxx-xx-xx/xxxxx"; /* Pardot link form */
  document.write('<iframe width="100%" height="348px" frameborder="0" style="border: 0;" src="' + formUrl); /* Opens the base structure */
  document.write('"></iframe>'); /* Close the base structure */
  /* END - Mount the iFrame and capture the fields */
</script>
<!-- iFrame Form -->

But that’s not what you came here for, right? We’ll insert captures of information from the page where the script is inserted and send them to Pardot using the UTM parameters.

2nd Part: Capturing the Page Title

To capture the title of the page where the script we created is inserted and send it through a UTM parameter to Pardot, we’ll need to insert in our code the excerpt “document.title.substring(0, 99)”, varying the substring to get the full title or just specific parts of it.

Besides, we’ll have to insert in our script a piece of code that links the UTM parameters to the iFrame, so that we are able to send the data we want to capture to Pardot through a hidden field which we will add to the form. We will do this through a unique ID.

Pardot Form Fields: Padot iFrame Script

Total Title

<!-- iFrame Form -->
<script type="text/javascript">
  /* START - Mount the iFrame and capture the fields */
  var fieldId = "Service_Interest"; /* ID hidden field in Pardot */
  var formUrl = " https://go.yourbusiness.com/l/xxxxx/xxxx-xx-xx/xxxxx ";"; /* Link form in Pardot */
  var ServiceInt = encodeURI(document.title.substring(0, 99)); /* Get the Total Title of the Page */
  document.write('<iframe width="100%" frameborder="0" id="myIframe" style="border: 0;" src="' + formUrl);
  document.write('?' + fieldId + '=' + ServiceInt); /* Insert the title last in the Service_Interest input */
  document.write('"></iframe>');
  /* END - Mount the iFrame and capture the fields */

  /* Capture UTMs from URL and send to iFrame */
  var iframe = document.getElementById('myIframe'); /* Connect UTMs to Pardot */
  iframe.src = iframe.src + window.location.search;
</script>
<!-- iFrame Form -->

The script captures the page title, inserts it in the “ServiceInt” variable, which in turn concatenates as UTM in the iFrame through the string “fieldId”. This string captures this information and sends it to the hidden field created in Pardot “Service_Interest”. There, we have the title inserted in the hidden field.

Partial Title

To capture parts of the page title, for example, to get the name of a product by cutting the name of the website, we need to adjust the substring of the document.title.substring(0, 99) code snippet to get from a certain number of characters defined by you.

Example:

Page Title: Stellaxius – Marketing Automation

We want to capture only “Marketing Automation” so that we can know which page the form was sent from. Our substring will look like this: document.title.substring(13, 99).

The ’13’ at the end of the substring refers to the number of characters and blanks we want to skip before the string captures the title text and the ‘99‘ is the character limit you want it to capture, in this case, the ‘99‘ says that we will capture everything after “Stellaxius – “.

Titles in Script

<!-- iFrame Form -->
<script type="text/javascript">
  /* START - Mount the iFrame and capture the fields */
  var fieldId = "Service_Interest"; /* ID hidden field in Pardot */
  var formUrl = "https://go.yourbusiness.com/l/xxxxx/xxxx-xx-xx/xxxxx";"; /* Link form in Pardot */
  var ServiceInt = encodeURI(document.title.substring(13, 99)); /* Get the Total Title of the Page */
  document.write('<iframe width="100%" frameborder="0" id="myIframe" style="border: 0;" src="' + formUrl);
  document.write('?' + fieldId + '=' + ServiceInt); /* Insert the title last in the Service_Interest input */
  document.write('"></iframe>');
  /* END - Mount the iFrame and capture the fields */

  /* Capture UTMs from URL and send to iFrame */
  var iframe = document.getElementById('myIframe'); /* Connect UTMs to Pardot */
  iframe.src = iframe.src + window.location.search;
</script>
<!-- iFrame Form -->

3rd Part: Capturing the URL of the Page

Another element that can ease the analysis of the data of a form submission when it’s not possible to capture the page title (when the titles are static, for example) is the capture of the URL of the page where the form is inserted. Here it is also possible to capture a full or partial URL, depending on your needs. To capture a URL we will use window.location.pathname.

Total URL

<!-- iFrame Form -->
<script type="text/javascript">
  /* START - Mount the iFrame and capture the fields */
  var fieldId = "Service_Interest"; /* Maps the field ID to Pardot */
  var formUrl = "https://go.yourbusiness.com/l/xxxxx/xxxx-xx-xx/xxxxx"; /* Pardot link form */
  var ServiceInt = encodeURI(window.location.pathname); /* Get the URL */
  document.write('<iframe width="100%" frameborder="0" id="myIframe" style="border: 0;" src="' + formUrl); /* Opens the base structure */
  document.write('&' + fieldId + '=' + ServiceInt); /* Insert the URL last in the Service_Interest input */
  document.write('"></iframe>'); /* Close the base structure */
  /* END - Mount the iFrame and capture the fields */

  /* Capture UTMs from URL and send to iFrame when they exist */
  var iframe = document.getElementById('myIframe');
  iframe.src = iframe.src + window.location.search;
</script> 
<!-- iFrame Form -->

In this case, we’ll capture the entire URL after the website domain (www.yourbusiness.com/), and it will look like this:

Pathname

Partial URL

You can also capture specific URL parts, such as the last part of it, disregarding the domain and subfolders. For that, our capture code changes a bit, as we need to add to it the “.split ” tag that parts the URL into pieces separated in between them by dots (.).

Further explaining and exemplifying, we would have to do the following: window.location.pathname.split(‘/’)[3]. In this case, the split (‘/’)[3] says that we only want the third part of the URL (after the .com domain), as you can see below:

Example:

Page URL: https://stellaxius.com/knowledgecenter/marketing-automation/the-best-marketing-automation-tools/

We want to capture only the last part “the-best-marketing-automation-tools/“, that is, part 3 (remember that the .com domain does not enter into this account). Then we’ll use window.location.pathname.split(‘/’)[3] . Our code will then look like this:

<!-- iFrame Form -->
<script type="text/javascript">
  /* START - Mount the iFrame and capture the fields */
  var fieldId = "Service_Interest"; /* Maps the field ID to Pardot */
  var formUrl = "https://go.yourbusiness.com/l/xxxxx/xxxx-xx-xx/xxxxx"; /* Pardot link form */
  var ServiceInt = encodeURI(window.location.pathname.split('/')[3]); /* Take the 3 part of the URL */
  document.write('<iframe width="100%" frameborder="0" id="myIframe" style="border: 0;" src="' + formUrl); /* Opens the base structure */
  document.write('&' + fieldId + '=' + ServiceInt); /* Insert the URL last in the Service_Interest input */
  document.write('"></iframe>'); /* Close the base structure */
  /* END - Mount the iFrame and capture the fields */

  /* Capture UTMs from URL and send to iFrame when they exist */
  var iframe = document.getElementById('myIframe');
  iframe.src = iframe.src + window.location.search;
</script> 
<!-- iFrame Form -->

Other variations:

Variations: Padot iFrame Script

Bonus Tip: iFrame with Automatic Height

One of the main headaches of using an iFrame is that we need by default to set a fixed height for displaying the content that will be inserted into it. In the case of Pardot forms it worsens because it is not enough to calculate the height of a form (fields and buttons), we also have to predict the areas of error messages, reCaptcha, and information actions inserted before or after the form. This generates a very blank space below the form, unbalancing the page where the form is inserted.

Padot iFrame Script

To solve this, at Stellaxius, we use the iFrameResizer, a set of scripts that automatically calculates the height of your iFrames on a page and individually sizes each one. It looks cool, right? Let’s see how to implement this in your Pardot!

Operation: Implement iFrameResizer in Pardot

To run the iFrameResizer two files javascript (.Js) are required. One is on the page where the iFrame is inserted, and the other is in the iFrame page (the template of Pardot). This is necessary to create the so-called “cross-domain”, so the browser understands that you are the real ‘ owner ‘ of both pages and allows the transit of information between them. Let’s understand the iFrameResizer scripts one by one:

  • iFrameResizer.min.js: this file will be inserted on the page of your website that will receive the iFrame that we created.
  • iFrameResizer.contentWindow.min.js: this other file will be inserted in the template of the Pardot form you use.

In addition to these two files it is necessary to insert in the CSS of the page where the iFrame will be displayed, the following CSS class:

iframe {
  width: 1px;
  min-width: 100%;
}

Once this is done, we need to call the iFrameResizer script to start loading. So, for this we must add the following excerpt to the page that will receive the iframe:

<script>
  iFrameResize({ log: false }, '#myIframe')
</script>

Note that there is an ID in this small script called “myIframe”, which will individually identify the scripts of your iFrames on the page. That is, if you have two iframes on the same page, you will need to call this script part with different IDs twice.

But how do we link this solution to our iFrame script? Below is an example of the application of the iFrameResizer to our script:

<!-- iFrame Form -->
<script type="text/javascript">
  /* INÍCIO - Monta o iFrame e captura os fields */
  var fieldId = "Service_Interest"; /* Mapeia o ID do field no Pardot */
  var formUrl = "https://go.yourbusiness.com/l/xxxxx/xxxx-xx-xx/xxxxx"; /* Link form no Pardot */
  var ServiceInt = encodeURI(window.location.pathname.split('/')[3]); /* Pega a 3 parte da URL */
  document.write('<iframe width="100%" frameborder="0" id="myIframe" style="border: 0;" src="' + formUrl); /* Abre a estrutura base */
  document.write('&' + fieldId + '=' + ServiceInt); /* Insere última a URL no input Service_Interest */
  document.write('"></iframe>'); /* Fecha a estrutura base */
  /* FIM - Monta o iFrame e captura os fields */

  /* Chamada para o iframeResizer para o ID */
  iFrameResize({ log: false }, '#myIframe');
  /* Captura os UTMs da URL e envia ao iFrame quando existirem */
  var iframe = document.getElementById('myIframe');
  iframe.src = iframe.src + window.location.search;
</script> 
<!-- iFrame Form -->

See in the script that we use the same ID that identifies our script also when calling the iFrameResizer.

Okay, now your iFrames have automatic height and are 100% responsive on mobile devices. Good job!

 

I hope you find this post useful! Subscribe to Stellaxius blog Knowledge Center to know more about Salesforce Pardot and its tailor-made design solutions! 🙂


Share1Tweet4Share6Send
Previous Post

6 Steps to get your Marketing Automation Implementation Ready!

Next Post

10 Tip Guide To Check If You Are Prepared For Marketing Automation

Alexandre Duarte

Alexandre Duarte

I am a Senior User Experience Designer & Information Architect with over fourteen years of experience in the areas of User Experience Design and Information Architecture which includes analyzing business and marketing requirements, designing work flows, site-maps and wireframes and documenting functional specifications.

Related Articles

Development

What is Business Process Model and Notation (BPMN)?

30th July 2024 - Updated on 28th February 2025
119
Tailoring Campaigns for Success with Marketing Cloud Account Engagement (Pardot)
Account Engagement (Pardot)

Tailoring Campaigns for Success with Marketing Cloud Account Engagement (Pardot)

6th June 2024
49
Salesforce Marketing Cloud Account Engagement vs. HubSpot Marketing Hub
Account Engagement (Pardot)

Salesforce Marketing Cloud Account Engagement vs. HubSpot Marketing Hub (2024)

9th April 2024
127
Next Post
10 Things You Need To Consider Before Betting on Marketing Automation

10 Tip Guide To Check If You Are Prepared For Marketing Automation

Top 3 Hottest Features of Salesforce Pardot Winter'21 Release!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stellaxius

At Stellaxius, we are focused on turning our customers into superheroes by offering you simple-to-use consulting services and implementing sustainable solutions that transform people through technology and knowledge. We believe success comes with strong human relations to help transform businesses, improve people’s lives and have an impact on our community.

Categories

  • Analytics & AI
  • Business Analysis & Implementation
  • Integration & MuleSoft
  • Marketing
  • People & Culture
  • Salesforce
  • Development

Subscribe to our Blog

  • Careers
  • Privacy Policy
  • Contact Us

© 2025 Stellaxius Knowledge Center. All rights reserved.

No Result
View All Result
  • Login
  • Sign Up
  • Salesforce
    • CPQ
    • Net Zero Cloud
    • Release Notes
    • Sales Cloud
    • Salesforce Certifications
    • Service Cloud
  • Analytics &
    AI
    • Data Analysis
    • Einstein
  • Business Analysis &
    Implementation
  • Integration &
    Mulesoft
  • Marketing
    • Account Engagement
      (Pardot)
    • Marketing Automation
  • People &
    Culture
    • Human resources
    • Social Responsibility
  • Development

© 2025 Stellaxius Knowledge Center. All rights reserved.

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms bellow to register

*By registering into our website, you agree to the Terms & Conditions and Privacy Policy.
All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Skip to content
Open toolbar Accessibility Tools

Accessibility Tools

  • Increase TextIncrease Text
  • Decrease TextDecrease Text
  • GrayscaleGrayscale
  • High ContrastHigh Contrast
  • Negative ContrastNegative Contrast
  • Light BackgroundLight Background
  • Links UnderlineLinks Underline
  • Readable FontReadable Font
  • Reset Reset
  • SitemapSitemap
  • FeedbackFeedback