0

On our Sitecore 9.0-u1 website, we have a REACT application where users can update their profile information in a secured zone. We want to store this information back into the xDB contact profile.

The React application sends this information through a stateless API. Whilst security is being handled by the framework, by nature a stateless API doesn't have a session.

We can update the xDB profile by fetching it through it's identifier, update the contact and store it. However, the profile is not updated into the users session (because there is none). This results in personalisation being based on his old profile information since the session profile is not updated.

If it was a statefull call with session we could reload the contactdata into session by using the contactmanager. However, since we don't have a Tracker.Current (stateless api call), we cannot update.

Any suggestion how we could reload the xDB contact in a stateless context?

1
  • You are going to need to allow the React app get and keep the Analytics cookie from Sitecore. Then use can use something like Fetch with includeSecurity = true; to send the cookie into the API calls. Then you can remain disconnected, but still have Sitecore know who you are (via the contact ID on the analytics cookie). OR you can treat your connection to xConnect like people do when they are talking to it from .NETCore and IoT devices. Where you talk to xConnect over a secure channel with a known contact ID.
    – Chris Auer
    Nov 24, 2018 at 16:41

3 Answers 3

1

Thanks for the suggestions.

In order to solve our problem, we ended up creating a session aware route for this request, so that the Tracker.Current is available. (So we removed the statelessness from this one call)

public static void RegisterRoutes(RouteCollection routes)
{
        routes.MapHttpRoute(
            name: "AuthenticationApi",
            routeTemplate: "api/authentication/profile",
            defaults: new { controller = "AuthenticationApi", action = "UpdateProfile" },
            constraints: new { httpMethod = new HttpMethodConstraint("Put") }
        ).RouteHandler = new SessionRouteHandler();
}

SessionControllerHandler.cs

public class SessionControllerHandler : HttpControllerHandler, IRequiresSessionState
{
    public SessionControllerHandler(RouteData routeData) : base(routeData)
    {
    }
}
2
  • this is indeed the most simple solution.
    – Bas Lijten
    Apr 25, 2019 at 14:08
  • Is it possible if you can please send the implemented method? Feb 28, 2020 at 14:20
0

I think the only way to do this is force a session reload as described in Sitecore documentation in the 'Re-loading contact data' section: https://doc.sitecore.net/developers/xp/tracking-and-session/tracker/tracking-contacts/contact-facets/update-facets.html

So this means your react app will have to trigger another event to your Sitecore instance. Perhaps you can have an in session/Sitecore context api where you trigger this session reload on. You could do this after every api call, or only when you know it can have effect. This endpoint would just execute:

var manager = Sitecore.Configuration.Factory.CreateObject("tracking/contactManager", true) as Sitecore.Analytics.Tracking.ContactManager;
manager.RemoveFromSession(Sitecore.Analytics.Tracker.Current.Contact.ContactId); //     Use tracker ID, not xConnect ID
Sitecore.Analytics.Tracker.Current.Session.Contact = manager.LoadContact(Sitecore.Analytics.Tracker.Current.Contact.ContactId);
2
  • Thanks for the answer Joost, I am aware of how to reload a contact into the session .The issue here is that I don't have a session in a stateless call. Nov 23, 2018 at 11:01
  • Then maybe I don't understand what you are trying to do, but I would expect that you want to make your JSS? Sitecore instance update the session with the updated xconnect data. The only option to do that, is like I mention, trigger this refresh in the JSS instance context. So make your react app, next to calling your api that updates the contact, also trigger a refresh on the Sitecore instance afterwards
    – Joost
    Nov 23, 2018 at 11:57
-1

You can call a web api method from the react app which you have deployed/ developed on sitecore pass the updated value as an parameter and use a method inside web api code to read the contacts from xdb using the xconnect services. Once the contacts are loaded just simply update them.

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.