Articles on: CMS Overview

Contactform7 & Gravity Forms - Measure generate_lead events using Webhooks

Accurate conversion tracking is essential for measuring your marketing ROI and optimizing lead generation campaigns. While traditional tracking methods can sometimes miss form submissions due to browser restrictions or user settings, webhooks provide a reliable server-side solution that captures 100% of your leads. This guide will show you how to implement webhook tracking for Contactform7 and Gravity Forms on WordPress, ensuring every form submission is properly measured and attributed.

Prerequisites:
A WordPress site with either Contactform7 or Gravity Forms installed
An AdPage server container
The AdPage tagging plugin for Wordpress
A GTM web and server container


1 Overwrite the client ID, session ID & session count on the web container



Create DataLayer variables from the AdPage dataLayer Event "trytagging_user_data" as shown in the images below:

marketing.user_id


marketing.session_count


marketing.session_id


Ensure that the Google Tag (with the server configuration settings) fires on or after the Custom event "trytagging_user_data" and not with the "All Pages" Trigger.

(This also depends on the way you've set up your triggers to work with the consent update)



Add 3 parameters with the variables created in Step 1:




2 Ensure the generate_lead event doesn't get sent on the server container



Exclude GA4 client generate_lead event from the GA4 trigger in the server container. This is to ensure that you don't send the same conversion twice, once from the webhooks and another time from the GA4 client event.




3 Set up the Data Client



Add a new Client to receive the webhook event. Download it from https://github.com/stape-io/data-client



Open Templates tag in the GTM server container -> Click new -> Import Data Client -> Click save and publish the server container.

Set up a Data Client by opening a Client tab -> Click New -> Select type Data Client Accepted Path Settings -> Add Path -> Save.




4 Set up the sGTM tag for GA4



In the Server Google Tag Manager, create three event data variables:
sessioncount
sessionid
ClientId







Create Transformations inside the Google Tag Manager server container with Transformation type Augment Event:



client_id = {{ ClientId }}
ga_session_id = {{ sessionid }}
ga_session_number = {{ sessioncount }}

Now attach your regular Google Analytics tag to this transformation.



Add the following variables to your sGTM container:

marketing_data.session_id


marketing_data.session_count


marketing_data.user_id


timestamp


page_location (depends on your own site and your URL structure)


Create a new GA4 event tag. Give it the name 'GA4 - generate_lead'. Fill in your GA4 Measurement ID in the correct input field.

Give the tag the following parameters:

ga_session_id = {{ marketing_data.session_id }}
ga_session_number = {{ marketing_data.session_count }}
client_id = {{ marketing_data.user_id }}
event_time = {{ timestamp }}
page_location = {{ page_location }}
engagement_time_msec = 1564
Page_hostname = domainname.com
page_title = page title where the form is located

Create a trigger for the webhook lead tag that fires on:
Client Name equals Data Client
Event Name equals trytagging_generate_lead




5 Set up the sGTM tag for Meta Ads



Create a new Facebook Conversions API event tag. Give it the name 'Meta Ads - generate_lead'.

Select 'Lead' as the event name. Fill in your Meta Pixel ID and API Token in the correct inputfields.



Add the following parameters to the tag:



The variables that you haven't set up for GA4:

id


form_data.your_email
dependant on if you ask this in the form, check the webhook payload for the value of the event data

form_data.your-name
dependant on if you ask this in the form, check the webhook payload for the value of the event data

marketing.user_agent


Get the fbc & fbp variables from this JSON import:
https://drive.google.com/file/d/1dlTtHKctZUeDDG6_fxWEmOkFkJ9Iz8wN/view?usp=sharing

Create a trigger for the webhook lead tag that fires on:
Client Name equals Data Client
Event Name equals trytagging_generate_lead

Updated on: 31/01/2025

Was this article helpful?

Share your feedback

Cancel

Thank you!