Google Ads Attribution

Part 2: Capturing UTM information (and more) on the Website and sending it with form submissions


Capturing UTM information (and more) on the Website and sending it with form submissions

Our Prospect has clicked on a Google Ad link and is now browsing our Website. We want to do a few things here:

  • Store and persist the UTM data: It's likely that a visitor will browse multiple pages on a Website before submitting their information in a form. As soon as the visitor clicks a link on the website to visit another page all of the UTM information will be lost unless we store it first.
  • Ensure we have a unique user identifier: We want to be able to reference this visitor uniquely and have this user identifier known by Google Analytics so we can refer to the user when they convert.
  • Capture first and last contact data: We mentioned Multi-touch attribution. If a visitor clicks on an advert on Monday then clicks on another advert on Tuesday before submitting a form it would be helpful to track the multiple steps they take so, at a later stage, we can attribute outcomes to the different campaigns that have contributed to this Lead.
  • Augment the data with useful marketing metrics: In addition to the UTM data it would be helpful to get more insights about this visitor. For example: a list of all the pages they have visited on the Website and when they visited them; the country they are visiting from and their approximate location in that country and the browser they are using which can be helpful for making sure the Website content is optimised.
  • Send all the data when the visitor submits a form: When the visitor decides to take the next step we want to package-up all the data we have stored and send this to our CRM system.

Automation using Website Javascript

Fortunately all of this is possible using Javascript - small blocks of code that run in the browser and enhance the website experience.

We have created a script that provides all this functionality and it's available by adding this code to each website page:

<script async src='https://a.attribution.tools/js?key=DEMO&googleTrackingId=G-XXXXXXX'></script>

Please see this link for detailed documentation on the script functionality and parameters.

To take advantage of all the data captured, the Website owner includes hidden input fields with names or identities setup to match the different data items. Hidden input fields are - as their name implies - fields that can hold data and are sent along with the rest of the form data but are not visible to the website visitor.


Marketing Data Captured

The script creates these 25 data items. Website owners include them by including hidden input fields with the names or ids shown.

Data item Description Field Name or Id
utm_source The site that sent the traffic, for example: 'google' utm_source or attribution_utm_source
utm_medium The type of medium - like 'email' or 'social' utm_medium or attribution_utm_medium
utm_campaign The campaign name like 'Chinese New Year promotion' utm_campaign or attribution_utm_campaign
utm_term The search terms the visitor entered for example 'Deals near me' utm_term or attribution_utm_term
utm_content More specific information about what was clicked on. We set this up to be the Ad Group in Google Adwords in the first step. utm_content or attribution_utm_content
gclid The Google click identifier from the original Google Ad. gclid or attribution_gclid
network The Google network source: 'g' for Google search, 's' for a search partner, 'd' for the Display Network, 'u' for a Smart Shopping Campaign, 'ytv' for YouTube videos, 'yts' for YouTube search, or 'vp' for Google video partners network or attribution_network
client_id The Google Analytics Client Id - the unique identifier for this client from Google Analytics. client_id or attribution_client_id
user_id The unique user identifier we created for this user and passed to Google Analytics. user_id or attribution_user_id
page_visits A string listing all the pages this visitor has visited together with a timestamp. This is returned with delimiters to separate the different pages. Each entry is delimited with a '|' and the page and timestamp in each entry is delimited with a ';'. An example string:
'/home.html;1673093937|/products.html;1673094170|/product1.html;1673094216'
page_visits or attribution_page_visits
page_visit_count The total number of pages visited before this form was submitted. page_visit_count or attribution_page_visit_count
ip_address The IP address of this visitor. ip_address or attribution_ip_address
browser The browser name the visitor is using, for example 'Safari'. browser or attribution_browser
operating_system The Operating System the visitor is using, for example 'Windows'. operating_system or attribution_operating_system
device The visitor's device type: 'mobile', 'tablet' or 'desktop' - if available. device or attribution_device
country_code The 2 digit country code of the visitor, for example 'SG' for Singapore. country_code or attribution_country_code
city The name of the nearest city to this user - if available. city or attribution_city
latitude The approximate latitude of the visitor. latitude or attribution_latitude
longitude The approximate longitude of the visitor. longitude or attribution_longitude
timezone The visitor's timezone, like 'Asia-Singapore'. timezone or attribution_timezone
fc_utm_source The first contact utm_source for multi-touch attribution. fc_utm_source or attribution_fc_utm_source
fc_utm_medium The first contact utm_source for multi-touch attribution. fc_utm_medium or attribution_fc_utm_medium
fc_utm_campaign The first contact utm_medium for multi-touch attribution. fc_utm_campaign or attribution_fc_utm_campaign
fc_utm_term The first contact utm_term for multi-touch attribution. fc_utm_term or attribution_fc_utm_term
fc_utm_content The first contact utm_content for multi-touch attribution. fc_utm_content or attribution_fc_utm_content

An example of hidden fields that Website owners can add to their forms:

//Using an input with the id set for the 'utm_source' data item:
<input type="hidden" id="utm_source">

//The same input but setting the input name instead:
<input type="hidden" name="utm_source">

//Using an input with the alternative id format - with 'attribution_' at the start:
<input type="hidden" id="attribution_utm_source">

//Using an input with the name set and the alternative format:
<input type="hidden" name="attribution_utm_source">

Examples of this in action

Here are three demonstration pages to show the data capture in action. You can see for the first link we are passing the UTM values shown. utm_source set to google etc. Click on the first link to see the hidden form fields being populated.

For the second link we are setting different UTM values. utm_source is set to social. Click on the second link to see how the First Contact data is saved as well as the page count and list of pages browsed.

The third link has no additional URL parameters set. When you click on this link you can see the stored parameters from the previous requests are still available. In addition the page count should increase and the pages browsed show the additional demostration page.

https://www.attribution.tools/demo1.html?utm_source=google&utm_campaign=CNY_promotion&utm_term=promotions&utm_content=promo1

https://www.attribution.tools/demo2.html?utm_source=social&utm_campaign=NewStocks&utm_term=shoes&utm_content=stock9

https://www.attribution.tools/demo3.html

Congratulations again! We've completed the second part: we can now capture the UTM information as well as other valuable marketing data and send it to the CRM System when forms are submitted. On to Part 3:

  1. Adding UTM information to Google Ads links
  2. Capturing visitor and campaign information on the Website
  3. Storing visitor and campaign information in the CRM System
  4. Passing conversion events back to Google Ads

Additional documentation on the script can be found here.

References - Google Analytics User Identifiers

Google User ID Introduction: Measure activity across platforms with User-ID
Google: Sending User IDs: Send user IDs
Google tag API reference: Google tag API reference