I'm using sitecore 9.1.1 and SQL server is used for xDB. in below code I'm adding custom values and this gets executed when I close the browser and interaction is being added into xConnect by default by sitecore.

now my question is that it is not being hit all the time when I close the browser.

there is no consistency some time it gets executed post closing browser in 5 min, sometime in 10 min, sometime 20 min or some time dont get executed.

Please advise.

public class ConvertInteractionFacet : ConvertToXConnectInteractionProcessorBase
        private ILogger _logMessage;

        public override void Process(ConvertToXConnectInteractionPipelineArgs args)
            _logMessage = new Logger();
            _logMessage.Log(LogType.Info, "Info: start ConvertInteractionFacet process12345");
                string planCode = string.Empty;
                string planMemberId = string.Empty;
                string userId = string.Empty;

                    var memberActiveAccount = string.Empty;
                    if (Sitecore.Context.HttpContext.Session != null && Sitecore.Context.HttpContext.Session["CurrentUserDetails"] != null)
                        var currentUserDetails = ((UserDetails)Sitecore.Context.HttpContext.Session["CurrentUserDetails"]);

                        planMemberId = ((PlanMemberAccount)currentUserDetails.MemberAccounts).PlanMemberId.ToString();
                        planCode = ((PlanMemberAccount)currentUserDetails.MemberAccounts).PlanCode.ToString();
                        userId = currentUserDetails.UserId;
                        _logMessage.Log(LogType.Info, "Info: plan member id is " + planMemberId + " and Plan code is " + planCode);
                        _logMessage.Log(LogType.Info, "Info: plan member id not in session");
                catch(Exception ex)
                    _logMessage.Log(LogType.Error, "Error12345.GetActivePlanMemberAccount: " + ex.Message);

                if (args != null && args.XConnectInteraction.Events.Count > 0)
                    if (!args.XConnectInteraction.Events[0].CustomValues.ContainsKey("PlanCode"))
                        args.XConnectInteraction.Events[0].CustomValues.Add("PlanCode", planCode);

                    if (!args.XConnectInteraction.Events[0].CustomValues.ContainsKey("PlanMemberId"))
                        args.XConnectInteraction.Events[0].CustomValues.Add("PlanMemberId", planMemberId);

                    if (!args.XConnectInteraction.Events[0].CustomValues.ContainsKey("SessionId"))
                        args.XConnectInteraction.Events[0].CustomValues.Add("SessionId", Guid.NewGuid().ToString());

                    if (!args.XConnectInteraction.Events[0].CustomValues.ContainsKey("UserId"))
                        args.XConnectInteraction.Events[0].CustomValues.Add("UserId", userId);

                    if (!args.XConnectInteraction.Events[0].CustomValues.ContainsKey("CorrelationId"))
                        args.XConnectInteraction.Events[0].CustomValues.Add("CorrelationId", Guid.NewGuid().ToString());

                    if (!args.XConnectInteraction.Events[0].CustomValues.ContainsKey("TimeStamp"))
                        args.XConnectInteraction.Events[0].CustomValues.Add("TimeStamp", DateTime.UtcNow.ToString());
                _logMessage.Log(LogType.Info, "Info: end ConvertInteractionFacet process12345");
            catch (Exception ex)
                _logMessage.Log(LogType.Error, "Error12345: " + ex.Message);
  • 1
    for testing can you reduce the session timeout to 1 minute. Default value is 20 . <sessionState mode="InProc" cookieless="false" timeout="20" sessionIDManagerType="Sitecore.SessionManagement.ConditionalSessionIdManager"> – Vlad Iobagiu Feb 25 at 7:02
  • the above configuration is on web.config. If is working fine I will explain you in an answer. – Vlad Iobagiu Feb 25 at 7:03
  • Hi Vald, thanks a lot for response. yes now I can see debugger coming within a minute. I tried twice and both the time debugger came and code executed successfully. Please now let me know what was happening when it was 20 min like sometime never executed. – Erwin Paul Feb 25 at 10:20
  • Hi Vlad, will it behave same if I will use it with session statemode = outproc and redis as session state provider. – Alok Kumar Feb 25 at 11:07
  • @AlokKumar is not recommended to change the value in production, for local environment/testing is fine to change it. – Vlad Iobagiu Feb 25 at 11:12

Sitecore is keeping the information about the contact in the session until session is ended. The default value is 20 minutes until it is expiring and save the data into xdb.

You have two option to write data faster into xdb:

  1. Change the timeout for session to 1 minute. This is recommended just for testing , is not recommended to reduce the value in production

  2. Also for testing is recommended to have a page which is called to flush the data from session into xDB. Please add next content to the page and save it like Abandon.aspx:

     <%@ Page language="c#" %> <!DOCTYPE html> 
     <html>   <head>
    <title>Abandon Page</title></head> 
    <body>  <script runat="server"> 
    protected void Page_Load(object sender, EventArgs e){

Save abandon.aspx into your root folder and call it to save data from Session in Xdb.

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.