How to use Data Keys and Data Key Targets via API
AdButler’s Data Keys are key-value pairs that offer more ways to target your audience. For example, you can create a key age
with type NUMBER to hold age values.
Data keys don't do anything on their own. They must be used in tandem with Data key targets, which combine data keys with conditional operators and options, such as AND
, OR
, >
, starts-with
, and is-after
.
Going back to our previous example, you can use the data key age
to create a data key target that lets you serve ads only to audiences of a certain age (=
) or age range (>=
).
You can also incorporate multiple data key targets into one target. For instance, you can further restrict audiences by both age and gender, or by name or location.
It might help you to read our interface guide on Data Keys so you can see how data keys and data key targets are created using AdButler's UI.
Data key targeting can be used on its own or with other targeting methods to make your target audience as specific as needed.
In this guide, you will learn about:
- Creating Data keys.
- Passing Data keys via GET.
- Passing Data keys via POST.
- Creating Data key targets.
- Data key target operators and options.
How to create Data keys
To create a Data Key, provide its name
and type
. name
must be a string, while type
must be one of the following: STRING, NUMBER, DATE, DATETIME, or TIME.
Example:
{
"name": "age",
"type": "NUMBER"
}
As their names suggest, each key type can hold only certain values, but the Data Key itself is actually a string. For example, in a Data Key target, the value of age
is assigned as follows:
{"age" : {">" : "25"}}
How to pass Data keys via GET
Use the _abdk[]
query parameter in your ad request to pass your Data Keys to AdButler.
Example:
https://ads.domain.com/adserve/;ID=171230;size=300x250;setID=373469;type=json;_abdk[bird]=duck;_abdk[bug]=ant;click=CLICK_MACRO_PLACEHOLDER
;click=CLICK_MACRO_PLACEHOLDER
to make sure the request is read correctly. Everything after the ;click=
parameter is read as one value. If you do not have a click tracking link, we recommend removing the ;click=
parameter. Doing so will also make it easier to add or remove other parameters without affecting your ad's click-throughs.How to pass Data keys via POST
You can also pass Data Keys via POST. In this case, you will use the _abdk_json
field.
Example:
POST https://ads.domain.com/adserve
{
"ID": 171230,
"size" : "300x250",
"setID": 373469,
"type" : "json",
"_abdk_json" : {
"bird" : "duck",
"bug" : "ant"
}
}
How to create data key targets
As stated in the introduction, before creating a data key target, you must first create the Data key(s) that you will reference in the target.
To create a data key target, provide its name
(optional) and target
. The latter is a JSON blob formatted as a Lisp S-expression. This is where you enter comparative values for your data keys and add the logic operators and options that will flesh out your targeting criteria.
Let's say you want to target male audiences over the age of 25. You create data keys age
and gender
. You can then write your data key target as
["AND",
{"age" : {">" : "25"}},
{"gender" : {"=" : "male"}}
]
When passing the data key target to AdButler, the JSON must be in a string, i.e. they must have escape characters.
{
"name": "Data key target 1",
"target": "[\"AND\",
{\"age\" : {\">\" : \"25\"}},
{\"gender\" : {\"=\" : \"male\"}}
],"
}
As shown in the example, a data key target has a logical grouping that consists of an array beginning in either AND
or OR
, followed by a comma-separated list of data key comparators.
Just like in the AdButler interface, you can also make data key targets that consist of multiple logical groupings.
Going back to the previous example, let's say your target can now be male audiences over the age of 25, or audiences over the age of 50 who are either female and own iPhones, or living in the United States. You then create a third data key device
and a fourth data key location
. You can then expand your data key target as
{
"name": "Data key target 1",
"target": "[\"OR\",
[\"AND\",
{\"age\" : {\">\" : \"25\"}},
{\"gender\" : {\"=\" : \"male\"}}
],
["\AND\",
{\"age\" : {\">\" : \"50\"}},
[\"OR\",
[\"AND\",
{\"gender\" : {\"=\" : \"female\"}},
{\"device\" : {\"=\" : \"iphone\"}}
],
{\"location\": {\"=\" : \"USA\"}}
]
]
]"
}
Data key target logic operators and options
Logical Grouping
AND |
The target audience must meet all requirements within the logical grouping. |
OR |
The target audience meets any of the requirements within the logical grouping. |
STRING Operators
= |
is equal to |
!= |
is not equal to |
starts-with |
conditional characters at the start of the retrieved string |
ends-with |
conditional characters at the end of the retrieved string |
contains |
conditional characters anywhere within the retrieved string |
does-not-contain |
conditional characters should not be in the retrieved string |
NUMBER Operators
= |
is equal to |
!= |
is not equal to |
< |
is less than |
<= |
is less than or equal to |
> |
is greater than |
>= |
is greater than or equal to |
Date and Time Operators
There are three date and time formats:
- Date:
mm/dd/YYYY
- 2 digit month, 2 digit day, and 4 digit year IE May 11, 2023 is05/11/2023
- Time:
gg:ii AP
- 2 digit hour in 12 hour format, 2 digit minute and AM or PM, IE09:30 AM
or11:30 PM
- DateTime:
mm/dd/YYYY gg:ii AP
- a combination of both Date and Time IE05/11/2023 09:30 AM
DATE Operators
If we assume the request is passed the following:
{
...
"_abdk_json" : {
"gender" : "male",
"registration-date" : "01/17/2023"
},
...
}
is-before |
the retrieved time must come before the retrieved value. With the above request if the target is { "registration-date": { "is-before": "05/10/2023" } } it will match since the request date is before the target. |
is-after |
the retrieved time must come after the retrieved value. With the above request if the target is { "registration-date": { "is-after": "05/10/2023" } } it will not match since the request date is before the target. |
is-between |
the retrieved time must be between the retrieved values. With the above request if the target is { "registration-date": { "is-between": "01/01/2023-05/31/2023" } } it will match because the request date is between the target dates. |
TIME Operators
If we assume the request is passed the following:
{
...
"_abdk_json" : {
"gender" : "male",
"registration-time" : "11:30 AM"
},
...
}
is-before |
the retrieved time must come before the retrieved value. With the above request if the target is { "registration-time": { "is-before": "12:00 PM" } } it will match since the request time is before the target time. |
is-after |
the retrieved time must come after the retrieved value. With the above request if the target is { "registration-time": { "is-after": "12:00 PM" } } it will not match since the request time is before the target time. |
is-between |
the retrieved time must be between the retrieved values. With the above request if the target is { "registration-time": { "is-between": "09:00 AM-04:00 PM" } } it will match since the request time is between the target times. |
DATETIME Operators
If we assume the request is passed the following:
{
...
"_abdk_json" : {
"gender" : "male",
"registration-datetime" : "01/17/2023 12::00 PM"
},
...
}
is-before |
the retrieved time must come before the retrieved value. With the above request if the target is { "registration-datetime": { "is-before": "05/01/2023 12:00 PM" } } it will match since the request date time is before the target date time. |
is-after |
the retrieved time must come after the retrieved value. With the above request if the target is { "registration-datetime": { "is-after": "05/01/2023 12:00 PM" } } it will not match since the request date time is before the target date time. |
is-between |
the retrieved time must be between the retrieved values. With the above request if the target is { "registration-datetime": { "is-between": "05/01/2023 09:00 AM-05/30/2023 04:00 PM" } } it will not match since the request date time is not between the target date times. |
ARRAY Operators
Use ARRAY operators when the _abdk
or _abdk_json
data key sent with the request is an array. There are 2 groups of operators you can use depending on what is going into the data key target: either a single string in the target or a comma delimited list of strings in the target.
Value in data key target is a single string
If we assume the request is passed the following:
{
...
"_abdk_json" : {
"gender" : "male",
"fruits" : ["apple", "plum", "orange"]
},
...
}
includes |
The target will match when the target is in the array sent with the request. With the above request if the target is { "fruits": { "includes": "apple" } } it will match because apple is in the fruits passed with the request. |
does-not-include |
The target will match when the target is NOT in the array sent with the request. With the above request if the target is { "fruits": { "does-not-includes": "banana" } } it will match because banana is not in the the fruits passed with the request. |
Value in data key target is a comma delimited list of strings
If we assume the request is passed the following:
{
...
"_abdk_json" : {
"gender" : "male",
"fruits" : ["apple", "orange"]
},
...
}
includes-all-of |
The target will match when all the items in the target are in the array sent with the request. With the above request if the target is { "fruits": { "includes-all-of": "apple,orange,banana" } } it will not match because the request only contains apple and orange but not banana which is also required for a match. |
includes-one-of |
The target will match when one of the items in the target is in the array sent with the request. With the above request if the target is { "fruits": { "includes-one-of": "apple,banana" } } it will match because apple was passed to the request and only one of apple or banana is required to match. |
includes-none-of |
The target will match when none of the items in the target is in the array sent with the request. With the above request if the target is { "fruits": { "includes-none-of": "plum,banana" } } it will match because none of the fruits in the request above are in the target. |