You can use our AFL UTM Tracker plugin to populate dynamic UTM parameters into your HubSpot Forms.
This documentation is only for WordPress sites who have installed the HubSpot WordPress plugin and they are using the HubSpot Form block or shortcode to insert the form into the page.
If you are manually inserting the HubSpot form via manual HTML, then follow the documentation here:
Minimum Requirements
- AFL UTM Tracker v2.23.0
- HubSpot WordPress plugin v11.3.16
- WordPress v5.0.0
Steps
Let’s summarize the steps to populate the UTM parameters into your HubSpot Form v4.
- Enable the “Javascript Merge Tag” feature under the AFL UTM Tracker plugin settings.
- In your HubSpot settings, create Contact Properties for the UTM parameters.
- In your HubSpot settings, display the UTM parameters as Contact Card.
- In your HubSpot Form, add the UTM parameter properties as Hidden Fields.
- Add the HubSpot block into your WordPress page.
- Add our Appfromlab Javascript Code.
- Test your HubSpot form.
1. Enable the Javascript Merge Tag feature
- Login to your WordPress Admin dashboard.
- Go to AFL UTM Tracker > Settings page.
- Under Attribution section, enable the Javascript Merge Tag feature.
- Save settings.
- Clear all page cache from your caching plugin.
2. HubSpot: Create Contact Properties for UTM parameters
Here you will be creating contact properties so that UTM parameters can be saved into a Contact.
- Login to your HubSpot account > Settings page.
- Data Management > Objects > Contacts.
- Setup > Properties > Manage Contact properties.
- Group tab > Create Group.
- Name: AFL UTM Tracker
NOTE: For the Internal Name below, we will use our prefix "afl_" so that it does not conflict with HubSpot properties and HubSpot own UTM tracking script.
Create Properties for Last Touch UTM Parameters
- Properties tab > Create property.
- Property label: AFL UTM Source
- Internal name: afl_utm_source
- Object type: Contact
- Group: AFL UTM Tracker
- Field type: Single-line text
- Save.
- Properties tab > Create property.
- Property label: AFL UTM Medium
- Internal name: afl_utm_medium
- Object type: Contact
- Group: AFL UTM Tracker
- Field type: Single-line text
- Save.
- Properties tab > Create property.
- Property label: AFL UTM Campaign
- Internal name: afl_utm_campaign
- Object type: Contact
- Group: AFL UTM Tracker
- Field type: Single-line text
- Save.

Create Properties for First Touch UTM Parameters
- Properties tab > Create property.
- Property label: AFL UTM Source (First)
- Internal name: afl_utm_source_first
- Object type: Contact
- Group: AFL UTM Tracker
- Field type: Single-line text
- Save.
- Properties tab > Create property.
- Property label: AFL UTM Medium (First)
- Internal name: afl_utm_medium_first
- Object type: Contact
- Group: AFL UTM Tracker
- Field type: Single-line text
- Save.
- Properties tab > Create property.
- Property label: AFL UTM Campaign (First)
- Internal name: afl_utm_campaign_first
- Object type: Contact
- Group: AFL UTM Tracker
- Field type: Single-line text
- Save.

Want to populate more attribution data?
Refer to our Javascript Merge Tag list to populate First Touch UTM parameters, Last Touch UTM parameters, click identifiers (gclid, fbclid, msclkid) and other attribution data.
3. HubSpot: Create Contact Card to display UTM parameters
Here is how you can display the UTM parameters in an individual Contact view.
- Go to your HubSpot > Settings page.
- Data Management > Objects > Contacts.
- Record Customization tab > Default view.
Create Card for Last Touch UTM parameters
- Add cards > Create card > Data highlight.
- Cart title: AFL UTM Tracker (Last Touch)
- Properties > Add properties.
- Select the AFL UTM Source property.
- Select the AFL UTM Medium property.
- Select the AFL UTM Campaign property.
- Save.
Create Card for First Touch UTM parameters
- Add cards > Create card > Data highlight.
- Cart title: AFL UTM Tracker (First Touch)
- Properties > Add properties.
- Select the AFL UTM Source (First) property.
- Select the AFL UTM Medium (First) property.
- Select the AFL UTM Campaign (First) property.
- Save.
- Save and exit.

4. HubSpot: Add Hidden Fields to your form
Here you will be adding the Contact Properties which you have just created into your form.
- Go to Hubspot > Marketing > Forms.
- Select your form.
Hidden Fields for Last Touch UTM parameters
- Add to Form > Properties.
- Search Property > AFL UTM Source.
- Default value: afl_utm_js:utm_source|default:none
- Hidden field: Enable
- Add to Form > Properties.
- Search Property > AFL UTM Medium
- Default value: afl_utm_js:utm_medium|default:none
- Hidden field: Enable
- Add to Form > Properties.
- Search Property > AFL UTM Campaign
- Default value: afl_utm_js:utm_campaign|default:none
- Hidden field: Enable
Hidden Fields for First Touch UTM parameters
- Add to Form > Properties.
- Search Property > AFL UTM Source (First).
- Default value: afl_utm_js:utm_source_1st|default:none
- Hidden field: Enable
- Add to Form > Properties.
- Search Property > AFL UTM Medium (First)
- Default value: afl_utm_js:utm_medium_1st|default:none
- Hidden field: Enable
- Add to Form > Properties.
- Search Property > AFL UTM Campaign (First)
- Default value: afl_utm_js:utm_campaign_1st|default:none
- Hidden field: Enable
Review and update form and published changes.


5. Add the HubSpot Form into your WordPress page
Please note that HubSpot has two versions of their form (the new v4 and legacy v2) and hence will require using two different solutions.
Adding HubSpot Form via Block method
- Login to your WordPress admin dashboard.
- Edit your Contact page.
- Add the “HubSpot Form” block.
- Choose a form.
Adding HubSpot Form via Shortcode method
- Login to your WordPress admin dashboard.
- Edit your Contact page.
- Go to the HubSpot > Forms page.
- Hover your mouse over a form > Click on the “Embed” button.
- Click on the “WordPress short code” tab.
- It will look something like below. Do take note of the version.
V4 Shortcode
[hubspot type="form" portal="00000" id="xxxxxxxx" version="v4"]
V2 Shortcode
[hubspot type="form" portal="00000" id="xxxxxxxx"]
6. Get our Appfromlab Javascript Code
For HubSpot Form v4
- Add a new “Custom HTML” block below the HubSpot Form.
- On Line 3, replace MY_DOMAIN_NAME with your website URL.
- Paste the code below in the block.
- Save page.
- Test form.
For HubSpot Form v2
- Add a new “Custom HTML” block below the HubSpot Form.
- On Line 3, replace MY_DOMAIN_NAME with your website URL.
- Paste the code below in the block.
- Save page.
- Go to your functions.php and add the PHP snippet below.
- This will modify the HubSpot Javascript payload to call our Javascript API.
- Test your form.