using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Microsoft.Extensions.DependencyInjection; using Sitecore.Analytics.XConnect.Facets; using Sitecore.XConnect; using Sitecore.XConnect.Client; using Sitecore.XConnect.Collection.Model; namespace HeadlessTraining.sitecore.admin { public partial class xConnect_Identify : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { this.Submit.ServerClick += Submit_ServerClick; this.Abandon.ServerClick += Abandon_ServerClick; } private void Abandon_ServerClick(object sender, EventArgs e) { Sitecore.Analytics.Tracker.Current.EndTracking(); Session.Abandon(); this.Notification.InnerText = "Session abandoned!"; } private void Submit_ServerClick(object sender, EventArgs e) { if (Sitecore.Analytics.Tracker.Current == null) { Sitecore.Analytics.Tracker.StartTracking(); } using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { { try { Contact contact = new Contact(new ContactIdentifier("test", this.Email.Value, ContactIdentifierType.Known)); client.AddContact(contact); // Facet with a reference object, key is specified PersonalInformation personalInfoFacet = new PersonalInformation() { FirstName = this.FirstName.Value, LastName = this.LastName.Value }; FacetReference reference = new FacetReference(contact, PersonalInformation.DefaultFacetKey); client.SetFacet(reference, personalInfoFacet); // Facet without a reference, using default key EmailAddressList emails = new EmailAddressList(new EmailAddress(this.Email.Value, true), "Home"); client.SetFacet(contact, emails); // Facet without a reference, key is specified PhoneNumberList phone = new PhoneNumberList(new PhoneNumber(this.CountryCode.Value, this.Phone.Value), "Home"); client.SetFacet(contact, PhoneNumberList.DefaultFacetKey, phone); // Submit operations as batch client.Submit(); } catch (XdbExecutionException ex) { } } } this.Notification.InnerText = "Contact Identified!"; } } }