Targeting Audiences

The two ways to define who gets your ad are targeting or audiences. With targeting, provide attributes such as demographics or location and we deliver ads to people on Facebook who meet those attributes. See Targeting.

With audiences you build a group of people who receive your ad. You can create audiences based on customer data, conversion data such as activity in your app or website, and so on.

Custom Audiences from CRM Data

Build the target Custom Audiences from customer information. This includes email addresses, phone numbers, names, dates of birth, gender, locations, App User IDs, Page Scoped User IDs, Apple's Advertising Identifier (IDFA), or Android Advertising ID.

As the owner of CRM and other business data, you are responsible for creating and managing this data. To create audiences, share your data in an hashed format to maintain privacy. Facebook compares this with our hashed data to see if we should add someone on Facebook to your ad's audience.

You can add an unlimited number of records to an audience, but only a maximum of 10000 at a time. It may take up to 1 hour before Facebook adds users to an audience, and up to 24 hours for deleting users from an audience.

Building a Custom Audience

Follow this process:

  1. Create an empty Custom Audience with subtype=CUSTOM.
  2. Add or remove people by updating Users

Create a blank audience:

use FacebookAds\Object\CustomAudience;
use FacebookAds\Object\Fields\CustomAudienceFields;
use FacebookAds\Object\Values\CustomAudienceSubtypes;

$audience = new CustomAudience(null, 'act_<AD_ACCOUNT_ID>');
$audience->setData(array(
  CustomAudienceFields::NAME => 'My new CA',
  CustomAudienceFields::SUBTYPE => CustomAudienceSubtypes::CUSTOM,
  CustomAudienceFields::DESCRIPTION => 'People who bought from my website',
));

$audience->create();
from facebookads.adobjects.customaudience import CustomAudience
from facebookads.adobjects.adaccount import AdAccount

ad_account = AdAccount(fbid='act_<AD_ACCOUNT_ID>')

params = {
    CustomAudience.Field.subtype: CustomAudience.Subtype.custom,
    CustomAudience.Field.name: 'My new CA',
    CustomAudience.Field.description: 'People who bought on my website',
}
audience = ad_account.create_custom_audience(params=params)
CustomAudience customAudience = new AdAccount(act_<AD_ACCOUNT_ID>, context).createCustomAudience()
  .setName("My new CA")
  .setSubtype(CustomAudience.EnumSubtype.VALUE_CUSTOM)
  .setDescription("People who bought from my website")
  .execute();
curl \
  -F 'name=My new CA' \
  -F 'subtype=CUSTOM' \
  -F 'description=People who bought from my website' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.10/act_<AD_ACCOUNT_ID>/customaudiences

Add users using single-key matches:

use FacebookAds\Object\CustomAudience;
use FacebookAds\Object\Values\CustomAudienceTypes;

$emails = array(
  'test1@example.com',
  'test2@example.com',
  'test3@example.com',
);

$audience = new CustomAudience(<CUSTOM_AUDIENCE_ID>);

$audience->addUsers($emails, CustomAudienceTypes::EMAIL);
from facebookads.adobjects.customaudience import CustomAudience

audience = CustomAudience('<CUSTOM_AUDIENCE_ID>')
users = ['test1@example.com', 'test2@example.com', 'test3@example.com']

audience.add_users(CustomAudience.Schema.email_hash, users)
User user = new CustomAudience(<CUSTOM_AUDIENCE_ID>, context).createUser()
  .setPayload("{\"schema\":\"EMAIL_SHA256\",\"data\":[\"9b431636bd164765d63c573c346708846af4f68fe3701a77a3bdd7e7e5166254\",\"8cc62c145cd0c6dc444168eaeb1b61b351f9b1809a579cc9b4c9e9d7213a39ee\",\"4eaf70b1f7a797962b9d2a533f122c8039012b31e0a52b34a426729319cb792a\"]}")
  .execute();
