Develop PHP Webhook for Google Lead Form Extension

How to set up PHP webhook code for forwards google lead extension form.

create a webhook in PHP, save this file in the root folder with adwords_webhook.php for connecting your server to Google Ads, and help to get leads data into CRM or mailing address.

Below code for Google Ads Lead form extension.

<?php
$dataStr = @file_get_contents("php://input");
//parse_str($dataStr,$data);
 $data = json_decode($dataStr,TRUE);
 $google_key = $data['google_key'];


if(empty($google_key) || ($google_key != '8765gt8u7654er56ty7u8i95rt6y7u8ytredfgvbhyt6')){
	
	$response=array(
				'status' => 0,
				'status_message' =>'Access Denied.'
			);
		header('Content-Type: application/json');
		echo json_encode($response);
			exit;
}

$name = $data['user_column_data'][0]['string_value'];
$contact_number = $data['user_column_data'][1]['string_value'];
$email = $data['user_column_data'][2]['string_value'];
$LeadMedium = 'Adword Form';	


$correct_number = ''; 
$correct_email = ''; 

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  $correct_number = $email; $correct_email = $contact_number; 
}else{
     $correct_number = $contact_number ; $correct_email =  $email; 
}

$campaign_id = 'googleAds';
$lead_id = '7698788';
    $bodyemail .= “<br>Campagin ID: “. $campaign_id;

     $bodyemail .= “<br>lead ID: “. $lead_id;

//Leads Details forwards to your mail address.

     $emailfrom = “your WordPress Email Address as sender“;

      $emailto = “mail@myfreeonlinetools.com“;

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

}

?>

Google documentation for implementation webhook, POST Schema

Lead Form Webhook

https://developers.google.com/google-ads/webhook/docs/implementation