Graph API Version

Ad Pixel

Reading

A Facebook pixel is a small piece of JavaScript code that an advertiser places on every page of their website. This piece of code provides a set of lightweight functionalities for sending user-specific events and event-specific custom data to Facebook. Advertisers can use the Facebook pixel to capture intent information about how people are using their website. A single Facebook pixel is added to all pages of a website, and is then used to create website custom audiences

Example

Graph API Explorer
GET /v12.0/{ads-pixel-id} HTTP/1.1
Host: graph.facebook.com
/* PHP SDK v5.0.0 */
/* make the API call */
try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->get(
    '/{ads-pixel-id}',
    '{access-token}'
  );
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();
/* handle the result */
/* make the API call */
FB.api(
    "/{ads-pixel-id}",
    function (response) {
      if (response && !response.error) {
        /* handle the result */
      }
    }
);
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{ads-pixel-id}",
    null,
    HttpMethod.GET,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{ads-pixel-id}"
                                      parameters:params
                                      HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];
If you want to learn how to use the Graph API, read our Using Graph API guide.

Parameters

This endpoint doesn't have any parameters.

Fields

FieldDescription
id
numeric string

ID of the pixel

automatic_matching_fields
list<enum>

Advanced matching fields which are enabled for automatic advanced matching

can_proxy
bool

can_proxy

code
string

Pixel code to be placed on the website

creation_time
datetime

Time at which the pixel was created

creator

The user who created this pixel

data_use_setting
enum

Setting to capture how pixel data should be used

enable_automatic_matching
bool

Represents whether automatic advanced matching is enabled for the pixel for identity matching purposes

first_party_cookie_status
enum

First party cookie status to indicate whether first party cookies can be set for this pixel

is_created_by_business
bool

Flag stands for if a pixel is created by busines

is_crm
bool

True if a pixel contains lead gen data source config

is_unavailable
bool

Whether this pixel is unavailable

last_fired_time
datetime

Time at which the pixel was last fired

name
string

Name of the pixel

owner_business

ID of the business that owns this pixel or null if the pixel has not been claimed by any business yet.

Edges

EdgeDescription

assigned_users

A list of results after running Dynamic Ads checks on this pixel.

Ad Accounts in the same business that this pixel is shared

Agencies or other businesses this pixel is shared with

Stats data for this pixel

Error Codes

ErrorDescription
100Invalid parameter
368The action attempted has been deemed abusive or is otherwise disallowed
200Permissions error

Creating

You can make a POST request to events edge from the following paths:
When posting to this edge, an AdsPixel will be created.

Example

Graph API Explorer
POST /v12.0/<PIXEL_ID>/events HTTP/1.1
Host: graph.facebook.com

data=%5B%7B%22event_name%22%3A%22PageView%22%2C%22event_time%22%3A1635166690%2C%22user_data%22%3A%7B%22fbc%22%3A%22fb.1.1554763741205.AbCdEfGhIjKlMnOpQrStUvWxYz1234567890%22%2C%22fbp%22%3A%22fb.1.1558571054389.1098115397%22%2C%22em%22%3A%22309a0a5c3e211326ae75ca18196d301a9bdbd1a882a4d2569511033da23f0abd%22%7D%7D%5D
/* PHP SDK v5.0.0 */
/* make the API call */
try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->post(
    '/<PIXEL_ID>/events',
    array (
      'data' => '[{"event_name":"PageView","event_time":1635166690,"user_data":{"fbc":"fb.1.1554763741205.AbCdEfGhIjKlMnOpQrStUvWxYz1234567890","fbp":"fb.1.1558571054389.1098115397","em":"309a0a5c3e211326ae75ca18196d301a9bdbd1a882a4d2569511033da23f0abd"}}]',
    ),
    '{access-token}'
  );
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();
/* handle the result */
/* make the API call */
FB.api(
    "/<PIXEL_ID>/events",
    "POST",
    {
        "data": "[{\"event_name\":\"PageView\",\"event_time\":1635166690,\"user_data\":{\"fbc\":\"fb.1.1554763741205.AbCdEfGhIjKlMnOpQrStUvWxYz1234567890\",\"fbp\":\"fb.1.1558571054389.1098115397\",\"em\":\"309a0a5c3e211326ae75ca18196d301a9bdbd1a882a4d2569511033da23f0abd\"}}]"
    },
    function (response) {
      if (response && !response.error) {
        /* handle the result */
      }
    }
);
Bundle params = new Bundle();
params.putString("data", "[{\"event_name\":\"PageView\",\"event_time\":1635166690,\"user_data\":{\"fbc\":\"fb.1.1554763741205.AbCdEfGhIjKlMnOpQrStUvWxYz1234567890\",\"fbp\":\"fb.1.1558571054389.1098115397\",\"em\":\"309a0a5c3e211326ae75ca18196d301a9bdbd1a882a4d2569511033da23f0abd\"}}]");
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/<PIXEL_ID>/events",
    params,
    HttpMethod.POST,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