curl \
  -F 'payload={ 
    "schema": "EMAIL_SHA256", 
    "data": [ 
      "9b431636bd164765d63c573c346708846af4f68fe3701a77a3bdd7e7e5166254", 
      "8cc62c145cd0c6dc444168eaeb1b61b351f9b1809a579cc9b4c9e9d7213a39ee", 
      "4eaf70b1f7a797962b9d2a533f122c8039012b31e0a52b34a426729319cb792a" 
    ] 
  }' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.10/<CUSTOM_AUDIENCE_ID>/users

Share your custom audience with business objects. Learn more here.

Multi-key Matching

To increase the match rate for your records; provide multiple keys in an array of individual keys, for example ['EXTERN_ID', 'LN', 'FN', 'EMAIL']. You can provide some or all multi-keys for a record. See multi-key extern id matching example later in this document for details. Add users using multi-key matches:

use FacebookAds\Object\CustomAudienceMultiKey;

use FacebookAds\Object\Fields\CustomAudienceMultikeySchemaFields;

$users = array(
  array('fname', 'lname', 'someone@example.com'),
  array('fnamenew', 'lnamenew', 'someone_new@example.com'),
);

$schema = array(
  CustomAudienceMultikeySchemaFields::FIRST_NAME,
  CustomAudienceMultikeySchemaFields::LAST_NAME,
  CustomAudienceMultikeySchemaFields::EMAIL,
);

$audience = new CustomAudienceMultiKey(<CUSTOM_AUDIENCE_ID>);

$audience->addUsers($users, $schema);
from facebookads.adobjects.customaudience import CustomAudience

audience = CustomAudience('<CUSTOM_AUDIENCE_ID>')
users = [['FirstName', 'test2@example.com', 'LastName1'],
         ['FirstNameTest', 'test2@example.com', 'LastNameTest']]

schema = [CustomAudience.Schema.MultiKeySchema.fn,
          CustomAudience.Schema.MultiKeySchema.email,
          CustomAudience.Schema.MultiKeySchema.ln,
          ]
audience.add_users(schema, users, is_raw=True)
User user = new CustomAudience(<CUSTOM_AUDIENCE_ID>, context).createUser()
  .setPayload("{\"schema\":[\"FN\",\"LN\",\"EMAIL\"],\"is_raw\":\"1\",\"data\":[[\"22b074c0fdb3b9e315df7e94ca7c52cbcfe41be6f01d1d03189389489187b857\",\"ec136ea7349a087b1a2c45f68cff8bd30a142a4f07dce11879fa46936d401117\",\"72497f475e4f76d0b28f57c73a084ece576d170874eba3ee2609d9afe4b71aab\"],[\"27aceb96e275c3f80463f472d8cadf320c5a448d89b4aa9910d872601d569621\",\"1369f121c02faf47c434c5e8abd28f44af7bd53ada021e6f71bc1af208edc6e7\",\"08bce13e67535920d8229d8087e98c8715f886299c1a86fad0b78baf9406c2f2\"]]}")
  .execute();
curl \
  -F 'payload={ 
    "schema": [ 
      "FN", 
      "LN", 
      "EMAIL" 
    ], 
    "data": [ 
      [ 
        "22b074c0fdb3b9e315df7e94ca7c52cbcfe41be6f01d1d03189389489187b857", 
        "ec136ea7349a087b1a2c45f68cff8bd30a142a4f07dce11879fa46936d401117", 
        "72497f475e4f76d0b28f57c73a084ece576d170874eba3ee2609d9afe4b71aab" 
      ], 
      [ 
        "27aceb96e275c3f80463f472d8cadf320c5a448d89b4aa9910d872601d569621", 
        "1369f121c02faf47c434c5e8abd28f44af7bd53ada021e6f71bc1af208edc6e7", 
        "08bce13e67535920d8229d8087e98c8715f886299c1a86fad0b78baf9406c2f2" 
      ] 
    ] 
  }' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.10/<CUSTOM_AUDIENCE_ID>/users

If you use the key APPUID, you must include a list of App IDs for your apps that people used.

