Skip to content
Skip to main contentWhere does your team stand on AI adoption?
CONTACT SALESSTART BUILDING

Targeting cheatsheet

Enterprise plans

This document serves as a quick reference for fetching content entries by targeting attributes.

What to know

  • Query Pages, Sections, and Data models by targeting attributes.

Create and use custom 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.

Custom targeting attribute examples

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.

Target by device

By default, content entries have access to targeting by device.

Request Desktop Version

Framework
Meta-Framework
SDK Generation
import { builder } from '@builder.io/react'; import type { GetContentOptions } from '@builder.io/sdk'; export default function targetedRequest( modelName: string, options: GetContentOptions ) { return builder.get(modelName, { userAttributes: { device: 'desktop', }, ...options, }); }

Request Mobile Version

Framework
Meta-Framework
SDK Generation
import { builder } from '@builder.io/react'; import type { GetContentOptions } from '@builder.io/sdk'; export default function targetedRequest( modelName: string, options: GetContentOptions ) { return builder.get(modelName, { userAttributes: { device: 'mobile', }, ...options, }); }

Target by authentication

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

Framework
Meta-Framework
SDK Generation
import { builder } from '@builder.io/react'; import type { GetContentOptions } from '@builder.io/sdk'; export default function targetedRequest( modelName: string, options: GetContentOptions ) { return builder.get(modelName, { userAttributes: { isLoggedIn: true, }, ...options, }); }

Instead of passing a literal value such as true, consider passing a variable or function to the request, such as getAuthenticationStatus().

Target by custom list

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

Framework
Meta-Framework
SDK Generation
import { builder } from '@builder.io/react'; import type { GetContentOptions } from '@builder.io/sdk'; export default function targetedRequest( modelName: string, options: GetContentOptions ) { return builder.get(modelName, { userAttributes: { audience: ['mens-fashion'], }, ...options, }); }

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:

  1. recent-shopper and womens-fashion
  2. mens-fashion
  3. recent-shopper and mens-fashion

A request for recent-shopper and womens-fashion would return the first and third entries.

Framework
Meta-Framework
SDK Generation
import { builder } from '@builder.io/react'; import type { GetContentOptions } from '@builder.io/sdk'; export default function targetedRequest( modelName: string, options: GetContentOptions ) { return builder.get(modelName, { userAttributes: { audience: ['recent-shopper', 'womens-fashion'], }, ...options, }); }

What's next

For more information on targeting and custom attributes, see the following documentation:

Was this article helpful?