# Advanced Targeting
Advanced Targeting is a feature that must be enabled and requires additional setup. Please contact Support if you would like to make use of this feature.
Targets that fall under advanced targeting do not contain forecast data. They are best used in combination with SOV delivery.
## Introduction Advanced targeting allows the Adhese instance admins to create complex targeting rules and save them with a label. Sales and Operations can select these targets when booking a campaign. ## Creating and Editing To manage Advanced Targeting in Adhese, click on the *Advanced Targeting* link in the Administration screen. The following screen will appear: [](https://documentation.adhese.org/uploads/images/gallery/2024-06/kVO50XTewTk1c1Ia-advanced-targeting1.png) The screen is divided into two parts: - Add new advanced target - Advanced target table Click **Add new advanced target** to add a new one. To add a new target, enter a label, give it a value and click the *Add Advanced Target* button. The code must be unique for the application to accept it. The **Advanced Targets table** lists the advanced targets that have been created. ## Creating a new Targeting Expression Targeting expressions contain target identifiers and functions. The identifiers allow you to tell the system which targets you want to check, modify, etc.… With the functions, you can express what you want to do with the values. By 'target values' we mean the incoming values of an ad request, regardless of how they were injected into the request. So, this could be a value sent by the browser or app, a segment picked up by a server-side mapping, or a combination of both. ### Defining which targets to use Targets are referred to by their two-letter prefix code: “dt”, “co”, etc... just like in the POST body of an ad request. The exact values available for your Adhese instance can be found in the documentation of your account. The values of each target are always considered to be multi-valued. Their type is List<String>, a list of alphanumeric characters. If you know that a target is single-valued (as can be set in the 'definitions' of your instance), you can use last() to change the type to String (or Void if an empty list). ### Functions to express what to do with a target value Each function acts on the values sent by the request and is identified by the given 2-character target code. For example, given a request like the one below and using the target code 'sg', which is often used for 'segments': https://ads-myadheseinstance.adhese.com/json/sl123/tlall/**sgfamily;sports**/ag45/dtdesktop/II456d676e8d6878s687/ We can identify the target by its two-letter code, ‘sg,’ and see two values: ‘**family**’ and '**sports**'. ## List of all functions ### 1. Check the presence of the target ``` defined(target_code) ``` Checks if a target is present, even if it has an empty string value. ##### Example ``` defined(sg) ``` will match the following requests [https://ads-myadheseinstance.adhese.com/json/sl123/tlall/**sgfamily;sports**/ag45/dtdesktop/II456d676e8d6878s687/](https://ads-myadheseinstance.adhese.com/json/sl123/tlall/sgfamily;sports/ag45/dtdesktop/II456d676e8d6878s687/) https://ads-myadheseinstance.adhese.com/json/sl123/tlall/**sg**/ag45/dtdesktop/II456d676e8d6878s687/ but not match this one https://ads-myadheseinstance.adhese.com/json/sl123/tlall/ag45/dtdesktop/II456d676e8d6878s687/ ### 2. Count number of target values ``` size(target_code) ``` Counts the number of values for a given target code. ##### Example ``` size(sg) > 1 ``` will match [https://ads-myadheseinstance.adhese.com/json/sl123/tlall/**sgfamily;sports**/ag45/dtdesktop/II456d676e8d6878s687/](https://ads-myadheseinstance.adhese.com/json/sl123/tlall/sgfamily;sports/ag45/dtdesktop/II456d676e8d6878s687/) https://ads-myadheseinstance.adhese.com/json/sl123/tlall/**sgfamily**/ag45/**sggourmet**/dtdesktop/II456d676e8d6878s687/ but will not match this one https://ads-myadheseinstance.adhese.com/json/sl123/tlall/**sgfamily**/ag45/dtdesktop/II456d676e8d6878s687/ ### 3. Check the presence of value ``` target_code intersects {'value'} ``` Returns true if ‘value’ is part of the values for the given target_code ##### Example ``` sg intersects {'sports'} ``` will match [https://ads-myadheseinstance.adhese.com/json/sl123/tlall/**sgfamily;sports**/ag45/dtdesktop/II456d676e8d6878s687/](https://ads-myadheseinstance.adhese.com/json/sl123/tlall/sgfamily;sports/ag45/dtdesktop/II456d676e8d6878s687/) https://ads-myadheseinstance.adhese.com/json/sl123/tlall/**sgsports**/ag45/**sggourmet**/dtdesktop/II456d676e8d6878s687/ but will not match https://ads-myadheseinstance.adhese.com/json/sl123/tlall/**sgfamily**/ag45/dtdesktop/II456d676e8d6878s687/ ### 4. Logical operators ``` (condition1 && condition2) || (condition3 && condition4) ``` **&&** expresses ‘and’, **||** expresses ‘or’, **( )** round brackets can be used for grouping expressions ##### Example ``` sg intersects {'family'} || (sg intersects {'sports'} && dt intersects {'desktop'}) ``` will match [https://ads-myadheseinstance.adhese.com/json/sl123/tlall/**sgfamily;sports**/ag45/dtdesktop/II456d676e8d6878s687/](https://ads-myadheseinstance.adhese.com/json/sl123/tlall/sgfamily;sports/ag45/dtdesktop/II456d676e8d6878s687/) https://ads-myadheseinstance.adhese.com/json/sl123/tlall/**sgsports**/ag45/sggourmet/**dtdesktop**/II456d676e8d6878s687/ but will not match https://ads-myadheseinstance.adhese.com/json/sl123/tlall/**sgsports**/ag45/**dtmobile**/II456d676e8d6878s687/ ### 5. Numerical comparison operators ``` atoi(last(target_code)) operator integer ``` Compares the value of a target_code (converted from a string to an integer) with a fixed integer. ##### Available operators - < : less than - <= : less than or equal - > : greater than - >= : greater than or equal - <> : not equal - = : equal ##### Example ``` atoi(last(ag)) > 35 && atoi(last(ag)) <= 65 ``` will match [https://ads-myadheseinstance.adhese.com/json/sl123/tlall/sgfamily;sports/**ag45**/dtdesktop/II456d676e8d6878s687/](https://ads-myadheseinstance.adhese.com/json/sl123/tlall/sgfamily;sports/ag45/dtdesktop/II456d676e8d6878s687/) https://ads-myadheseinstance.adhese.com/json/sl123/tlall/sgsports/**ag65**/sggourmet/dtdesktop/II456d676e8d6878s687/ but will not match https://ads-myadheseinstance.adhese.com/json/sl123/tlall/sgsports/**ag25**/dtmobile/II456d676e8d6878s687/ ### 6. Decode urls and split ``` last(split(decode64(last(target_code))),'/') = string ``` Converts the last value of the given target_code from base64 encoded to a string, splits it by slash and compares the last item with a string ##### Example ``` last(split(decode64(last(br)),'/')) = 'index.html' ``` will match https://ads-myadheseinstance.adhese.com/json/sl123/tlall/sgsport/ag25/dtmobile/II456d676e8d6878s687/**rfL2Zvby9iYXIvaW5kZXguaHRtbA==**/ but will not match https://ads-myadheseinstance.adhese.com/json/sl123/tlall/sgsport/ag25/dtmobile/II456d676e8d6878s687/**rfL2Zvby9iYXIvb3ZlcnZpZXc=**/