4

I have a .NET Core application that sends Interactions to xConnect. I fill some facets and then use the information on a Sitecore website as a POC.

I am filling the ProfileScores Facet to show interest in Profile Keys and match Patterns. This is working fine the first time i do it, but when i try matching another pattern or show interest in other Profile Keys the ContactBehaviorProfile is not updated.

The documentation has this to say:

The Scores property in the Contact Behavior Profile is replaced each time an interaction with a ProfileScores facet is submitted. The dictionaries are not merged. This ensures that the behavior profile does not go stale.

When i submit an Interaction with ProfileScores the Scores dictionary does not change.

I looked in to the Sitecore.XConnect.Collection.Model.dll and I can not find a ContactBehaviorProfileHandler.

Finding that might show me what i (or xConnect) is doing wrong. Has anyone seen this problem before?

PS: here's some code incase i missed something please let me know

public async Task<bool> SendInteraction(Interaction i, StoreInfo storeInfo, ProfileScores profileScores, Contact contact)
    {
        var cfg = await _xconnect.InitializeXConnect();
        using (var client = new XConnectClient(cfg))
        {
            try
            {
                client.SetFacet(i, StoreInfo.DefaultFacetKey, storeInfo);
                client.SetFacet(i, ProfileScores.DefaultFacetKey, profileScores);
                //Some facets xConnect expects to not throw null references (DeviceProfile, IpInfo, WebVisit)
                FillRequiredFacets(client, i, contact);
                client.AddInteraction(i);
                await client.SubmitAsync();
                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return false;
            }
        }
    }  

//Method that creates the ProfileScores Facet
public ProfileScores GetProfileScores(Models.Interaction i)
    {
        ProfileScores profiles = new ProfileScores();
        foreach (var e in i.Events)
        {
            new Switch(e)
               .Case<Models.CheckoutEvent>(ev => AddProfileScore(profiles, new Guid("35FBC336-5AC5-4043-A911-69DD24458F44"), ev.Products, 4))
               .Case<Models.EditCartEvent>(ev => AddProfileScore(profiles, new Guid("35FBC336-5AC5-4043-A911-69DD24458F44"), new List<Models.Product> { ev.Product }, 2));
        }
        return profiles;
    }

private ProfileScores AddProfileScore(ProfileScores profiles, Guid ProfileKey, List<Models.Product> products, int points)
    {
        foreach (Models.Product p in products)
        {
            if (profiles.Scores.ContainsKey(ProfileKey))
            {
                if (!profiles.Scores[ProfileKey].Values.ContainsKey(ProfileKeys[p.Category]))
                {
                    profiles.Scores[ProfileKey].Values.Add(ProfileKeys[p.Category], 0);
                }
                profiles.Scores[ProfileKey].Values[ProfileKeys[p.Category]] += points;
                profiles.Scores[ProfileKey].ScoreCount++;
                profiles.Scores[ProfileKey].Score += points;
                profiles.Scores[ProfileKey].MatchedPatternId = ProfilePatterns[p.Category];
                break;
            }
            profiles.Scores.Add(ProfileKey, new ProfileScore()
            {
                MatchedPatternId = ProfilePatterns[p.Category],
                ProfileDefinitionId = ProfileKey,
                Score = points,
                ScoreCount = 1,
                Values = new Dictionary<Guid, double>() { { ProfileKeys[p.Category], points } }
            });
        }
        return profiles;
    }

EDIT: I tried creating my own Calculated Facet to play around with that and hopefully find some insights. The Facet is being created but all values stay empty. I tried writing some information to a file in the UpdateFacet method but that doesn't seem to be doing anything either.

EDIT 2: I did not add the Custom Calculated Facet in the config file i was supposed to, i have now got the Custom Calculated Facet working. I have also over written the ContactBehaviourProfile Facet to do some debugging, it looks like the ContactBehaviourProfile Facet Handler is working but in the Experience Profile the contact's matched pattern doesn't change.

  • You cannot extend the Contact Behavior Profile, did you remark this one on documentation ? – Vlad Iobagiu Dec 20 '17 at 13:00
  • i did, i have not extended the contact behaviour profile – mark DE Jong Dec 20 '17 at 13:02
  • You can find code for ContactBehaviourProfileHandler in Sitecore.XConnect.Collection.Model.Plugins.dll. – grg Dec 20 '17 at 13:06
  • Well i checked it out, sadly i didn't learn much. I checked Interaction starttime i have a feeling the UpdateFacet method is just not being called at all – mark DE Jong Dec 20 '17 at 14:06
  • xConnect logs didn't give me anything usefull either by the way – mark DE Jong Dec 20 '17 at 14:08

Your Answer

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

Browse other questions tagged or ask your own question.