Setup Enhanced Conversions for Leads using Data Layer in Google Tag Manager

Do you want expert help in setting up/fixing GA4 and GTM?

If you are not sure whether your GA4 property is setup correctly or you want expert help migrating to GA4 then contact us. We can fix your website tracking issues.

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:

  1. Configure your Google tag settings
  2. Enable enhanced conversions for leads in Google Ads
  3. Configure Enhanced Conversions for leads in Google Tag Manager
  4. 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

click on Data streams

Step-2: Now select your web data stream.

Now select your web data stream

Step-3: Click on the “Configure tag settings”. 

Configure tag settings

Step-4: In the Configure tag settings, click “Manage automatic event detection”.

Manage automatic event detection

 Step-5: Make sure that the ‘automatic event detection for “Form interactions” is turned on:

‘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.

google ads goals

Step-2: Click the ‘Conversions’ drop-down in the section menu.

Click the Conversions drop down

Step-3: Now click on the “Settings” tab.

Settings tab

Step-4: Click on “Enhanced conversions for leads”

Enhanced conversions for leads

Step-5: Click on the checkbox ‘Turn on enhanced conversions’ for leads.

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’.

select ‘Google Tag Manager

Step-10: Now click on “Save”.

click on Save

Do you want expert help in setting up/fixing GA4 and GTM?

If you are not sure whether your GA4 property is setup correctly or you want expert help migrating to GA4 then contact us. We can fix your website tracking issues.

#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:

  1. Set up a conversion linker tag.
  2. Specify a data source for lead conversions.
  3. 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’.

Click on Tags

Step-3: Now click on “New” to create a new tag:

click on New to create a new tag

Step-4: Click Tag Configuration and select ‘Conversion Linker’.

select ‘Conversion Linker

Step-5: Click on triggering and click on “All Pages”.

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:

  1. Automatic Collection.
  2. Manual Configuration.
  3. Code Configuration.

You only need to choose one of the options.

three methods through which you can set up enhanced conversions for leads in GTM

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 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’.

Variables

Step-2: Now Click on “Configure” under built-in Variables.

Configure

Step-3: Now select all the check boxes under “Forms”.

select all the check boxes under Forms

Step-4: Now click on the “Tags” Tab.

gtm tags

Step-5: Click on the ‘New’ button to create a new tag:

create a new tag

Step-6: Name your tag and then click on ‘Tag configuration’.

Name your tag and then click on ‘Tag configuration

Step-7: Select “Custom HTML” as a tag type.

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.

custom html tag gtm

Step-9: Click on the trigger button to create a new trigger.

create a new trigger

Step-10: Name your trigger and click on “Trigger Configuration”

Name your trigger

Step-11: Select “Form Submission” as the trigger type.

Select Form Submission as the trigger type

Step-12: Now select condition “All Forms” from the radio button and then click on “Save”.

Now select condition All Forms

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.

enter Preview mode in GTM

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.

Check Data Layer

The data layer should also be updated with the user’s email information upon form submission.

The data layer should also be updated with the users 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.

Variable tab in Google Tag Manager

Step-2: Under “User-Defined Variables”, click on ‘New’.

User Defined Variables

Step-3: Name the variable and click on the “Variable configuration”:

Name the variable and click on the Variable configuration

Step-4: Select the variable type as a “Data Layer Variable”.

Select variable type as a Data Layer Variable

Step-5: Type “userData.email” under Data Layer Variable Name and click on ‘Save’.

Type userData.email under Data Layer Variable Name

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:

Navigate to the Variable tab in Google Tag Manager

Step-2: Under “User-Defined Variables”, click on ‘New’.

new User Defined Variables

Step-3: Name the variable and click on the “Variable configuration”

user provided data variable

Step-4: Select the variable type as “User-Provided Data”.

variable type as User Provided Data

Step-5: Name the Variable and click on “Manual configuration”.

click on Manual configuration

Step-6: Now click on the drop-down under “Email” and select the data layer variable that we created earlier.

Now click on the drop down under Email

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.

reference them to the data layer variables in GTM

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:

click Tags from the navigation menu

Step-3: Click ‘New’ to create a new tag:

create a new tag gtm

Step-4: Rename your tag like “Google Ads User-Provided Data Event” and click on Tag Configuration:

Google Ads User Provided Data Event tag gtm

Step-5: Now, under choose tag type click on “Google Ads”:

choose tag type click on Google Ads

Step-6: Now click on ‘Google Ads User-Provided Data Event’.

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.

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.

wn select the User Provided Data variable

Step-9: Now click on the “Trigger”:

click on the Trigger

Step-10: Select the trigger “Form Submission” that we created earlier while testing the custom html tag.

Select the trigger Form Submission

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.

click the Preview button at the top

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.

Enter your websites URL in Tag Assistant

Step-3: On your website, fill out your form and click on “Submit”.

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.

Check the Tag Assistant 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. 

Click on the tag to see which values were passed to the tag

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”:

Open the developer tools

Step-3: Click on the “Network” Tab.

Click on the Network Tab

Step-4: Now click on the checkbox “Preserve log” and Disable cache”.

click on the checkbox Preserve log and Disble cache

To make validation easier, clear any pre-existing network logs. By clicking on the clear button

clear any pre existing network logs

Step-5: Now type “https://google.com/pagead” in the Filter box

filter

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”

The em parameter contains the hashed user data

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.

About the Author

Himanshu Sharma

  • Founder, OptimizeSmart.com
  • Over 15 years of experience in digital analytics and marketing
  • Author of four best-selling books on digital analytics and conversion optimization
  • Nominated for Digital Analytics Association Awards for Excellence
  • Runs one of the most popular blogs in the world on digital analytics
  • Consultant to countless small and big businesses over the decade