use FacebookAds\Api;
use FacebookAds\Http\RequestInterface;
use FacebookAds\Object\CustomAudienceNormalizers\HashNormalizer;
use FacebookAds\Object\Fields\CustomAudienceMultikeySchemaFields;

$schema = array(
  CustomAudienceMultikeySchemaFields::EMAIL,
  CustomAudienceMultikeySchemaFields::MADID,
  CustomAudienceMultikeySchemaFields::FB_USER_ID,
);

$users = array(
  array(
    'user1@example.com',
    '1234567890',
    '6032d997-3ab0-4de0-aa16-8af0e5b482fb',
  ),
  array(
    'user2@example.com',
    '',
    'B67385F8-9A82-4670-8C0A-6F9EA7513F5F',
  ),
  array(
    'user3@example.com',
    '9876543210',
    '',
  ),
);

foreach ($users as &$user) {
  $user[0] = hash(HashNormalizer::HASH_TYPE_SHA256, $user[0]);
}

$params = array(
  'payload' => array(
    'schema' => $schema,
    'app_ids' => array(<APP_ID>),
    'data' => $users,
  ),
);

Api::instance()->call(
  "/{<CUSTOM_AUDIENCE_ID>}/users",
  RequestInterface::METHOD_POST,
  $params);
from facebookads.adobjects.customaudience import CustomAudience
import hashlib

schema = [
    CustomAudience.Schema.MultiKeySchema.email,
    CustomAudience.Schema.MultiKeySchema.madid,
    CustomAudience.Schema.MultiKeySchema.appuid,
]

users = [
    [
        'user1@example.com',
        '1234567890',
        '6032d997-3ab0-4de0-aa16-8af0e5b482fb',
    ],
    [
        'user2@example.com',
        '',
        'B67385F8-9A82-4670-8C0A-6F9EA7513F5F',
    ],
    [
        'user3@example.com',
        '9876543210',
        '',
    ],
]

for user in users:
    user[0] = hashlib.sha256(user[0].encode('utf-8')).hexdigest()

CustomAudience(<CUSTOM_AUDIENCE_ID>).add_users(
    schema=schema,
    users=users,
    <APP_ID>s=[<APP_ID>],
    is_raw=True,
    pre_hashed=True)
curl \
  -F 'payload={ 
    "schema": [ 
      "EMAIL", 
      "MADID", 
      "APPUID" 
    ], 
    "app_ids": ["<APP_ID>"], 
    "data": [ 
      [ 
        "b36a83701f1c3191e19722d6f90274bc1b5501fe69ebf33313e440fe4b0fe210", 
        "1234567890", 
        "6032d997-3ab0-4de0-aa16-8af0e5b482fb" 
      ], 
      [ 
        "2b3b2b9ce842ab8b6a6c614cb1f9604bb8a0d502d1af49c526b72b10894e95b5", 
        "", 
        "B67385F8-9A82-4670-8C0A-6F9EA7513F5F" 
      ], 
      [ 
        "898628e28890f937bdf009391def42879c401a4bcf1b5fd24e738d9f5da8cbbb", 
        "9876543210", 
        "" 
      ] 
    ] 
  }' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.10/<CUSTOM_AUDIENCE_ID>/users

Hashing and Normalization for Multi-Key

You must hash your data as SHA256; we don't support other hashing mechanisms. This is required for all data except External Identifiers, App User IDs and Page Scoped User IDs. Before hashing, normalize your data. Only First name FN and Last Name LN support special characters and non-Roman alphabet. For best match results, provide the Roman alphabet translation with no special characters.

  • Email addresses - Use key EMAIL. Trimming leading and trailing whitespace and convert all characters to lowercase.
  • Phone numbers - Use key PHONE. Remove symbols, letters, and any leading zeroes.
  • Gender - Use key GEN. m for male and f for female.
  • Birth Year - Use key DOBY. YYYY from 1900 to current year.
  • Birth Month - Key DOBM. MM format: 01 to 12.
  • Birthday - Key DOBD, DD format: 01 to 31.
  • Last and first names - Keys LN and FN. a-z only. Lower case only, no punctuation. Special characters in UTF8 format.
  • First Initial - FI, first character of normalized first name.
  • US States - ST in 2-character ANSI abbreviation code, lower case. Normalize states outside U.S. in lower case, no punctuations, no special characters, no white space.
  • City - CT as a-z only. Lower case, no punctuations, no special characters, no white space.
  • Zip code - ZIP. In lower case, no white spaces. Use only the first 5 digits for U.S. Use Area/District/Sector format for UK.
  • Country code - COUNTRY. 2-letter country codes in ISO 3166-1 alpha-2.
  • Mobile advertiser id - MADID, all lower case. Keep hyphens.

