Setup Enhanced Conversions for Leads using Data Layer in Google Tag Manager
In this article, I am going to talk about how to set up enhanced conversions for leads using the data layer in Google Tag Manager.
This process consists of the following four major steps as below:
- Configure your Google tag settings
- Enable enhanced conversions for leads in Google Ads
- Configure Enhanced Conversions for leads in Google Tag Manager
- Verify your setup and publish the container
#1 Configure your Google tag settings
Before you can set up enhanced conversions for leads, you will need to adjust your Google tag:
Follow the below steps.
Step-1: Navigate to the admin area of your GA4 property and click on “Data streams”
Step-2: Now select your web data stream.
Step-3: Click on the “Configure tag settings”.
Step-4: In the Configure tag settings, click “Manage automatic event detection”.
Step-5: Make sure that the ‘automatic event detection for “Form interactions” is turned on:
#2 Enable enhanced conversions for leads in Google Ads
Follow the steps below to enable enhanced conversions for leads for existing conversion action:
Step-1: Navigate to your Google Ads account, and click the ‘Goals‘ icon.
Step-2: Click the ‘Conversions’ drop-down in the section menu.
Step-3: Now click on the “Settings” tab.
Step-4: Click on “Enhanced conversions for leads”
Step-5: Click on the checkbox ‘Turn on enhanced conversions’ for leads.
Note: When you select Turn on enhanced conversions for leads, you’ll need to accept the customer data terms.
Step-6: Select View Terms next to “Customer data terms” and read the “Policies and Additional Terms for Customer Data”.
Step-7: Click the checkbox beside “I have read and accept the terms on behalf of my company”.
Step-8: Click Agree. You’ll notice your status updated as “Accepted”.
Step-9: Under ‘To start, select how you want to set up enhanced conversions’, select ‘Google Tag Manager’.
Step-10: Now click on “Save”.
#3 Configure Enhanced Conversions for leads in Google Tag Manager
To measure your enhanced conversions for leads in GTM, you need to do the following:
- Set up a conversion linker tag.
- Specify a data source for lead conversions.
- Create a new tag of type ‘Google Ads User-Provided Data Event’ in GTM
#3.1 Set up a Conversion Linker tag in Google Tag Manager
Follow the below steps
Step-1: Navigate to your GTM account.
Step-2: Click on ‘Tags’.
Step-3: Now click on “New” to create a new tag:
Step-4: Click Tag Configuration and select ‘Conversion Linker’.
Step-5: Click on triggering and click on “All Pages”.
Step-6: Rename your tag, Save, and publish your tag configuration.
#3.2 Specify a data source for lead conversions
Following are the three methods through which you can set up enhanced conversions for leads in GTM:
- Automatic Collection.
- Manual Configuration.
- Code Configuration.
You only need to choose one of the options.
We are going to use the code configuration option.
First, we need to store user-provided data as key-value pairs in a JavaScript variable.
The sample user data is shown below.
The second step is to push user-provided data to the data layer.
Following is the sample data layer code:
window.dataLayer = window.dataLayer || [];
dataLayer.push({
‘event’: ‘leadSubmission’,
‘userData’: leadsUserData
});
You should add the data layer push on the form submission event before the user is redirected to the thank you page.
This is because you want to capture and send the data at the exact moment the user submits the form, ensuring the most accurate and timely data collection for your conversion tracking.
Adding it to the thank you page might result in missed data capture if the user navigates away or closes the browser before the thank you page fully loads.
Here’s a simplified example of how you might implement this if you use the Gravity Form WordPress plugin for embedding forms on your website:
// Listen for the Gravity Form submission event
document.addEventListener(‘gform_confirmation_loaded’, function(event) {
// Assuming event.detail.formId is available and corresponds to your form’s ID
if (event.detail.formId === YOUR_FORM_ID) {
// Capture form data
var email = document.getElementById(‘input_YOUR_FORM_ID_X’).value; // Replace X with the field ID for the email
var phone_number = document.getElementById(‘input_YOUR_FORM_ID_Y’).value; // Replace Y with the field ID for the phone number
// Construct your data object
var leadsUserData = {
’email’: email,
‘phone_number’: phone_number,
// Include other fields as needed
};
// Push the data to the data layer
window.dataLayer = window.dataLayer || [];
dataLayer.push({
‘event’: ‘leadSubmission’,
‘userData’: leadsUserData
});
}
});
Make sure to replace YOUR_FORM_ID, X, and Y with the actual ID of your form and the specific input IDs for the email and phone number fields.
Follow these step-by-step instructions to add a data layer push on a form submission event before the user is redirected to the thank you page using Google Tag Manager (GTM).
This approach captures user input from a form and uses GTM to push this data into the data layer at the right moment during the form submission process.
Step-1: Navigate to your Google Tag Manager account and click on ‘Variables’.
Step-2: Now Click on “Configure” under built-in Variables.
Step-3: Now select all the check boxes under “Forms”.
Step-4: Now click on the “Tags” Tab.
Step-5: Click on the ‘New’ button to create a new tag:
Step-6: Name your tag and then click on ‘Tag configuration’.
Step-7: Select “Custom HTML” as a tag type.
Step-8: Enter your below JavaScript code in the HTML area.
Here’s a simplified example that pushes the email field into the data layer. Adjust the ID and field names as necessary:
Note: This code only captured the email address as user-provided data. You can modify the code to add extra user-defined parameters like First name, Last name, Phone number, etc.
<script>
document.addEventListener(‘submit’, function(event) {
var email = document.querySelector(‘[name=”your_email_field_name”]’).value;
window.dataLayer = window.dataLayer || [];
dataLayer.push({
‘event’: ‘leadSubmission’,
‘userData’: {
’email’: email
}
});
}, true);
</script>
Replace [name=”your_email_field_name”] with the actual name or ID selector of your email input field.
Step-9: Click on the trigger button to create a new trigger.
Step-10: Name your trigger and click on “Trigger Configuration”
Step-11: Select “Form Submission” as the trigger type.
Step-12: Now select condition “All Forms” from the radio button and then click on “Save”.
Step-13: Before publishing your changes, enter Preview mode in GTM to test the setup. This allows you to see in real-time how tags are fired without affecting live site visitors.
Step-14: Submit the Form: Go to the page with the form on your website while in Preview mode and submit the form.
Check Data Layer: Use GTM’s Preview mode panel or your browser’s developer tools to verify that the custom event that we created is fired.
The data layer should also be updated with the user’s email information upon form submission.
Debug if Necessary: If the data isn’t pushed as expected, double-check your trigger and tag configurations, ensuring they’re correctly set up to capture and push form submission data.
Step-15: Once you’ve confirmed that the data layer is correctly updated upon form submission, exit Preview mode and publish the changes in GTM to make the data layer push active on your live site.
Create data layer Variables in GTM:
For each piece of user data you want to track (e.g., email, phone number), create a Data Layer Variable in GTM. This tells GTM where to look in the data layer for the information it needs.
Step-1: Navigate to the ‘Variables’ tab in Google Tag Manager.
Step-2: Under “User-Defined Variables”, click on ‘New’.
Step-3: Name the variable and click on the “Variable configuration”:
Step-4: Select the variable type as a “Data Layer Variable”.
Step-5: Type “userData.email” under Data Layer Variable Name and click on ‘Save’.
Note: If your form has other details (e.g., first name, last name, phone number), you can repeat the same steps and create the data layer variables in GTM.
Create User-Provided Data variable in GTM
To create a new User-Provided Data variable in GTM, follow the below steps
Step-1: Navigate to the ‘Variables’ tab in Google Tag Manager:
Step-2: Under “User-Defined Variables”, click on ‘New’.
Step-3: Name the variable and click on the “Variable configuration”
Step-4: Select the variable type as “User-Provided Data”.
Step-5: Name the Variable and click on “Manual configuration”.
Step-6: Now click on the drop-down under “Email” and select the data layer variable that we created earlier.
Note: There are other fields as well in the configuration settings of the variable like below. If your form contains these variables you can reference them to the data layer variables in GTM that we created earlier.
Create a new tag of type ‘Google Ads User-Provided Data Event’ in GTM
Follow the below steps
Step-1: Navigate to your GTM container.
Step-2: In your “Workspace”, click ‘Tags’ from the navigation menu:
Step-3: Click ‘New’ to create a new tag:
Step-4: Rename your tag like “Google Ads User-Provided Data Event” and click on Tag Configuration:
Step-5: Now, under choose tag type click on “Google Ads”:
Step-6: Now click on ‘Google Ads User-Provided Data Event’.
Step-7: In “Tag Configuration”: In the field “Conversion ID”, supply your Google Ads Conversion Tracking ID.
Note: Make sure that this conversion action has the same conversion tracking ID and label as the conversion action that you enabled enhanced conversions for in your Google Ads account.
Step-8: Now, under the “User-provided data” drop-down, select the User-Provided Data variable that we created earlier.
Step-9: Now click on the “Trigger”:
Step-10: Select the trigger “Form Submission” that we created earlier while testing the custom html tag.
Step-11: Save the Tag.
#4 Verify your setup and publish the container
Verify your setup and publish your tag.
Before you publish your container, make sure that the tag behaves as intended using Preview mode.
If you are familiar with networking and hashing algorithms, you can also validate user data hashing.
Validate your tag setup using Preview mode
To validate your setup with Preview mode, follow these steps:
Step-1: In your Tag Manager workspace, click the ‘Preview’ button at the top. A new tab opens with Tag Assistant.
Step-2: Enter your website’s URL in Google Tag Assistant. Tag Assistant opens your website and the Tag Assistant summary. Keep both tabs open.
Step-3: On your website, fill out your form and click on “Submit”.
Step-4: Check the “Tag Assistant” summary. Your Google Ads User-Provided Data Event tag should be listed under the “Tags Fired” section in the summary.
If your tag is listed under “Tags Not Fired”, you need to adjust the tag’s trigger settings.
Step-5: Click on the tag to see which values were passed to the tag. Check if your input was received.
If the tag did not receive any input: Verify your implementation method.
If another tag fires before the Google Ads User-Provided Data Event tag, edit the “Form Submission” trigger. Set the “Wait for Tags” option.
Step-6: Now publish the workspace in Google Tag Manager.
Validate user data hashing using network calls
To validate that user data is submitted hashed using Google Chrome, follow these steps:
Step-1: Open your website and navigate to the form field you want to validate.
Step-2: Open the developer tools by right-clicking on the web page and select “Inspect”:
Step-3: Click on the “Network” Tab.
Step-4: Now click on the checkbox “Preserve log” and Disable cache”.
To make validation easier, clear any pre-existing network logs. By clicking on the clear button
Step-5: Now type “https://google.com/pagead” in the Filter box
Step-6: With your Network tab in the developer tools open, submit the data to the form field that you want to validate.
Result: You should see a request sent to https://google.com/pagead/form-data/ with a page parameter em=xyz.
The ’em’ parameter contains the hashed user data. Here the, ’em’ parameter is highlighted in “Yellow”
Once your tag collects the data parameters you need, Submit your changes in Tag Manager.
Congratulations!!!
You have successfully Set up enhanced conversions for leads using the data layer in Google Tag Manager.
In this article, I am going to talk about how to set up enhanced conversions for leads using the data layer in Google Tag Manager.
This process consists of the following four major steps as below:
- Configure your Google tag settings
- Enable enhanced conversions for leads in Google Ads
- Configure Enhanced Conversions for leads in Google Tag Manager
- Verify your setup and publish the container
#1 Configure your Google tag settings
Before you can set up enhanced conversions for leads, you will need to adjust your Google tag:
Follow the below steps.
Step-1: Navigate to the admin area of your GA4 property and click on “Data streams”
Step-2: Now select your web data stream.
Step-3: Click on the “Configure tag settings”.
Step-4: In the Configure tag settings, click “Manage automatic event detection”.
Step-5: Make sure that the ‘automatic event detection for “Form interactions” is turned on:
#2 Enable enhanced conversions for leads in Google Ads
Follow the steps below to enable enhanced conversions for leads for existing conversion action:
Step-1: Navigate to your Google Ads account, and click the ‘Goals‘ icon.
Step-2: Click the ‘Conversions’ drop-down in the section menu.
Step-3: Now click on the “Settings” tab.
Step-4: Click on “Enhanced conversions for leads”
Step-5: Click on the checkbox ‘Turn on enhanced conversions’ for leads.
Note: When you select Turn on enhanced conversions for leads, you’ll need to accept the customer data terms.
Step-6: Select View Terms next to “Customer data terms” and read the “Policies and Additional Terms for Customer Data”.
Step-7: Click the checkbox beside “I have read and accept the terms on behalf of my company”.
Step-8: Click Agree. You’ll notice your status updated as “Accepted”.
Step-9: Under ‘To start, select how you want to set up enhanced conversions’, select ‘Google Tag Manager’.
Step-10: Now click on “Save”.
#3 Configure Enhanced Conversions for leads in Google Tag Manager
To measure your enhanced conversions for leads in GTM, you need to do the following:
- Set up a conversion linker tag.
- Specify a data source for lead conversions.
- Create a new tag of type ‘Google Ads User-Provided Data Event’ in GTM
#3.1 Set up a Conversion Linker tag in Google Tag Manager
Follow the below steps
Step-1: Navigate to your GTM account.
Step-2: Click on ‘Tags’.
Step-3: Now click on “New” to create a new tag:
Step-4: Click Tag Configuration and select ‘Conversion Linker’.
Step-5: Click on triggering and click on “All Pages”.
Step-6: Rename your tag, Save, and publish your tag configuration.
#3.2 Specify a data source for lead conversions
Following are the three methods through which you can set up enhanced conversions for leads in GTM:
- Automatic Collection.
- Manual Configuration.
- Code Configuration.
You only need to choose one of the options.
We are going to use the code configuration option.
First, we need to store user-provided data as key-value pairs in a JavaScript variable.
The sample user data is shown below.
The second step is to push user-provided data to the data layer.
Following is the sample data layer code:
window.dataLayer = window.dataLayer || [];
dataLayer.push({
‘event’: ‘leadSubmission’,
‘userData’: leadsUserData
});
You should add the data layer push on the form submission event before the user is redirected to the thank you page.
This is because you want to capture and send the data at the exact moment the user submits the form, ensuring the most accurate and timely data collection for your conversion tracking.
Adding it to the thank you page might result in missed data capture if the user navigates away or closes the browser before the thank you page fully loads.
Here’s a simplified example of how you might implement this if you use the Gravity Form WordPress plugin for embedding forms on your website:
// Listen for the Gravity Form submission event
document.addEventListener(‘gform_confirmation_loaded’, function(event) {
// Assuming event.detail.formId is available and corresponds to your form’s ID
if (event.detail.formId === YOUR_FORM_ID) {
// Capture form data
var email = document.getElementById(‘input_YOUR_FORM_ID_X’).value; // Replace X with the field ID for the email
var phone_number = document.getElementById(‘input_YOUR_FORM_ID_Y’).value; // Replace Y with the field ID for the phone number
// Construct your data object
var leadsUserData = {
’email’: email,
‘phone_number’: phone_number,
// Include other fields as needed
};
// Push the data to the data layer
window.dataLayer = window.dataLayer || [];
dataLayer.push({
‘event’: ‘leadSubmission’,
‘userData’: leadsUserData
});
}
});
Make sure to replace YOUR_FORM_ID, X, and Y with the actual ID of your form and the specific input IDs for the email and phone number fields.
Follow these step-by-step instructions to add a data layer push on a form submission event before the user is redirected to the thank you page using Google Tag Manager (GTM).
This approach captures user input from a form and uses GTM to push this data into the data layer at the right moment during the form submission process.
Step-1: Navigate to your Google Tag Manager account and click on ‘Variables’.
Step-2: Now Click on “Configure” under built-in Variables.
Step-3: Now select all the check boxes under “Forms”.
Step-4: Now click on the “Tags” Tab.
Step-5: Click on the ‘New’ button to create a new tag:
Step-6: Name your tag and then click on ‘Tag configuration’.
Step-7: Select “Custom HTML” as a tag type.
Step-8: Enter your below JavaScript code in the HTML area.
Here’s a simplified example that pushes the email field into the data layer. Adjust the ID and field names as necessary:
Note: This code only captured the email address as user-provided data. You can modify the code to add extra user-defined parameters like First name, Last name, Phone number, etc.
<script>
document.addEventListener(‘submit’, function(event) {
var email = document.querySelector(‘[name=”your_email_field_name”]’).value;
window.dataLayer = window.dataLayer || [];
dataLayer.push({
‘event’: ‘leadSubmission’,
‘userData’: {
’email’: email
}
});
}, true);
</script>
Replace [name=”your_email_field_name”] with the actual name or ID selector of your email input field.
Step-9: Click on the trigger button to create a new trigger.
Step-10: Name your trigger and click on “Trigger Configuration”
Step-11: Select “Form Submission” as the trigger type.
Step-12: Now select condition “All Forms” from the radio button and then click on “Save”.
Step-13: Before publishing your changes, enter Preview mode in GTM to test the setup. This allows you to see in real-time how tags are fired without affecting live site visitors.
Step-14: Submit the Form: Go to the page with the form on your website while in Preview mode and submit the form.
Check Data Layer: Use GTM’s Preview mode panel or your browser’s developer tools to verify that the custom event that we created is fired.
The data layer should also be updated with the user’s email information upon form submission.
Debug if Necessary: If the data isn’t pushed as expected, double-check your trigger and tag configurations, ensuring they’re correctly set up to capture and push form submission data.
Step-15: Once you’ve confirmed that the data layer is correctly updated upon form submission, exit Preview mode and publish the changes in GTM to make the data layer push active on your live site.
Create data layer Variables in GTM:
For each piece of user data you want to track (e.g., email, phone number), create a Data Layer Variable in GTM. This tells GTM where to look in the data layer for the information it needs.
Step-1: Navigate to the ‘Variables’ tab in Google Tag Manager.
Step-2: Under “User-Defined Variables”, click on ‘New’.
Step-3: Name the variable and click on the “Variable configuration”:
Step-4: Select the variable type as a “Data Layer Variable”.
Step-5: Type “userData.email” under Data Layer Variable Name and click on ‘Save’.
Note: If your form has other details (e.g., first name, last name, phone number), you can repeat the same steps and create the data layer variables in GTM.
Create User-Provided Data variable in GTM
To create a new User-Provided Data variable in GTM, follow the below steps
Step-1: Navigate to the ‘Variables’ tab in Google Tag Manager:
Step-2: Under “User-Defined Variables”, click on ‘New’.
Step-3: Name the variable and click on the “Variable configuration”
Step-4: Select the variable type as “User-Provided Data”.
Step-5: Name the Variable and click on “Manual configuration”.
Step-6: Now click on the drop-down under “Email” and select the data layer variable that we created earlier.
Note: There are other fields as well in the configuration settings of the variable like below. If your form contains these variables you can reference them to the data layer variables in GTM that we created earlier.
Create a new tag of type ‘Google Ads User-Provided Data Event’ in GTM
Follow the below steps
Step-1: Navigate to your GTM container.
Step-2: In your “Workspace”, click ‘Tags’ from the navigation menu:
Step-3: Click ‘New’ to create a new tag:
Step-4: Rename your tag like “Google Ads User-Provided Data Event” and click on Tag Configuration:
Step-5: Now, under choose tag type click on “Google Ads”:
Step-6: Now click on ‘Google Ads User-Provided Data Event’.
Step-7: In “Tag Configuration”: In the field “Conversion ID”, supply your Google Ads Conversion Tracking ID.
Note: Make sure that this conversion action has the same conversion tracking ID and label as the conversion action that you enabled enhanced conversions for in your Google Ads account.
Step-8: Now, under the “User-provided data” drop-down, select the User-Provided Data variable that we created earlier.
Step-9: Now click on the “Trigger”:
Step-10: Select the trigger “Form Submission” that we created earlier while testing the custom html tag.
Step-11: Save the Tag.
#4 Verify your setup and publish the container
Verify your setup and publish your tag.
Before you publish your container, make sure that the tag behaves as intended using Preview mode.
If you are familiar with networking and hashing algorithms, you can also validate user data hashing.
Validate your tag setup using Preview mode
To validate your setup with Preview mode, follow these steps:
Step-1: In your Tag Manager workspace, click the ‘Preview’ button at the top. A new tab opens with Tag Assistant.
Step-2: Enter your website’s URL in Google Tag Assistant. Tag Assistant opens your website and the Tag Assistant summary. Keep both tabs open.
Step-3: On your website, fill out your form and click on “Submit”.
Step-4: Check the “Tag Assistant” summary. Your Google Ads User-Provided Data Event tag should be listed under the “Tags Fired” section in the summary.
If your tag is listed under “Tags Not Fired”, you need to adjust the tag’s trigger settings.
Step-5: Click on the tag to see which values were passed to the tag. Check if your input was received.
If the tag did not receive any input: Verify your implementation method.
If another tag fires before the Google Ads User-Provided Data Event tag, edit the “Form Submission” trigger. Set the “Wait for Tags” option.
Step-6: Now publish the workspace in Google Tag Manager.
Validate user data hashing using network calls
To validate that user data is submitted hashed using Google Chrome, follow these steps:
Step-1: Open your website and navigate to the form field you want to validate.
Step-2: Open the developer tools by right-clicking on the web page and select “Inspect”:
Step-3: Click on the “Network” Tab.
Step-4: Now click on the checkbox “Preserve log” and Disable cache”.
To make validation easier, clear any pre-existing network logs. By clicking on the clear button
Step-5: Now type “https://google.com/pagead” in the Filter box
Step-6: With your Network tab in the developer tools open, submit the data to the form field that you want to validate.
Result: You should see a request sent to https://google.com/pagead/form-data/ with a page parameter em=xyz.
The ’em’ parameter contains the hashed user data. Here the, ’em’ parameter is highlighted in “Yellow”
Once your tag collects the data parameters you need, Submit your changes in Tag Manager.
Congratulations!!!
You have successfully Set up enhanced conversions for leads using the data layer in Google Tag Manager.
My best selling books on Digital Analytics and Conversion Optimization
Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.
Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.
Attribution Modelling in Google Analytics and BeyondSECOND EDITION OUT NOW!
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.
Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.