January 4, 2017

Update programmatically visitor details in Sitecore

You can use below approach to update visitor details programmatically.

if (Sitecore.Analytics.Tracker.Current.Contact != null)
     {
        
var personalFacet = Tracker.Current.Contact.GetFacet<IContactPersonalInfo>("Personal"
);
         personalFacet.FirstName =
"First Name"
;
         personalFacet.Surname =
"Last Name"
;
         personalFacet.JobTitle =
"Job Title"
;
     }

var phoneFacet = Tracker.Current.Contact.GetFacet<IContactPhoneNumbers>("Phone Numbers"
);
if (!phoneFacet.Entries.Contains("Phone Number"
))
      {
          
IPhoneNumber phoneNumber = phoneFacet.Entries.Create("Phone Number"
);
           phoneNumber.Number =
"999999"
;
           phoneFacet.Preferred =
"Phone Number"
;
      }

var contactEmail = Tracker.Current.Contact.GetFacet<Sitecore.Analytics.Model.Entities.IContactEmailAddresses>("Emails"
);

if (!contactEmail.Entries.Contains("Home"
))
{
    contactEmail.Entries.Create(
"Home"
);
}

var email = contactEmail.Entries["Home"
];
email.SmtpAddress =
"s.k@c.com"
;;
contactEmail.Preferred =
"Home"
;

No comments:

Post a Comment