3

is it possible to build a custom condition for the segment builder that receives an EXM campaign as parameter / context? How?

I'm trying to find contacts where a specific facet has the same value as a field of the email, but I don't know how to pass the email as context when EXM uses the list, nor even if it's possible. Any idea or starting point?

3

Yes, you can.
However, it's not documented (as far as I know), so it will require some digging.

Conditions for the segment builder use the analytic index (either Lucene or SOLR) to filter the data.
So a requirement of a custom condition is that the data you are using to filter, exists in the index.

Here is a piece of example code that let's you create a segment with one contact that has a specific ID:

using System;
using System.Linq.Expressions;
using Sitecore.Analytics.Rules.SegmentBuilder;
using Sitecore.ContentSearch.Analytics.Models;
using Sitecore.ContentSearch.Rules.Conditions;

public class XDbContactIdCondition<T> : TypedQueryableStringOperatorCondition<T, IndexedContact> 
    where T : VisitorRuleContext<IndexedContact>
{
    public XDbContactIdCondition()
    {
        this.OperatorId = "{10537C58-1684-4CAB-B4C0-40C10907CE31}"; // The ID of the "string operator is equal to" item
    }

    protected override Expression<Func<IndexedContact, bool>> GetResultPredicate(T ruleContext)
    {
        return this.GetCompareExpression((IndexedContact c) => c["_uniqueid"], string.Concat("contact|", this.Value));
    }
}

This is just one simple example and it if you need to find out more, I recommend you take a decompiler (dotPeek, Reflector, etc.) and dive into the Sitecore binaries looking for segmentation code belonging to the List Manager. That's how I figured this out a while back.

  • Thanks Ruud, In your exsample, i can see that the segment builder compares 2 values: The target being the contact (c["_uniqueid"]), and the source being the value introduced by the editor (this.Value). In my case, I need to replace the value introduced by the editor by the value of a field of the email, something like this.Context.CurrentEmail[myfield].Value. Do you think this is possible? – Vicent Galiana Nov 22 '16 at 8:20
  • 1
    Maybe you can use an EXM Campaign ID as input and then a field item to get data from that (something like is done with Pattern Matching where you first select a Profile item and they a Profile key item). But I couldn't say how exactly to get there. – Ruud van Falier Nov 24 '16 at 9:04
0

Not sure how you would do it, in the segment builder. But you could use an engagement plan to do this. Dump all users into first state of your engagement plan, and do a rule that always evaluate, where you check the specific value.

Then you can trigger an email campagin on the result state. Not sure if that is what you are looking for :)

  • I would consider this path only if I can't build a segmented list able to filter based on the current email. Let's see – Vicent Galiana Nov 21 '16 at 13:09
0

After a lot or research and getting in contact with Sitecore, I have concluded that EXM doesn't add anything to the list / segment builder, meaning that it's not possible to get the "current email" from the context when the list is being filtered.

My goal can be achieved by handling the list and conditions by code. We must set the value for the condition with custom code; Based on our workflow, we'll do it at email creation, but I guess it could be done on email save, to keep it up to date. The value could be the actual email (as @ruud suggested), or the values we want to pick from the email, it depends on where we want to put the logic, but I prefer the actual values to keep the condition agnostic of the email.

This solution is not as "clean and dynamic" as I would, but

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.