如何通过
PHP API SDK替换JS函数
fbq('track', 'Lead', { ... })
?
https://developers.facebook.com/docs/marketing-api/audiences-api/pixel
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);