To connect a Google Ads lead form webhook to send an event to Google Analytics (GA4) and count it as a conversion, you can follow these steps:
1. Set up the Google Ads lead form extension:
– Sign in to your Google Ads account.
– Go to the Ads & Extensions section.
– Click on Extensions and choose the Lead form extensions.
– Create a new lead form extension or select an existing one.
– Configure the lead form with the necessary fields and information.
– Enable the webhook option and specify the webhook URL to which the form submission data will be sent.
2. Set up a webhook endpoint to receive the form submission:
– Create a PHP script or use an existing one to serve as the webhook endpoint.
In the screenshot below, you will see the URL set to https://zigma.ca/webhook.php
– Ensure the endpoint URL is accessible publicly and can receive POST requests.
– Capture and process the form submission data in the PHP script.
– Validate and sanitize the submitted data to ensure its integrity and security.
Use the PHP code below as the sample to create the webhook PHP file without using Zapier, you can upload this file to your WordPress file by FTP connection to the root. Replace Zigma.ca with your own domain name.
<?php
$Google_data = file_get_contents(“php://input”);
$decoded_data= json_decode($Google_data, true);
$pass=”Strongpassword12345(*!@#“;
if ( $pass == $decoded_data[“google_key”]){
$lead_id = $decoded_data[“lead_id”];
$campaign_id = $decoded_data[“campaign_id”];
$bodyemail .= “Name: ” . $decoded_data[“user_column_data”][0][“string_value”];
$bodyemail .= “<br>Phone: ” . $decoded_data[“user_column_data”][1][“string_value”];
$bodyemail .= “<br>Email: ” . $decoded_data[“user_column_data”][2][“string_value”];
}
$bodyemail .= “<br>Campagin ID: “. $campaign_id;
$bodyemail .= “<br>lead ID: “. $lead_id;
//Change with your emails
$emailfrom = “your WordPress Email Address as sender“;
$emailto = “Your Email Address“;
$subject = “Google Ads | Lead form extension”;
$headers = “From: ” . $emailfrom . “\r\n”;
$headers .= “Reply-To: “. $emailfrom . “\r\n”; //Optional
$headers .= “MIME-Version: 1.0\r\n”;
$headers .= “Content-Type: text/html; charset=utf-8\r\n”;
@mail($emailto, $subject, $bodyemail, $headers);
}
?>
3. Send an event to Google Analytics (GA4):
– Use the PHP script to construct and send an HTTP request to the GA4 Measurement Protocol API.
– Set the appropriate parameters for the GA4 event, such as the Measurement ID and event details.
– Include any additional parameters required for tracking and reporting purposes.
– Make sure to handle any errors or exceptions that may occur during the HTTP request.
Once you have the event set in GA4, you can make it a conversion.
Get the Measurement ID from your GA account.
Get your Secret API key here.
If you can’t receive the GA4 events through the PHP webhook:
A. You might not be passing the proper client ID code with your event.
B. The parameters are being passed in the wrong format.
Use the above sample to create proper Conversions in GA4 for your “Lead form” conversions in Google Ads.
4. Track the conversion in Google Analytics (GA4):
– Set up a conversion goal in your GA4 property to track the lead form submission as a conversion.
– Define the specific event parameters or conditions that should be considered as a successful conversion.
– Assign a meaningful name to the conversion goal for identification and reporting purposes.
– Verify that the conversion goal is properly configured and active.
Now it is time to test your GA4 Event coming from Google Ads “Lead Form”
4. Track the conversion in Google Analytics (GA4):
– Set up a conversion goal in your GA4 property to track the lead form submission as a conversion.
– Define the specific event parameters or conditions that should be considered as a successful conversion.
– Assign a meaningful name to the conversion goal for identification and reporting purposes.
– Verify that the conversion goal is properly configured and active.
By following these steps, you can connect the Google Ads lead form webhook by a PHP file to send an event to Google Analytics (GA4) and count it as a conversion without using Zapier. This allows you to have more control over the data flow and customize the handling of the form submissions according to your specific requirements.