Created
May 9, 2020 14:35
-
-
Save KruegerDesigns/d589d6c097a66e14692221fb9f796141 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Comment out this variable when you are ready to use this webhook: | |
$Google_data = '{ | |
"lead_id": "NDAwMDAwMDAwMDA6bGVhZF9pZDoxNTg4OTgxNjA1ODIw", | |
"user_column_data": [{ | |
"column_name": "User Phone", | |
"string_value": "+16505550123", | |
"column_id": "PHONE_NUMBER" | |
}, | |
{ | |
"column_name": "User Email", | |
"string_value": "[email protected]", | |
"column_id": "EMAIL" | |
}, | |
{ | |
"column_name": "Postal Code", | |
"string_value": "94043", | |
"column_id": "POSTAL_CODE" | |
}, | |
{ | |
"column_name": "First Name", | |
"string_value": "FirstName", | |
"column_id": "FIRST_NAME" | |
}, | |
{ | |
"column_name": "Last Name", | |
"string_value": "LastName", | |
"column_id": "LAST_NAME" | |
} | |
], | |
"api_version": "1.0", | |
"form_id": 40000000000, | |
"campaign_id": 7581129110, | |
"google_key": "12345", | |
"is_test": true, | |
"gcl_id": "123abc456def", | |
"adgroup_id": 20000000000, | |
"creative_id": 30000000000 | |
}'; | |
// Uncomment next line when you are ready to use this webhook: | |
// $Google_data = file_get_contents("php://input"); | |
$data = json_decode($Google_data, true); | |
function loopAllData($data) { | |
foreach ($data as $key => $value) { | |
if (!is_array($value)) { | |
$results .= $key . ": " . $value . "<br>\r\n"; | |
} | |
if (is_array($value)) { | |
$results .= loopAllData($value); | |
} | |
} | |
return $results; | |
} | |
// You set this in Google Ads, just under where you put the webhook URL | |
$pass="12345"; | |
if ( $pass == $data["google_key"]) { | |
$lead_id = $data['lead_id']; | |
$api_version = $data['api_version']; | |
$form_id = $data['form_id']; | |
$campaign_id = $data['campaign_id']; | |
// $google_key = $data['google_key']; | |
// $is_test = $data['is_test']; | |
// $gcl_id = $data['gcl_id']; | |
// $adgroup_id = $data['adgroup_id']; | |
// $creative_id = $data['creative_id']; | |
$body_data = loopAllData($data['user_column_data']); | |
$bodyemail = "<br>Campaign ID: {$campaign_id}<br>\r\n"; | |
$bodyemail .= "lead ID: {$lead_id}<br>\r\n"; | |
$bodyemail .= "Form ID: {$form_id}<br>\r\n"; | |
$bodyemail .= $body_data; | |
$bodyemail .= "API Version: {$api_version}<br>\r\n"; | |
// Change with your emails | |
$emailfrom = "[email protected]"; | |
$emailto = "[email protected]"; | |
$subject = "Brand - 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"; | |
// Uncomment next line when you are ready to use this webhook | |
// mail($emailto, $subject, $bodyemail, $headers); | |
// Comment out next line when you are ready to use this webhook | |
print_r($emailto. $subject. $bodyemail. $headers); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires php mail() to be working... would be better if using SMTP with PHPmailer.