NSDictionary *params = @{
  @"data": @"[{\"event_name\":\"PageView\",\"event_time\":1635166690,\"user_data\":{\"fbc\":\"fb.1.1554763741205.AbCdEfGhIjKlMnOpQrStUvWxYz1234567890\",\"fbp\":\"fb.1.1558571054389.1098115397\",\"em\":\"309a0a5c3e211326ae75ca18196d301a9bdbd1a882a4d2569511033da23f0abd\"}}]",
};
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/<PIXEL_ID>/events"
                                      parameters:params
                                      HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];
curl -X POST \
  -F 'data=[
       {
         "event_name": "PageView",
         "event_time": 1635166690,
         "user_data": {
           "fbc": "fb.1.1554763741205.AbCdEfGhIjKlMnOpQrStUvWxYz1234567890",
           "fbp": "fb.1.1558571054389.1098115397",
           "em": "309a0a5c3e211326ae75ca18196d301a9bdbd1a882a4d2569511033da23f0abd"
         }
       }
     ]' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v12.0/<PIXEL_ID>/events
If you want to learn how to use the Graph API, read our Using Graph API guide.

Parameters

ParameterDescription
data
list<JSON-encoded string>

data

Required
test_event_code
string

Code that is used to identify server test events

Return Type

Struct {
events_received: integer,
messages: List [
string
],
fbtrace_id: string,
}

Error Codes

ErrorDescription
200Permissions error
100Invalid parameter
You can make a POST request to adspixels edge from the following paths:
When posting to this edge, an AdsPixel will be created.

Parameters

ParameterDescription
is_crm
boolean

Whether it is CRM type

name
string

Name of the pixel.

Required

Return Type

This endpoint supports read-after-write and will read the node represented by id in the return type.
Struct {
id: numeric string,
}

Error Codes

ErrorDescription
100Invalid parameter
294Managing advertisements requires an access token with the extended permission for ads_management

Updating

You can update an AdsPixel by making a POST request to /{ads_pixel_id}.

Parameters

ParameterDescription
automatic_matching_fields
array<enum {em, fn, ln, ph, ge, zp, ct, st, country, db, external_id}>

Advanced matching fields for which automatic advanced matching should be enabled

data_use_setting
enum {EMPTY, ADVERTISING_AND_ANALYTICS, ANALYTICS_ONLY}

Setting to capture how pixel data should be used

enable_automatic_matching
boolean

Enable automatic advanced matching for the pixel for identity matching purposes

first_party_cookie_status
enum {EMPTY, FIRST_PARTY_COOKIE_ENABLED, FIRST_PARTY_COOKIE_DISABLED}

First party cookie status to indicate whether first party cookies can be set for this pixel

name
string

Name of the pixel

server_events_business_ids
array<Server Events Permitted Business ID>

server_events_business_ids

Return Type

This endpoint supports read-after-write and will read the node to which you POSTed.
Struct {
success: bool,
}

Error Codes

ErrorDescription
100Invalid parameter
294Managing advertisements requires an access token with the extended permission for ads_management

Deleting

You can't perform this operation on this endpoint.