Hashing

Provide SHA256 values for normalized keys and HEX representations of this value, using lowercase for A through F. The hash function in PHP converts normalized email and phone number:

example result

hash("sha256", "mary@example.com")

f1904cf1a9d73a55fa5de0ac823c4403ded71afd4c3248d00bdcd0866552bb79

hash("sha256", "15559876543")

1ef970831d7963307784fa8688e8fce101a15685d62aa765fed23f3a2c576a4e

External Identifiers

You can match people for an audience with your own identifiers, known as External Identifiers or EXTERN_ID. Hashing the identifiers is optional, but stick to the exact same format when using the identifiers later on. For example, if you choose to hash using SHA256, make sure to use back the same hashed value. These identifiers can then be used as individual keys to delete people from Custom Audiences or create new Custom Audiences. This way you don't need to re-upload any other matching keys. If someone is tagged with personal information and EXTERN_ID, Facebook gives EXTERN_ID lower precedence in matching people on Facebook.

If you have an audience of EXTERN_ID fields in your Ad Account, create a new audience with just these identifiers:

use FacebookAds\Object\CustomAudience;
use FacebookAds\Object\Fields\CustomAudienceMultikeySchemaFields;

// Add Facebook IDs of users of certain applications
$audience = new CustomAudience('<CUSTOM_AUDIENCE_ID>');
$users = array('ExternIDTest123', 'ExternIDTest456');
$audience->createUser(
  $users,
  CustomAudienceMultikeySchemaFields::EXTERN_ID);
from facebookads.adobjects.customaudience import CustomAudience

audience = CustomAudience('<CUSTOM_AUDIENCE_ID>')
users = ['ExternIDTest123', 'ExternIDTest456']
audience.add_users(CustomAudience.Schema.MultiKeySchema.extern_id,
                   users,
                   True,
                   )
User user = new CustomAudience(<CUSTOM_AUDIENCE_ID>, context).createUser()
  .setPayload("{\"schema\":\"EXTERN_ID\",\"data\":[\"ExternIDTest123\",\"ExternIDTest456\"]}")
  .execute();
curl \
  -F 'payload={"schema":"EXTERN_ID","data":["ExternIDTest123","ExternIDTest456"]}' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.8/<CUSTOM_AUDIENCE_ID>/users

You can also add people tagged EXTERN_ID and with multi-key matching:

use FacebookAds\Object\CustomAudienceMultiKey;

use FacebookAds\Object\Fields\CustomAudienceMultikeySchemaFields;

$users = array(
  array('ExternId123', 'FirstName', 'test2@example.com', 'LastName1'),
  array('ExternId456', 'FirstNameTest', '', 'LastNameTest'),
  array('ExternId789', '', 'test3@example.com', 'LastNameTest'),
);

$schema = array(
  CustomAudienceMultikeySchemaFields::EXTERN_ID,
  CustomAudienceMultikeySchemaFields::FIRST_NAME,
  CustomAudienceMultikeySchemaFields::EMAIL,
  CustomAudienceMultikeySchemaFields::LAST_NAME,
);

$audience = new CustomAudienceMultiKey('<CUSTOM_AUDIENCE_ID>');
$audience->addUsers($users, $schema);
from facebookads.adobjects.customaudience import CustomAudience

