简体   繁体   中英

Get the form name of Facebook lead ads using webhook

I have two different Facebook leads ad campaigns (A and B) connected to the same FB page, I've connected it to a webhook following this guide using Facebook ads PHP sdk, and pass the leads to my CRM, everything works fine, the problem is that I can't tell if the lead came from form A or B .

I've tried to pull the from name like this:

$input = json_decode(file_get_contents('php://input'), true);
if($input)
{
    $form_id = $input['entry'][0]['changes'][0]['value']['form_id'];
    $form = AdsWebhookHandler::getFormName($form_id);
}

From the AdsWebhookHandler class:

public static function getFormName($form_id)
    {
        $form = new LeadgenForm($form_id);

        if(!$form) return $form_id;

        return $form->read();
    }

But the form always returns empty ( {} ) for some reason. Does anybody know how can I pull the form name? or even better - is it possible to pass custom hidden fields in the form?

Thank you all for an answer:)

OK so I figure out how to get the form name, all I needed to do is use the getData() function included in the Facebook PHP SDK, my code looks like this now:

public function getFormName($form_id)
{
    $form = new LeadgenForm($form_id,null,$this->fb_instance);

    if(!$form) return $form_id;

    $data = $form->read()->getData();
    return isset($data['name']) ? $data['name'] : $form_id;
}

Hope it'll help someone in the future:)

I have two different Facebook leads ad campaigns (A and B) connected to the same FB page, I've connected it to a webhook following this guide using Facebook ads PHP sdk, and pass the leads to my CRM, everything works fine, the problem is that I can't tell if the lead came from form A or B .

I've tried to pull the from name like this:

$input = json_decode(file_get_contents('php://input'), true);
if($input)
{
    $form_id = $input['entry'][0]['changes'][0]['value']['form_id'];
    $form = AdsWebhookHandler::getFormName($form_id);
}

From the AdsWebhookHandler class:

public static function getFormName($form_id)
    {
        $form = new LeadgenForm($form_id);

        if(!$form) return $form_id;

        return $form->read();
    }

But the form always returns empty ( {} ) for some reason. Does anybody know how can I pull the form name? or even better - is it possible to pass custom hidden fields in the form?

Thank you all for an answer :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM