6

I've setup and configured a custom facet on the contact but we now want to be able to segment on the fields it contains in the ListManager but they aren't available there. What do I need to do to see them in the ListManager?

If I add these fields to the sitecore_analytics_index, will they automatically appear in the ListManager?

2

You are halfway there. If you have completed the customization of the Contact Facet, then you need to add Rule Definitions to the Segment Builder in Sitecore.

There are a couple examples in Sitecore for Firstname and Surname that allow you to see how to create a Condition.

Here's how I would do it:

Add the Custom Contact Facet attribute to the Analytics Index

  1. Sitecore Provides a really good doc for accomplishing this.

Create a Custom IndexedContact class

  1. Create a custom IndexedContact class that inherits from IndexedContact
  2. Set the Property decoration attribute IndexField equal to the Index name you gave the facet in the above step.
  3. Add additional custom facet properties here as needed.

    namespace CustomNameSpace
    {
      [PredefinedQuery("type", ComparisonType.Equal, "contact")]
      public class CustomIndexedContact : IndexedContact 
      {
        [IndexField("contact.NewFacetNameFromIndex")]
        public string NewPropertyName{ get; set; }
      }
    }
    

Create New Rule Condition Using New IndexedContact

  1. Create a new Rule Condition
  2. Use the custom IndexedContact you created above.
  3. Compile Code

    using Sitecore.Analytics.Rules.SegmentBuilder;
    using Sitecore.ContentSearch.Analytics.Models;
    using Sitecore.ContentSearch.Rules.Conditions;
    using System;
    using System.Linq.Expressions;
    
    namespace CustomNameSpace
    {
      public class NewPropertyNameCondition<T> : TypedQueryableStringOperatorCondition<T, CustomIndexedContact> where T : VisitorRuleContext<CustomIndexedContact>
      {
        protected override Expression<Func<CustomIndexedContact, bool>> GetResultPredicate(T ruleContext)
        {
          return this.GetCompareExpression((Expression<Func<CustomIndexedContact, string>>) (c => c.NewPropertyName), this.Value);
        }
      }
    }
    

Add the Segment Condition To Sitecore

Here is a screenshot of an example: enter image description here

  1. Duplicate this item naming it after your custom facet attribute
  2. Add a Reference to Sitecore.SegmentBuilder.dll
  3. Set the type to the namespace, class, and dll name in the Type field on the item to the Condition that you created above
  4. Leave the Text field highlighted the same exchange change the text to represent the custom facet attribute.
  5. Save and publish.

Now go back to List Manager and you will find this Segment Rule is now available for your consumption.

Lather rinse repeat for any other custom facet attributes.

  • Awesome. Thanks for this. Working through the steps ... Creating the new rule condition, using Sitecore.Analytics.Rules.SegmentBuilder doesn't appear in using Sitecore.Analytics.Rules for me (v 8.2.170614). What's going on there? – Steve Ward Dec 6 '17 at 23:57
  • Ignore that using. Probably typo. I wrote this post from a bit of memory and some cut and paste from dotPeek. =) – Pete Navarra Dec 6 '17 at 23:58
  • OK, this is tad embarrassing but having trouble finding the namespace for TypedQueryableStringOperatorCondition in that case .. – Steve Ward Dec 7 '17 at 0:06
  • You will need to add a dll to the reference using NuGet. I think its the Sitecore.Analytics.dll – Pete Navarra Dec 7 '17 at 0:07
  • I've added that reference. TypedQueryableStringOperatorCondition isn't part of Sitecore.Analytics .. – Steve Ward Dec 7 '17 at 0:09

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.