0

Using Sitecore 9.1

I need to add profile values programmatically to a profile created under Marketing Control Panel. Once this is achieved, the idea is to use it for personalization by setting up rules. After much of research, I came to know that XConnect Behavior Profiles needs to be used for personalization based on historical profile data and that which would work in multiple visitor sessions, but I need more guidance in achieving it or the code snippet. How can I save the profile data to the visitor/contact and then use it for personalization by setting up rules? Please guide me.

If adding profile score would not be enough / complex, please let me know how I can set pattern cards instead. Thanks

  • Why not just edit the profile in Sitecore? Or do you mean assign values to a contact? – Chris Auer Feb 3 at 18:14
  • Yes, I want to add those values to the contacts programmatically. Basically I'm looking for a code that saves profile data to contacts (based on some user action) which should be persistent to the contact until cookies are cleared. I'm using Sitecore 9.1. – Paulson Maclean Feb 4 at 14:58
2

You are going to want to run this code in the users session. Like a button click.

    private static void ProcessProfile(Sitecore.Data.Items.Item profileItem)
    {
        // update the tracker
        var profile = Tracker.Current.Interaction.Profiles[Constants.Profile.IndustryName];
        var scores = new Dictionary<string, double> { { profileItem.Name, 10 } };

        Log.Debug("KickFire: Looking up profile " + profile.ProfileName, "KickFire");

        profile.Score(scores);
        profile.UpdatePattern();

        Log.Debug("KickFire: ====== ALL IS DONE ======", "KickFire"); 
    }

https://github.com/buildabonfire/Bonfire-Company-Personalization/blob/master/src/Feature/KickfireCore/code/Pipelines/createVisit/AdvancedIpData.cs#L132

In the code above the Constants.Profile.IndustryName is a string name of the profile. Example is Focus from /sitecore/system/Marketing Control Panel/Profiles/Focus profile.

Sitecore.Data.Items.Item profileItem is a profile key item under the profile referenced above (Focus). Example is an item with the path /sitecore/system/Marketing Control Panel/Profiles/Focus/Background.

| improve this answer | |
  • Thanks @Chris Auer..!! Sorry for the delay, will try this code. – Paulson Maclean Feb 7 at 16:22

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.