10

I'm trying to implement personalization with the contact custom facet in xDB pulled using xConnect. Here I'm using ICondition as mentioned in the Sitecore doc link. After implementing everything, It's not hitting my Evaluate method and throwing the below exception in logs:

"ERROR Type AssemblyName.FolderName.ClassName not found in assembly Assembly Name"

Not sure if I am missing anything. Please suggest.

Adding the code snippet and rule for more information

Code Snippet

Rule under sitecore content tree

Sitecore Content Tree

Rendering Personalization

enter image description here

8
  • 1
    did you deploy your code? Commented Jan 11, 2018 at 7:13
  • Yes, I have added the assembly dll to the sitecore publish folder Commented Jan 11, 2018 at 7:26
  • Which logs? Sitecore logs or the xConnect logs or the automation engine logs? Commented Jan 11, 2018 at 8:46
  • It is in sitecore logs Commented Jan 11, 2018 at 8:47
  • 1
    Yes, it is a conditional rendering and published every thing and attached the screen shot of my personalization Commented Jan 11, 2018 at 10:27

4 Answers 4

4

I'm not quite sure why SC throws that exception but what you and I were trying to accomplished is not following that documentation. you need to implement a class similar to NowCondition, I think SC looks for classes that inherits for RuleContext. Here is an working example, ps. the text needs to be [PropertyName, Control, Parameter, Display Value] for instance [MyProperty,,,City Name]

public class NowCondition<T> : WhenCondition<T> where T : RuleContext
{
/// <summary>Gets or sets the UTC date.</summary>
/// <value>The UTC date.</value>
public string Now { get; set; }

/// <summary>Executes the specified rule context.</summary>
/// <param name="ruleContext">The rule context.</param>
/// <returns><c>True</c>, if the condition succeeds, otherwise <c>false</c>.</returns>
protected override bool Execute(T ruleContext)
{
  DateTime utcNow = DateTimeProvider.GetUtcNow();
  DateTime dateTime = DateUtil.ParseDateTime(this.Now, DateTime.MaxValue);
  if (dateTime.Kind != DateTimeKind.Utc)
    this.HandleInvalidDateKind();
  return utcNow > dateTime;
}

/// <summary>Handles the invalid DateTime Kind.</summary>
protected virtual void HandleInvalidDateKind()
{
  Log.Warn("Sitecore.Rules.Conditions.DateTimeConditions.NowCondition<T> expects UTC date, but date with different kind has been assigned to Now property: " + this.Now, (object) this);
}
}
1
  • This is a bad example. Specially if the core of the problem is the contact facet, and you dont even touch that subject.
    – Gonçalo
    Commented Jul 3, 2019 at 14:18
1

I think you are getting personalisation rules and contact facets confused. The IContactService is used to extend the model(information) that is stored against a user.

If you are implementing IContactService you would be for example adding a "site theme" to every contact. For this you need to add a "schema name" into the config as well as deploy your new facet model as json to xconnect.

As Albernazf pointed out if you are trying to implement a custom personalisation rule you will need to use the Syntax "NowCondition : WhenCondition where T : RuleContext" and have public property which matches the rule you set in sitecore.

Let me know if you need further details on either concept.

2
  • 1
    Thanks for the response, I would like to read the contact information stored in xDb through xconnect, based on the data I would like to perform personalization. Could you please provide more info on this.. Commented Mar 22, 2018 at 10:30
  • I have done this recently. My approach was to call a service which checks the contact information from my custom rule. Your code that uses the XConnect API should be called from within the "Execute" method of your custom rule(see Albernazf answer) .
    – JKerny
    Commented Mar 22, 2018 at 23:17
0

ICondition interface is based on Sitecore.Framework.Rules assembly of the rules engine and used by the Marketing Automation Engine to evaluate rules. Seems like you just want to create Personalization rules which are based on Sitecore.Rules assembly of the rules engine and RuleCondition<T>whereT:RuleContext implementation is used for this. You should follow the below steps to create a custom personalization rule utilizing the contact custom facets:

