6

I'm creating a small POC to learning Sitecore personalization, and I'm trying to create contacts. I have a register form where I will create extranet users and login form. The experience profile page always showing anonymous even I login also. Then I try to identify contacts using this code after login code.

Sitecore.Analytics.Tracker.Current.Session.Identify(UserName);

and I can see the current contact by

Sitecore.Analytics.Tracker.Current.Contact.Identifiers.Identifier

But when I look into experience profile it is showing as "unknown" .

How this contacts make work? Is there any detailed documentation available for it?

Sitecore Version : Sitecore.NET 8.2 (rev. 160729)

2
  • did you end the session or did you wait 20 minutes to end session automatically/ Nov 4, 2016 at 11:43
  • @SitecoreClimber I closed the browser window to end the session, But In the code I was not adding any value personal facet. Once I added those the name and other details began to show.
    – Jojo
    Nov 4, 2016 at 14:20

1 Answer 1

7

Not sure what version of Sitecore you are on, but this is a bit of code from the Sitecore Launch site. It identifies the user and adds the out of the box xDB facets. This is Sitecore 8.1.0.151207.

    public static void SetVisitTagsOnLogin(string domainUser, bool IsNewUser)
    {
     string name = Sitecore.Context.User.Profile.FullName;
     if (name == String.Empty) name = Sitecore.Context.User.LocalName;
     Tracker.Current.Contact.Tags.Add("Username", domainUser);
     Tracker.Current.Contact.Tags.Add("Full name", name);

     Tracker.Current.Contact.Identifiers.AuthenticationLevel = AuthenticationLevel.PasswordValidated;
     Tracker.Current.Session.Identify(domainUser);

     if (IsNewUser)
     {
      IContactPersonalInfo personalFacet = Tracker.Current.Contact.GetFacet<IContactPersonalInfo>("Personal");
      personalFacet.FirstName = GetFirstName(name);
      personalFacet.Surname = GetSurName(name);

      IContactEmailAddresses addressesFacet = Tracker.Current.Contact.GetFacet<IContactEmailAddresses>("Emails");
      IEmailAddress address;
      if (!addressesFacet.Entries.Contains("work_email"))
      {
       address = addressesFacet.Entries.Create("work_email");
       address.SmtpAddress = GetEmailAddressFromUser(domainUser);
       addressesFacet.Preferred = "work_email";
      }
     }   
    }

    private static string GetFirstName(string fullname)
        {
         if (fullname.Contains(' '))
          return fullname.Substring(0, fullname.IndexOf(" "));

         return fullname;
        }

        private static string GetSurName(string fullname)
        {
         if (fullname.Contains(' '))
          return fullname.Substring(fullname.IndexOf(" ") + 1);

         return String.Empty;
        }

        private static string GetEmailAddressFromUser(string username)
        {
         if (username.Contains('\\'))
          return username.Substring(username.IndexOf("\\") + 1);

         return String.Empty;
        }
2
  • Thanks, this worked for me, I found some other blogs related to this link1 Link2
    – Jojo
    Nov 4, 2016 at 14:23
  • Perfect. Could you please market my answer as answered if it solved your issue.
    – Chris Auer
    Nov 4, 2016 at 14:48

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.