This document serves as a quick reference for fetching content entries by targeting attributes.
- Query Pages, Sections, and Data models by targeting attributes.
Before querying by targeting attributes, you must apply targeting attributes to a content entry. For more on this topic, see:
Tip: For Pages and Sections, the urlPath
is also a targeting attribute. When requesting content entries by target attributes, do not forget to include urlPath
if necessary.
When you create custom targeting attributes, you can specify the attribute you need as well as specify the type. Targeting attributes should be included as key-value pairs within the userAttributes
option object.
The following list includes some common examples.
By default, content entries have access to targeting by device.
Request Desktop Version
Request Mobile Version
To target by authentication, go to your Space Settings and create a new custom targeting attribute with a value type of boolean. Reference the attribute within your code and pass in the appropriate boolean value.
Is Logged In
Instead of passing a literal value such as true
, consider passing a variable or function to the request, such as getAuthenticationStatus()
.
To target by a custom, multi-faceted list of values, go to your Space Settings and create a new custom targeting attribute with a value type string. Toggle the Enum option and add options for your custom targeting attribute.
For example, an attribute of audience could have values such as recent-shopper, mens-fashion, and womens-fashion.
Reference the attribute within your code and pass in the appropriate one or more strings.
Single Value
Multiple Values
Providing multiple values to a custom target attribute will return the most inclusive content set of entries matching the values.
For example, imagine you have three content entries with an audience target. These entries have the following values:
- recent-shopper and womens-fashion
- mens-fashion
- recent-shopper and mens-fashion
A request for recent-shopper and womens-fashion would return the first and third entries.
For more information on targeting and custom attributes, see the following documentation:
- Custom Targeting Attributes: offers more detail on creating and using custom targeting attributes.