4

Is there an option to switch Contact context programmatically?

Let's say i have some logic that depends on Contact context. When running such logic i would want to use something like

using (new Sitecore....ContactSwitcher("contactID"))
{
    //my logic with rules and personalization
}

I.e. Something EXM does with &recipient=xdb:{contactID} parameter

2

Doesn't exist a ContactSwitcher like LanguageSwitcher or UserSwitcher.

You need to identify new user when you want to switch to other contact.

            var contactIdentifier = "contactemail or otheridentifier"; 
            if (Tracker.Current.Contact != null && Tracker.Current.Contact.Identifiers.Identifier == contactIdentifier)
            {
                // Contact already identified
                return;
            }
            Tracker.Current.Session.Identify(contactIdentifier);

If you want to switch back to previous user you need to identify again previous contact.

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.