1. Business Rule for the custom personalization condition:

    class CampaignIDMatches<T> : WhenCondition<T> where T : RuleContext
    {
        public string CampaignID { get; set; }
        public StringOperationType Comparison { get; set; }
     
        protected override bool Execute(T ruleContext)
        {
            Contact contact = Tracker.Current.Session.Contact;
             
            if (contact == null)
            {
                Log.Info(this.GetType() + ": contact is null", this);
                return false;
            }
     
            var xConnectFacet = Sitecore.Analytics.Tracker.Current.Contact.GetFacet<Sitecore.Analytics.XConnect.Facets.IXConnectFacets>("XConnectFacets");
            var allFacets = xConnectFacet.Facets;
            CampaignInfo campInfo = allFacets[CampaignInfo.DefaultFacetKey] as CampaignInfo;
            if (campInfo.CampaignID == CampaignID)
            {
                return true;
            }
            return false;
        }
    }
  1. As in the above code you can see we are trying to fetch custom facet (CampaignInfo) value from the session. To load custom facets in session, we need to register the custom facets key in App_Config\Sitecore\Marketing.Tracking\Sitecore.Analytics.Tracking.config file
<dataAdapterManager defaultProvider="xconnect">
            <providers>
                <clear/>
                <add name="xconnect" type="Sitecore.Analytics.XConnect.DataAccess.XConnectDataAdapterProvider, Sitecore.Analytics.XConnect">
                    <facets hint="raw:AddFacet">
                        <facet facetKey="Classification"/>
                        <facet facetKey="EngagementMeasures"/>
                        <facet facetKey="ContactBehaviorProfile"/>
                        <facet facetKey="Personal"/>
                        <facet facetKey="KeyBehaviorCache"/>
                        <facet facetKey="ListSubscriptions"/>
                        <facet facetKey="CampaignInfo"/> <!-- This is CampaignInfo.DefaultFacetKey value. I've assumed CampaignInfo -->
                    </facets>
                    <GetOperationTimeout>0.00:00:05</GetOperationTimeout>
                </add>
            </providers>
        </dataAdapterManager>

3. Rule under Sitecore content tree --> which you have done correctly.

Once all the above changes are made content/business editors can configure this rule to personalize the components from the Experience editor.

For more details, refer to this blog:

https://sitecorewithraman.wordpress.com/2021/05/02/custom-rules-for-sitecore-email-personalization/

0

To start with custom personalization, you need to perform the below steps:

Step 1: Go to the path /sitecore/system/Settings/Rules/Definitions/Tags right-click on Tags and add new customize Tag (I have given name CustomPersonalization):

enter image description here

Step 2: Go to the path /sitecore/system/Settings/Rules/Conditional Renderings and expand conditional rendering and add created tag into the Tags property of default tag as below:

enter image description here

Step 3: Go to the path /sitecore/system/Settings/Rules/Definitions/Elements

  • Right-click on Elements and add new Element folder (I have given the name CustomPersonalization).

  • Right-click on CustomPersonalization and add new condition and set the Text and Type property of condition.

    Text Property: Give the condition with Rule which will show to the content editor.

    Type Property: Specify our class name with a namespace followed by the assembly name, where we will write our personalization rule business logic.

enter image description here

Step 4: Now you need to add created tag into default tag, Tags property of element folder:

enter image description here

Step 5: Write your personalization rule business logic as below or update your code as per requirement:

public class PersonaliseRuleService<T> : StringOperatorCondition<T> where T : RuleContext
    {
        public string Value { get; set; }
        protected override bool Execute(T ruleContext)
        {
            Assert.ArgumentNotNull(ruleContext, "ruleContext");
            HttpCookie customCookie = HttpContext.Current.Request.Cookies["Custom_Personalization"];      
        if (Value.ToLower().Equals(customCookie.Value.ToLower()))
            {
                return true;
            }
            return false;
        }
    }

Step 6: After completion of all above change, you need to set your personalization rule on the component using experience editor. Go to the page presentation details and select that rendering and click on personalize section. Add your personalization rule and select Edit rule then select our created rule and update the data source from the content property.

enter image description here

enter image description here

enter image description here

Same you can create a more custom rule to show relevant content to the visitor.

For more details, see Blog Post: Custom Personalization Rules in Sitecore 9

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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