Audience rules determine whether someone is added your custom audience. The rules are applied on either the referrer URL or specific events and data.
Provide your rules as JSON-encoded strings structured like so:
Use audience rules for different types of custom audiences, including Website Custom Audiences, Mobile App Custom Audiences, and Offline Custom Audiences. For Engagement Audience Rules, see Engagement Custom Audiences.
rules
in inclusions
or exclusions
.To define an audience rule, the following structure must be followed:
rule: { "inclusions": <RULE_SET>, "exclusions": <RULE_SET>, }
Name | Description |
---|---|
type: String | Required. Rule Set JSON string that defines the inclusion. See Rule Set Syntax. |
type: String | Required. Rule set JSON string that defines the exclusion. See Rule Set Syntax. |
For each rule set, follow this structure:
{ "operator" : <BOOLEAN_OPERATOR>, "rules" : <JSON_RULE>, }
Name | Description |
---|---|
type: string | Required.
|
type: string | Required. JSON string of rules (array of rules). See Inclusion And Exclusion Rule Syntax. |
For each inclusion or exclusion rule, follow this structure:
{ "event_sources" : <EVENT_SOURCE_DEFINITION>, "retention_seconds" : <SECONDS>, "filter" : <FILTER>, "aggregation" : <AGGREGATION>, }
aggregation
and retention_seconds
are editable fields. However, editing aggregation
and retention_seconds
does not flush the audience. People who only match the old rule/aggregation continue to be in the audience until they expire.
Name | Description |
---|---|
type: String | Required. JSON object containing the
More event sources can be added to |
type: Integer | Required. Integer (in seconds) for the retention window of the audience, should be less than |
type: String | Required. JSON string of the filter rules. See Filters. |
type: Integer | Optional. JSON string of the aggregation functions. See Aggregate Functions. |
Filtration follows this general format:
"filter" : { "operator": <BOOLEAN_OPERATOR>, "filters": <FILTER_SET>, }
Name | Description |
---|---|
type: string | Required.
|
type: string | Required. Array of JSON objects of filter rules. See Filter Rules Syntax. |
{ "field": <FIELD>, "operator": <COMPARISON_OPERATOR>, "value": <VALUE>, }
Name | Description |
---|---|
type: String | Required.
|
type: String | Required.
If |
type: String | Required. If the |
Create custom audiences based upon the frequency and intensity of behavior using the aggregation
in the audience rule field. With this, you define an aggregate function, for example:
"aggregation" : { "type":"count", "operator":">", "value":1 }
Name | Description |
---|---|
type: String | Required. The aggregation function type.
|
| Required by certain types of aggregation functions. |
type: String | Optional.
|
type: String | Required. Unless type is The parameter on which the aggregation function is applied. |
type: String | Required.
|
type: String | Required. Expected value of the parameter. |
For example:
"aggregation" : { "type":"count", "operator":">", "value":1 }
Operator | Description |
---|---|
| True if event's parameter value greater than specified value. |
| True if event's parameter value greater than or equal to specified value. |
| True if event's parameter value less than specified value. |
| True if event's parameter value less than or equal to specified value. |
| True if event's parameter value equal to specified value. Note: This is equivalent to not specifying an operator at all; that is, "'x' : { 'eq' : 'y' }" is the same as "'x' : 'y' }. |
| True if event's parameter value not equal to specified value. |
| True if event's parameter value, as string, contains specified string. Value of "shoe12345" fulfills 'contains' if specified value 'shoe'. |
| True if event's parameter value, as string, does not contain specified string. Value "shoe12345" fulfills 'not_contains' if specified value is 'purse'. |
| Contains, case-insensitive |
| Not contains, case-insensitive |
| True if event's parameter value matches any strings in given array. |
| True if event's parameter value matches no strings in specified array. |
| 'is_any', case-insensitive. |
| 'is_not_any', case-insensitive |
| True is the event's parameter value starts with the given string |
| "starts_with", case-insensitive |
| Matches a regular expression such as \"example\.com.*purchase$\". The full PCRE grammar is supported |
Match all referring URLs containing the string shoes in the last 30 days:
{ "inclusions": { "operator": "or", "rules": [ { "event_sources": [ { "type": "pixel", "id": "<PIXEL_ID>", } ], "retention_seconds": 2592000, "filter": { "operator": "and", "filters": [ { "field": "url", "operator": "i_contains", "value": "shoes" } ] }, } ] } }
Match ViewContent
events where item price is greater than or equal to USD 100 in the last 30 days. Consider using this rule for the following event:
_fbq.push([ 'track', 'ViewContent', { productId: 1234, category: 'Men > Shoes', price: 199 } ]);
{ "inclusions": { "operator": "or", "rules": [ { "event_sources": [ { "type": "pixel", "id": "<PIXEL_ID>" } ], "retention_seconds": 2592000, "filter": { "operator": "and", "filters": [ { "field": "event", "operator": "eq", "value": "ViewContent" }, { "operator": "or", "filters": [ { "field": "price", "operator": ">=", "value": "100" } ] } ] } } ] } }
See Mobile App Custom Audiences, Example Custom Audience Rules.
Rules have the following operators and data or events:
Operators | The type of filter |
---|---|
| Contains substring, case insensitive |
| Does not contain substring, case insensitive |
| Contains substring, case sensitive |
| Does not contain substring, case sensitive |
| Equal to, case sensitive |
| Not equal to, case sensitive |
| Less than, numeric fields only |
| Less than or equal to, numeric fields only |
| Greater than, numeric fields only |
| Greater than or equal to, numeric fields only |
| Matches a regular expression such as |
Data | Data being filtered |
---|---|
| Fully escaped URL of the site visited |
| Domain of site visited |
| Path of site visited, excluding domain |
| Name of pixel |
| Device that accessed site:
|
any | Any field added to |
Provide each rule as a JSON-encoded string.