Try our conversational search powered by Generative AI!

Filtering Audiences

Vote:
 

Hello

I have been digging thru the documentation but couldn't find a good reference anywhere. On a CMS 12, how do we filter the Audience criterias, either just removing some of the choices, or renaming them.
It's not filtering the created Audiences, I've found that blogpost (Customizing VisitorGroup Behavior in Optimizely CMS | Kunal Shetye's Blog), it is the criteras like for example "Ip Range" when building the Audience.

#315760
Jan 17, 2024 15:34
Vote:
 

Hi,

You should be able to use a similar technique to the one mentioned in Kunal's blog post. In this instance though you'd want to intercept IVisitorGroupCriterionRepository. If you create a class which implements that interface like this:

public class FilterVisitorGroupCriteria : IVisitorGroupCriterionRepository
{
    private readonly IVisitorGroupCriterionRepository _instance;
    public FilterVisitorGroupCriteria(IVisitorGroupCriterionRepository instance)
    {
        _instance = instance;
    }

    public IEnumerable<VisitorGroupCriterion> List()
    {
        //Get the list of criteria from the default implementation
        var initialCriteriaList = _instance.List();
        foreach (var criterion in initialCriteriaList)
        {
            //Add your filtering here and return the criteria you want to keep
            yield return criterion;
        }
    }
}

Then register it as an interceptor in your startup.cs like this:

services.Intercept<IVisitorGroupCriterionRepository>((a, b) => new FilterVisitorGroupCriteria(b));

You should then be able to do whatever filtering you need to to exclude the criteria you're not interested in.

#315808
Jan 18, 2024 11:24
Vote:
 

Aha, thanks Paul!
Excellent, I was hoping there was a similar way to perform this. This seems very simple to implement. Have my upvote :)

#315811
Jan 18, 2024 12:11
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.