audience = CustomAudience('<CUSTOM_AUDIENCE_ID>')
users = [['ExternId123', 'FirstName', 'test2@example.com', 'LastName1'],
         ['ExternId456', 'FirstNameTest', '', 'LastNameTest'],
         ['ExternId789', '', 'test3@example.com', 'LastNameTest']]

schema = [CustomAudience.Schema.MultiKeySchema.extern_id,
          CustomAudience.Schema.MultiKeySchema.fn,
          CustomAudience.Schema.MultiKeySchema.email,
          CustomAudience.Schema.MultiKeySchema.ln,
          ]
audience.add_users(schema, users, is_raw=True)
User user = new CustomAudience(<CUSTOM_AUDIENCE_ID>, context).createUser()
  .setPayload("{\"schema\":[\"EXTERN_ID\",\"FN\",\"EMAIL\",\"LN\"],\"is_raw\":\"1\",\"data\":[[\"ExternId123\",\"4cfdde69bde68452d2921db3186d45b8bc825df51e16b94b9517471589eb4f6f\",\"8cc62c145cd0c6dc444168eaeb1b61b351f9b1809a579cc9b4c9e9d7213a39ee\",\"55b5c51f8670181b0454a698c930ee641890c5c80b1e7da87e39a768aa8231ac\"],[\"ExternId456\",\"9b4da888a30b9925bcac4024173a421a823dfe5ffcd2370d21d4b5b66dd8d554\",\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"047569390fc6a34a68dbda84f1c3aa8765422c355ef7e78148dc557e586ff7f4\"],[\"ExternId789\",\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"4eaf70b1f7a797962b9d2a533f122c8039012b31e0a52b34a426729319cb792a\",\"047569390fc6a34a68dbda84f1c3aa8765422c355ef7e78148dc557e586ff7f4\"]]}")
  .execute();
curl \
  -F 'payload={ 
    "schema": [ 
      "EXTERN_ID", 
      "FN", 
      "EMAIL", 
      "LN" 
    ], 
    "data": [ 
      [ 
        "ExternId123", 
        "4cfdde69bde68452d2921db3186d45b8bc825df51e16b94b9517471589eb4f6f", 
        "8cc62c145cd0c6dc444168eaeb1b61b351f9b1809a579cc9b4c9e9d7213a39ee", 
        "55b5c51f8670181b0454a698c930ee641890c5c80b1e7da87e39a768aa8231ac" 
      ], 
      [ 
        "ExternId456", 
        "9b4da888a30b9925bcac4024173a421a823dfe5ffcd2370d21d4b5b66dd8d554", 
        "", 
        "047569390fc6a34a68dbda84f1c3aa8765422c355ef7e78148dc557e586ff7f4" 
      ], 
      [ 
        "ExternId789", 
        "", 
        "4eaf70b1f7a797962b9d2a533f122c8039012b31e0a52b34a426729319cb792a", 
        "047569390fc6a34a68dbda84f1c3aa8765422c355ef7e78148dc557e586ff7f4" 
      ] 
    ] 
  }' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.10/<CUSTOM_AUDIENCE_ID>/users

Facebook supports EXTERN_ID parameters for individual Ad Accounts. This means Facebook cannot use values in one Account for any other Ad Accounts, even if the accountes belong to the same entity.

Removing Audience Members

Use the same data you used to create an audience:

use FacebookAds\Object\CustomAudience;
use FacebookAds\Object\Values\CustomAudienceTypes;

$emails = array(
  'test1@example.com',
  'test2@example.com',
  'test3@example.com',
);

$audience = new CustomAudience(<CUSTOM_AUDIENCE_ID>);

$audience->removeUsers($emails, CustomAudienceTypes::EMAIL);
from facebookads.adobjects.customaudience import CustomAudience

audience = CustomAudience('<CUSTOM_AUDIENCE_ID>')
users = ['test1@example.com', 'test2@example.com', 'test3@example.com']

