You can use our AFL UTM Tracker plugin to capture dynamic UTM parameters for your legacy HubSpot Forms embedded into your WordPress site.
You will be utilizing our Javascript Merge Tag feature to populate the UTM parameters into your HubSpot form hidden fields which will be then be saved into the HubSpot Contact property.
Minimum Requirements
- AFL UTM Tracker v2.23.0
- Hubspot Form v2 (legacy)
- WordPress v5.0.0
Steps
1. AFL UTM Tracker Settings
- 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 Setup
You will need to login to your Hubspot account.
Create Contact Properties
Here you will be creating contact properties so that UTM parameters can be saved into a Contact.
- Go to your Hubspot > Settings page.
- Data Management > Objects > Contacts.
- Setup > Properties > Manage Contact properties.
- Group tab > Create Group.
- Name: AFL UTM Tracker
- Properties tab > Create property.
- Property label: UTM Source
- Internal name: utm_source
- Object type: Contact
- Group: AFL UTM Tracker
- Field type: Single-line text
- Save.
- Properties tab > Create property.
- Property label: UTM Medium
- Internal name: utm_medium
- Object type: Contact
- Group: AFL UTM Tracker
- Field type: Single-line text
- Save.
- Properties tab > Create property.
- Property label: UTM Campaign
- Internal name: utm_campaign
- 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.

Edit Hubspot 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.
- Sidebar > Contact Properties > AFL UTM Tracker.
- Drag and drop the 3 properties to your form.
- Edit the UTM Source field.
- Enable the “Make this field hidden”.
- Default value: afl_utm_js:utm_source
- Edit the UTM Medium field.
- Enable the “Make this field hidden”.
- Default value: afl_utm_js:utm_medium
- Edit the UTM Campaign field.
- Enable the “Make this field hidden”.
- Default value: afl_utm_js:utm_campaign
- Update.


Create Contact Card
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.
- Add cards > Create card > Data highlight.
- Cart title: AFL UTM Tracker
- Properties > Add properties.
- Select the UTM Source, UTM Medium and UTM Campaign properties.
- Save.
- Save and exit.


3. Get your HubSpot Embed Code
- Login to your HubSpot account.
- Go to your Hubspot > Marketing > Forms.
- Select the form > Edit Form.
- Click on the Embed button on the top.
- Select the Embed code tab.
- Copy your portalId and formId value (we will be using these values in the next section).

4. Setup your WordPress Page
- Login to your WordPress admin dashboard.
- Add a “Custom HTML” block into your WordPress page.
- Paste our Javascript code from the next section into the Custom HTML block.
- Save page and clear page cache.
- Test your HubSpot form.

Javascript Code
You will need to change the values in the Javascript code.
- On Line 4, replace MY_DOMAIN_NAME with your website URL.
- On Line 9, replace the portalId property value with your value.
- On Line 10, replace the formId property value with your value.