I have a simple form that takes an email which I use to identify a Contact.
I also have a label with some text that changes based on a condition on the same page.

After identifying the Contact I return the same view. However, for the condition to take effect, I have to refresh the page a second time. Is there a way to have the condition take effect right away?

Heres some code:

    public ActionResult Track(string email)
        if (Request.Form["Email"] != null)
            if (Request.Form["Email"] != "")
                Tracker.Current.Session.IdentifyAs("email", Request.Form["email"]);
        FillViewBag(); // for debugging to check if the contact is actualy identified.
        //Remove from session to refresh the contact
        var manager = Sitecore.Configuration.Factory.CreateObject("tracking/contactManager", true) as Sitecore.Analytics.Tracking.ContactManager;
        return View();

This is probably not the cleanest solution but changing return view() to return Redirect("/page") solved this for me

  • Please observe the Q and A format for this site. This is not a forum, don't edit in your answers and solutions to the question part. Self answer it instead. – Mark Cassidy Jan 24 '18 at 20:33

The reason behind this is that the IdentifyAs() method is being called in a component that isn't executed until Sitecore has already determined what components to display.

To see a new component based on a page event or based on the identified user, the page has to be refreshed in order for Sitecore to personalize a different set of components.

In order to get this to work as expected, perform a Redirect to the same Page.

Your Answer