audience.remove_users(CustomAudience.Schema.email_hash, users)
new CustomAudience(<CUSTOM_AUDIENCE_ID>, context).deleteUsers()
  .setPayload("{\"schema\":\"EMAIL_SHA256\",\"data\":[\"9b431636bd164765d63c573c346708846af4f68fe3701a77a3bdd7e7e5166254\",\"8cc62c145cd0c6dc444168eaeb1b61b351f9b1809a579cc9b4c9e9d7213a39ee\",\"4eaf70b1f7a797962b9d2a533f122c8039012b31e0a52b34a426729319cb792a\"]}")
  .execute();
curl -X DELETE \
  --data-urlencode 'payload={ 
    "schema": "EMAIL_SHA256", 
    "data": [ 
      "9b431636bd164765d63c573c346708846af4f68fe3701a77a3bdd7e7e5166254", 
      "8cc62c145cd0c6dc444168eaeb1b61b351f9b1809a579cc9b4c9e9d7213a39ee", 
      "4eaf70b1f7a797962b9d2a533f122c8039012b31e0a52b34a426729319cb792a" 
    ] 
  }' \
  -d 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.10/<CUSTOM_AUDIENCE_ID>/users

You could also remove people from a list with EXTERN_ID if available:

use FacebookAds\Object\CustomAudience;
use FacebookAds\Object\Fields\CustomAudienceMultikeySchemaFields;

$extern_ids = array(
  'ExternId123',
  'ExternId456',
  'ExternId789',
);

$params = array(
  'payload' =>  array(
    'schema' => CustomAudienceMultikeySchemaFields::EXTERN_ID,
    'data' => $extern_ids
  )
);

$audience = new CustomAudience('<CUSTOM_AUDIENCE_ID>');
$audience->deleteUsers(array(), $params);
from facebookads.adobjects.customaudience import CustomAudience

audience = CustomAudience('<CUSTOM_AUDIENCE_ID>')
users = ['ExternId123', 'ExternId456', 'ExternId789']

audience.remove_users(CustomAudience.Schema.MultiKeySchema.extern_id, users)
new CustomAudience(<CUSTOM_AUDIENCE_ID>, context).deleteUsers()
  .setPayload("{\"schema\":\"EXTERN_ID\",\"data\":[\"ExternId123\",\"ExternId456\",\"ExternId789\"]}")
  .execute();
curl -X DELETE \
  --data-urlencode 'payload={ 
    "schema": "EXTERN_ID", 
    "data": [ 
      "ExternId123", 
      "ExternId456", 
      "ExternId789" 
    ] 
  }' \
  -d 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.10/<CUSTOM_AUDIENCE_ID>/users

Household Audiences

Target ads to multiple people living in the same household. You can create a household audience from one seed audience and include people in the seed audience plus family members who live in the same household. Currently, the seed audience can only be a Custom Audience from CRM data.

  • Build a custom audience, as you normally do.

  • Create a household audience. After the custom audience contains at least 100 people, you can use it as the seed audience for a household audience:

curl -i -X POST \
-d "name=test_household_ca1" \
-d "subtype=CUSTOM" \
-d "seed_audience=6008502483674" \
-d "access_token=<TOKEN>" \
"https://graph.facebook.com/<VERSION>/act_<ID>/customaudiences"
  • It may take 1-2 days for us to create a household audience.
  • Household audience will regularly update based on Facebook's householding information. The household audience will also get updated if the seed is updated.
  • You can only create one household audience from each Custom Audience. If you try to create a 2nd household audience from the same seed audience, you will receive the following error message:
{"error":{"message":"(#100) There's a household audience associated with this seed audience already.","type":"OAuthException","code":100,"fbtrace_id":"DhVxxqjbQlE"}}*

Limitations:

  • You can't use multiple sources for a single household audience.
  • You can't create a household audience from an audience shared with you.
  • Only one household audience can be created from a seed audience.
  • If you delete the seed audience, the associated household audience is deleted.

You can read, update and delete a household audience as you do for Custom Audiences.

Target ads with a household audience as you do for any other custom audience. We support inclusion targeting only, exclusion targeting only, inclusion and exclusion targeting. See Ad Set, Reference.

Audiences, Resources

Other types of audiences you can build and target: