Contact
us
Google Ads-Google Analytics- Zapier

How to Capture Google Ads Lead Form Extension as a Goal in Google Analytics Without Zapier

We have had clients ask us recently about using the lead generation form in Google Analytics as a goal, so we have decided to provide some instructions.

By following the steps below, you will be able to implement this PHP code into a WordPress website or any other PHP CMS.

  1. Create a webhook for your lead form extension on your server using the instructions in the link provided.
  2. After capturing the lead and receiving the information by email, the next step involves tracking lead form submission as a Google Analytics goal. Add the PHP code below at the bottom of the page to generate a Google event for any Google Ads leads for submission:

$req = curl_init(‘https://www.google-analytics.com/collect’);

curl_setopt_array($req, array)

CURLOPT_POST => TRUE,

CURLOPT_RETURNTRANSFER => TRUE,

CURLOPT_POSTFIELDS =>

v=1&t=event&tid=UA-xxxxxxx-1&cid=555&ec=Google_Ads%20Lead%20Form%20Extension&ea=submittion&el=PPC

));

// Send the request

$response = curl_exec($req);

 

Parameter Tracking Value
v Version 1
t Type event
tid Tracking ID UA-xxxxxxx-1
cid Client ID 555 (anonyms)
ec Event Category Google_Ads Lead Form Extension
ea Event Action Submittion
el Event Label PPC

 

  1. To track the form lead submissions in Google Analytics, you must pass this extension as an event to Google Analytics and then create a goal based on the passed event.

The webhook PHP file looks like this:

 

<?php

$Google_data = file_get_contents(“php://input”);

$decoded_data= json_decode($Google_data, true);

$pass=”Key Used in Form Extensions“;

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);

$req = curl_init(‘https://www.google-analytics.com/collect’);

curl_setopt_array($req, array(

CURLOPT_POST => TRUE,

CURLOPT_RETURNTRANSFER => TRUE,

CURLOPT_POSTFIELDS =>

‘v=1&t=event&tid=UA-xxxxxxx-1&cid=555&ec=Google_Ads%20Lead%20Form%20Extension&ea=submittion&el=PPC’

));

// Send the request

$response = curl_exec($req);

}

?>

If you have questions about using Google Analytics or other information about lead generation, call us at (647) 556-6071 to reach an Internet marketing expert to get the answers you’re looking for.