1

On a goal, you can assign a profile card like you would do on any other items on the content tree.

I though this would assign the Pattern related to this Profile card when the goal is triggered but it does not seem to work.

I tried both on the published page and in the Explore mode by selecting the goal manually, but in both cases the pattern was not assigned to my user.

Is that even possible, and if so what am I missing?

2
  • You're going to have to do it programmatically since profile cards are for content items. Here's code that will help you update the user's pattern (and you can base it a specific pattern if necessary) sitecore.stackexchange.com/questions/6801/….
    – Marco
    Jan 26, 2018 at 17:01
  • In my case I would still like the authors to be able to manage it so what I will try is to still trigger the goal and use the rule engine to add the right profile. I will try the code on this post and see if it works: sitecore.stackexchange.com/questions/7847/… Jan 26, 2018 at 19:16

1 Answer 1

2

You can do it programmatically. Below is the steps to be able to implement this easily.

  1. Trigger a goal programmatically.

  2. Since you have the goal id, you can get the goal item and then read the tracking field.

Here is a snippet on how to read the Tracking Field

TrackingField trackingField;

ProfileUtil.GetProfiles(item, out trackingField);
  1. Once you have the profile card, you can set the pattern card on the user.

Below is a code snippet on how to assign the pattern card to a user:

public static void BoostUserPattern(Session session, Item patternCard, Profile profile)
{
    if (patternCard != null && !patternCard.Name.Equals(profile.PatternLabel))
    {
        Sitecore.Data.Fields.XmlField xmlData = patternCard.Fields["Pattern"];
        XmlDocument xmlDoc = xmlData.Xml;

        XmlNodeList parentNode = xmlDoc.GetElementsByTagName("key");
        var scores = new Dictionary<string, float>();

        foreach (XmlNode childrenNode in parentNode)
        {
            if (childrenNode.Attributes != null)
            {
                scores.Add(childrenNode.Attributes["name"].Value, 0);
            }
        }

        // Set a score value here
        scores[patternCard.Name] = 5;

        profile.Score(scores);

        profile.PatternId = patternCard.ID.ToGuid();
        profile.PatternLabel = patternCard.Name;

        UpdateBehaviorProfile(session);
    }
}

private static void UpdateBehaviorProfile(Session session)
{
    var profileConverterBase = BehaviorProfileConverterBase.Create();

    if (session?.Contact == null || Tracker.Current.Interaction == null)
    {
        return;
    }

    session.Contact.BehaviorProfiles.RemoveAll();

    foreach (var profileName in session.Interaction.Profiles.GetProfileNames())
    {
        var profile = session.Interaction.Profiles[profileName];

        if (!IgnoreInteractionProfile(profile))
        {
            var matchedBehaviorProfile = profileConverterBase.Convert(profile);

            session.Contact.BehaviorProfiles.Add(matchedBehaviorProfile.Id, matchedBehaviorProfile);
        }
    }
}

More information can be found here: Programmatically Trigger a Pattern Card/Profile Card in a selected content in Sitecore

Your Answer

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

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