Last active
April 15, 2022 18:13
-
-
Save taf2/b1ee4d9eb886d20499cebfb0f04c6aae to your computer and use it in GitHub Desktop.
Lead Form Process data from Google Ads Lead Form Extensions
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
/* | |
{"lead_id":"TeSter-123-ABCDEFGHIJKLMNOPQRSTUVWXYZ-abcdefghijklmnopqrstuvwxyz-0123456789-AaBbCcDdEeFfGgHhIiJjKkLl", | |
"user_column_data":[{"column_name":"Full Name","string_value":"FirstName LastName","column_id":"FULL_NAME"}, | |
{"column_name":"User Phone","string_value":"+16505550123","column_id":"PHONE_NUMBER"}, | |
{"column_name":"User Email","string_value":"[email protected]","column_id":"EMAIL"}, | |
{"column_name":"Company Name","string_value":"CompanyName","column_id":"COMPANY_NAME"}], | |
"api_version":"1.0","form_id":40000000000,"campaign_id":281489216452814, | |
"google_key":"----","is_test":true, | |
"gcl_id":"TeSter-123-ABCDEFGHIJKLMNOPQRSTUVWXYZ-abcdefghijklmnopqrstuvwxyz-0123456789-AaBbCcDdEeFfGgHhIiJjKkLl", | |
"adgroup_id":20000000000,"creative_id":30000000000} | |
see: https://support.google.com/google-ads/answer/10089407?hl=en | |
*/ | |
exports.handler = function(event, context, callback) { | |
const data = JSON.parse(decodeURIComponent(event.options.request_body)); | |
const gclid = data.lead_id; | |
const campaign_id = data.campaign_id; | |
const adgroup_id = data.adgroup_id; | |
const creative_id = data.creative_id; | |
const formData = {}; | |
const customFields = {}; | |
const fieldMapping = { | |
'FULL_NAME': 'caller_name', | |
'PHONE_NUMBER': 'phone_number', | |
'EMAIL': 'email' | |
}; | |
data.user_column_data.forEach( (field) => { | |
const ctmFieldName = fieldMapping[field.column_id]; | |
if (ctmFieldName) { | |
formData[ctmFieldName] = field.string_value; | |
} else { | |
customFields[field.column_id.toLowerCase()] = field.string_value; | |
} | |
}); | |
formData.paid_attribution = { | |
gclid: data.gcl_id, | |
adgroup_id: data.adgroup_id, | |
campaign_id: data.campaign_id, | |
creative_id: data.creative_id, | |
form_id: data.form_id | |
}; | |
if (Object.keys(customFields).length) { | |
formData.custom_fields = customFields; | |
} | |
console.log(formData); | |
context.done(null, formData); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment