使用 PHP API 进行 Facebook 转化跟踪 (fbq)

问题描述 投票:0回答:1

如何通过

PHP API SDK
替换JS函数fbq('track', 'Lead', { ... })

https://developers.facebook.com/docs/marketing-api/audiences-api/pixel

php facebook api facebook-php-sdk facebook-ads-api
1个回答
0
投票
    require './vendor/autoload.php';
    
    use FacebookAds\Api;
    use FacebookAds\Logger\CurlLogger;
    use FacebookAds\Object\ServerSide\ActionSource;
    use FacebookAds\Object\Se`enter code here`rverSide\Content;
    use FacebookAds\Object\ServerSide\CustomData;
    use FacebookAds\Object\ServerSide\DeliveryCategory;
    use FacebookAds\Object\ServerSide\Event;
    use FacebookAds\Object\ServerSide\EventRequest;
    use FacebookAds\Object\ServerSide\UserData;

$access_token = "YOUR_ACCESS_TOKEN";
$pixel_id = "YOUR_PIXEL_ID";
    $api = Api::init(null, null, $access_token);
        $api->setLogger(new CurlLogger());
        $user_data = (new UserData())
            ->setClientIpAddress($ip)
            ->setClientUserAgent($client_user_agent);
        $event = (new Event())
            ->setEventName('PageView')
            ->setEventTime(time())
            ->setEventSourceUrl($url)
            ->setUserData($user_data)
            ->setActionSource(ActionSource::WEBSITE);
        $events = array();
        array_push($events, $event);
        $request = (new EventRequest($pixel_id))
            ->setEvents($events);
        $response = $request->execute();
        print_r($response);
© www.soinside.com 2019 - 2024. All rights reserved.