Adding Targets¶

Developers perform this task.

A target is a set of characteristics by which Brightspot can differentiate users and thereby deliver them nuanced content. This section describes how to create your own target. (The standard Personalization targets are available in the target directory on GitHub.)

  1. Install the Personalization plugin; contact your Brightspot developer for details.
  2. Change to the directory src/main/java/personalization/target/.
  3. Create a class for your target.
  4. Run the Maven build. Users see the target when they navigate to Menu > Admin > Audiences.

The following snippet is an example of a customized target that differentiates by the current month.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package personalization.target;

import com.psddev.personalization.Target;

/* Other imports */

public class MonthOfYearTarget extends Target {

    private Set<Month> month;

    public Set<Month> getMonth() {
        if (month == null) {
            month = new LinkedHashSet<>();
        }
        return month;
    }

    public void setDays(Set<Month> month) {
        this.month = month;
    }

    @Override
    public boolean matches(HttpServletRequest request) {
        return getMonth().contains(OffsetDateTime.now().getMonth());
    }

    @Override
    public String getLabel() {
        return getMonth().stream()
                .map(Object::toString)
                .collect(Collectors.joining(", "));
    }
}

In the previous snippet—

  • Line 3 imports the Target package; this line is mandatory for creating new targets.
  • The method matches extracts the month included in the HTTP request.
  • The method getLabel concatenates the standard Java month names into a form that Brightspot can display.

This customized target appears in the New Audience widget.

../../../_images/new-target.svg

See Java API information for personalization.