Pardot UTM Parameter Capture Script Template

Get a ready-to-use UTM parameter capture script template for Pardot to store UTM values in Pardot and Salesforce.
Written by Axel
Updated 5 days ago

"I need a script to capture UTM parameters in Pardot forms. Is there a template I can use?"

Absolutely! UTM parameter tracking is crucial for understanding which marketing campaigns drive your conversions. Our ready-to-use script template makes it easy to capture these valuable insights directly in Pardot.

What This Script Does

This JavaScript snippet automatically captures UTM parameters from your URL and stores them in hidden fields on your Pardot forms. This ensures your campaign data follows leads throughout their journey, providing accurate attribution reporting.

The Script Template

For your convenience, we offer two ways to get the script:

  1. Do It Yourself: Copy and paste this template and customize it manually following the instructions below.
  2. Use Our Free Tool: For a simpler approach, visit our free UTM Parameters Pardot tool, enter your UTM field information, and get a customized version of the code ready to implement.

Copy and paste this script into your desired Pardot form inside "Below Form" and adjust the parameters to your needs - see two comments inside code:

<!-- Start Parameter Capture -->

<script type="text/javascript">
function getParameterByName(name) {
                name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
                var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
                    results = regex.exec(location.search);
                return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
            }
// Give the URL parameters (f.e. utm_source) variable names (f.e. source), add all UTM parameters needed (one parameter per line of code)
// Example: var PARAMETER = getParameterByName('PARAMETER-AS-SHOWN-IN-URL');
            var source = getParameterByName('utm_source');
            var medium = getParameterByName('utm_medium');
            var source = getParameterByName('utm_source');
            var medium = getParameterByName('utm_medium');
            var campaign = getParameterByName('utm_campaign');
            var term = getParameterByName('utm_term');
            var content = getParameterByName('utm_content');
//Put the variable names (f.e. source) into place, replace YOURFIELD with your field (f.e. UTM_Source). Make sure to use the field and not name: For this go to Account Engagement Settings - Prospect Fields - column Field (not column Name)
// Example: document.querySelector('.PARDOT-COLUMN-NAME input[type="hidden"]').value = PARAMETER;
            document.querySelector('.UTM_Source input[type="hidden"]').value = source;
            document.querySelector('.UTM_Medium input[type="hidden"]').value = medium;
            document.querySelector('.UTM_Campaign input[type="hidden"]').value = campaign;
            document.querySelector('.UTM_Term input[type="hidden"]').value = term;
            document.querySelector('.UTM_Content input[type="hidden"]').value = content;
            document.querySelector('.UTM_Source_First input[type="hidden"]').value = source;
            document.querySelector('.UTM_Medium_First input[type="hidden"]').value = medium;
            document.querySelector('.UTM_Campaign_First input[type="hidden"]').value = campaign;
            document.querySelector('.UTM_Term_First input[type="hidden"]').value = term;
            document.querySelector('.UTM_Content_First input[type="hidden"]').value = content;

        </script>
        
<!-- End Parameter Capture -->

How To Customize the Script

The script includes helpful comments that guide you through the customization process:

  1. Define Your Parameters:
    • The first comment section explains how to map URL parameters to variables
    • Each UTM parameter is already set up with var source = getParameterByName('utm_source') and similar lines
    • You can add additional custom parameters by following the pattern
  2. Configure Your Field Names:
    • The second comment section is crucial - it shows how to map variables to your specific Pardot fields
    • Replace the UTM_Source, UTM_Medium, etc. with your actual Pardot field classes
    • To find the correct field names, go to Account Engagement Settings > Prospect Fields and look at the "Field" column (not the "Name" column)
  3. First Touch vs. Current Touch:
    • The script includes both current UTM values and "First" versions (UTM_Source_First)
    • This allows you to track both the first and most recent touchpoints in a prospect's journey

Implementation Steps

  1. Create Hidden Fields in Pardot:
    • Navigate to Pardot Admin settings - prospect fields
    • Create UTM fields matching those you chose in the script: UTM_Source, UTM_Medium, UTM_Campaign, UTM_Term, UTM_Content
    • Also create "First" versions of each field: UTM_Source_First, etc. - if needed
    • Set field type as "Text"
  2. Add Hidden Fields to Your Form(s):
    • Edit your Pardot form
    • Add all the UTM fields you created
    • Mark them as "Hidden" fields
  3. Implement the Script:
    • Add the script to your form layout template or
    • Add it to a specific Pardot form in the "Below Form" section

Common UTM Parameters

Parameter Purpose Exampe

utm_source

Identifies the source of your traffic

google, facebook, newsletter

utm_medium

Identifies the marketing medium

cpc, social, email

utm_campaign

Identifies a specific campaign

spring_sale, product_launch

utm_content

Differentiates ads/links pointing to the same URL

banner_ad, text_link

utm_term

Identifies paid search keywords

marketing_automation, b2b_software

Next Steps

With this script implemented, your Pardot forms will now capture UTM parameters, allowing you to track which campaigns drive form submissions. Use this data to measure campaign effectiveness and optimize your marketing spend.

Need help implementing this script or with other Pardot topics? Get in touch with our team for personalized assistance.

Did this answer your question?