After some development work on our end, we have successfully gotten the real-time Facebook lead ad updates to our endpoint using the PHP method the Facebook Dev Team goes over in this video walk through here. However the video is a little grainy at times so it can be hard to see the code, which we added below.
This walk through assumes some basic coding knowledge in PHP as well as the fact you know how to run the PHP files on a publicly accessible server so your callback will work. To make this integration with Facebook and your listener happen you’ll need three things.
1 – Correct Facebook App set up. I will assume you have a Facebook Developer account and know how to set up a basic app. Just make sure on webhook settings that you have a page subscription with the correct callback URL (the public URL you will place the PHP listener, which we will call webhook.php), and the fields are for ‘leadgen’ in the webhook settings. We had issues with the app accessing the listener unless it was on an https domain (so make sure you have a valid SSL cert), and you will also want to give the app domain permissions in any protective service like Cloud Flare or other firewall so Facebook’s payload won’t be blocked from hitting the listener.
2 – PHP listener at your callback URL. We can label this ‘leadhook.php’ or ‘webhook.php’ and call it from the Facebook app settings above. Here’s how we have ours set up for PHP:
3 – Some kind of platform page in your CRM to subscribe the pages. This is what we used below, it’s very basic but works as a good start point for a fuller app integration to your CRM:
Lead Gen Platform
Using the above we have successfully had our Facebook lead ads begin to hit our listener at the callback URL and thus allow us to handle the data in real-time from there. The above integration only sets it up to show the raw array from the lead event to hit your listener and get recorded to your error log so you can view it.
Use tail -f in terminal on your server to watch the event come in 'live' on the logs. Once you confirm it does, you can then use the $input variable to access the leadgen_id and from there use a GET request to Facebook via their API to pull the actual lead data the user filled out in the form. That part can wait for the next post though!