Visitor Data Filters
Overview
Collectors gather data used by scorers to evaluate visitor characteristics. However, not all data collected is relevant for every scorer. To control which data is stored and to limit the size of visitor data, a scorer can implement the TargetingDataFilter interface. This interface allows a scorer to filter out irrelevant request data before it is added to the visitor profile.
/** * Allows request data collected by {@link Collector}s to be filtered before * the {@link TargetingData} is updated with it. * * @param <T> the type of request data filtered by this class. */ public interface TargetingDataFilter <T> { /** * Determine whether the <code>requestData</code> is relevant or must be * filtered out. * If it is filtered out it will not become part of the {@link * TargetingData}. * * @param requestData the request data that was collected * @return {@code true} if this data must be filtered out {@code false} * otherwise. */ public boolean filter(T requestData); /** * Get the type of {@link TargetingData} this class filters for. * * @return the type of {@link TargetingData} this class filters for. */ public Class<? extends TargetingData> getTargetingDataClass(); }
When multiple scorers consume the same type of visitor data, each scorer can provide its own filter. If any filter for a given piece of request data returns false from the filter method, the visitor data is updated with that request data.
Note: Starting with version 13.0.0, ensure that
TargetingDataFilterimplementations are included in the CMS (platform) webapp. In earlier versions, these implementations resided in the HST site webapp.
Example: Filtering Page View Data
The PageViewsTargetingData is an example of visitor data that can be filtered by a scorer. The PageViewsScorer consumes this data to determine if a visitor has viewed specific pages. The scorer is configured with a set of pages to match against the visitor's data. If the visitor has viewed a configured page, the scorer returns a value of 1.0.
The PageViewsScorer implements the TargetingDataFilter interface to filter out page views that are not relevant:
public class PageViewsScorer implements Scorer<PageViewsTargetingData>, TargetingDataFilter<String> { ... @Override public boolean filter(final String page) { return !configuredPages.contains(page); } @Override public Class<? extends TargetingData> getTargetingDataClass() { return PageViewsTargetingData.class; } }
Without filtering, visitor data would continue to grow with every request, potentially leading to unmanageable data sizes. Filtering ensures that only relevant page views are stored.