private static void GetContact() { using (var client = GetClient()) { var contactReference = new IdentifiedContactReference("twitter", "longhorntaco"); var contact = client.Get(contactReference, new ExpandOptions() { FacetKeys = { "Personal" } }); if (contact != null) { Console.WriteLine($"{contact.Personal().FirstName} {contact.Personal().LastName}"); } } }
public void SetPersonalInfo(PersonalInfo info, IdentifiedContactReference reference) { using (var client = SitecoreXConnectClientConfiguration.GetClient()) { var contact = client.Get(reference, new ContactExpandOptions(PersonalInformation.DefaultFacetKey)); var personalInfoFacet = contact.GetFacet <PersonalInformation>(PersonalInformation.DefaultFacetKey); personalInfoFacet = personalInfoFacet == null ? this.contactMapper.Map <PersonalInfo, PersonalInformation>(info) : this.contactMapper.MapToPersonalInformation(info, personalInfoFacet); client.SetFacet(contact, PersonalInformation.DefaultFacetKey, personalInfoFacet); client.Submit(); } }
public Guid?GetCurrentContactId() { var currentContact = this.GetCurrentContact(); if (currentContact == null) { return(null); } if (currentContact.IsNew) { xDbContactRepository.SaveNewContactToCollectionDb(currentContact); } var trackerIdentifier = new IdentifiedContactReference(Sitecore.Analytics.XConnect.DataAccess.Constants.IdentifierSource, currentContact.ContactId.ToString("N")); return(xDbContactRepository.GetContactId(trackerIdentifier)); }
public void UpdateCurrentContactFacet <T>(string facetKey, Action <T> updateFacets, Func <T> createFacet) where T : Facet { var currentContact = this.GetCurrentContact(); if (currentContact == null) { return; } if (currentContact.IsNew) { xDbContactRepository.SaveNewContactToCollectionDb(currentContact); } var trackerIdentifier = new IdentifiedContactReference(Sitecore.Analytics.XConnect.DataAccess.Constants.IdentifierSource, currentContact.ContactId.ToString("N")); xDbContactRepository.UpdateContactFacet(trackerIdentifier, new ContactExpandOptions(facetKey), updateFacets, createFacet); }
public static void GetContact() { // Valid certificate thumbprints must be passed in CertificateWebRequestHandlerModifierOptions options = CertificateWebRequestHandlerModifierOptions.Parse("StoreName=My;StoreLocation=LocalMachine;FindType=FindByThumbprint;FindValue=DAEDD8105CFFAD6E95F25488E72EF0B5C6C9328B"); var certificateModifier = new CertificateWebRequestHandlerModifier(options); // Optional timeout modifier List <IHttpClientModifier> clientModifiers = new List <IHttpClientModifier>(); var timeoutClientModifier = new TimeoutHttpClientModifier(new TimeSpan(0, 0, 20)); clientModifiers.Add(timeoutClientModifier); // This overload takes three client end points - collection, search, and configuration var collectionClient = new CollectionWebApiClient(new Uri("https://sc902.xconnect/odata"), clientModifiers, new[] { certificateModifier }); var searchClient = new SearchWebApiClient(new Uri("https://sc902.xconnect/odata"), clientModifiers, new[] { certificateModifier }); var configurationClient = new ConfigurationWebApiClient(new Uri("https://sc902.xconnect/configuration"), clientModifiers, new[] { certificateModifier }); var cfg = new XConnectClientConfiguration( new XdbRuntimeModel(CollectionModel.Model, MySiteCollectionModel.Model), collectionClient, searchClient, configurationClient); try { cfg.Initialize(); } catch (XdbModelConflictException ce) { System.Console.WriteLine("ERROR:" + ce.Message); return; } using (var client = new XConnectClient(cfg)) { var reference = new IdentifiedContactReference("Website", "*****@*****.**"); var contact = client.Get <Sitecore.XConnect.Contact>(reference, new ContactExpandOptions(PersonalInformation.DefaultFacetKey, BusinessIndustry.DefaultFacetKey, EmailAddressList.DefaultFacetKey) { Interactions = new RelatedInteractionsExpandOptions(IpInfo.DefaultFacetKey) { StartDateTime = DateTime.MinValue, EndDateTime = DateTime.MaxValue, Limit = 3 } }); } }
public Contact GetCurrentContact(params string[] facets) { var manager = Sitecore.Configuration.Factory.CreateObject("tracking/contactManager", true) as ContactManager; using (var client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try { var contactId = Sitecore.Analytics.Tracker.Current != null && Sitecore.Analytics.Tracker.Current.Contact != null? Sitecore.Analytics.Tracker.Current.Contact.ContactId.ToString("N") : ""; if (string.IsNullOrEmpty(contactId)) { return(null); } // Get from current contact var trackerIdentifier = new IdentifiedContactReference( Sitecore.Analytics.XConnect.DataAccess.Constants.IdentifierSource, contactId); var contact = client.Get <Contact>(trackerIdentifier, new ContactExpandOptions(facets)); if (contact == null && manager != null) { manager.CreateContact(ID.NewID); if (Sitecore.Analytics.Tracker.Current != null && Sitecore.Analytics.Tracker.Current.Contact != null && Sitecore.Analytics.Tracker.Current.Contact.IsNew) { Sitecore.Analytics.Tracker.Current.Contact.ContactSaveMode = ContactSaveMode.AlwaysSave; manager.SaveContactToCollectionDb(Sitecore.Analytics.Tracker.Current.Contact); } } return(contact); } catch (XdbExecutionException ex) { // Manage exception Sitecore.Diagnostics.Log.Error( $"[FaceLogin] Error Getting Contact", ex, ex.GetType()); } } return(null); }
public async Task <bool> CreateContact( string source, string identifier, string email) { using (XConnectClient client = SitecoreXConnectClientConfiguration.GetClient()) { try { IdentifiedContactReference reference = new IdentifiedContactReference(source, identifier); var contactTask = client.GetAsync( reference, new ContactExpandOptions() ); Contact existingContact = await contactTask; if (existingContact != null) { return(false); } Contact contact = new Contact(new ContactIdentifier(source, identifier, ContactIdentifierType.Known)); var preferredEmail = new EmailAddress(email, true); var emails = new EmailAddressList(preferredEmail, "Work"); client.AddContact(contact); client.SetEmails(contact, emails); var identifierEmail = new ContactIdentifier(IdentificationSourceEmail, email, ContactIdentifierType.Known); client.AddContactIdentifier(contact, identifierEmail); await client.SubmitAsync(); return(true); } catch (XdbExecutionException ex) { Log.Error(ex.Message, ex, this); return(false); } } }
/// <summary> /// Add Interaction /// </summary> /// <param name="identifier">Email</param> /// <param name="googleApiFacetInfo"></param> public void RegisterInteraction(string identifier, GoogleApiFacetInfo googleApiFacetInfo) { using (XConnectClient client = GetClient()) { var contactReference = new IdentifiedContactReference(Constants.xConnectApiSource, identifier); Contact contact = client.Get <Contact>(contactReference, new ContactExpandOptions(new string[] { PersonalInformation.DefaultFacetKey })); if (contact == null) { return; } Interaction interaction = new Interaction(contactReference, InteractionInitiator.Contact, channelId: new Guid(Constants.Offline_OtherEventChannelId), userAgent: Constants.UserAgent); // Add Custom GoogleApiFacet GoogleApiFacet googleApiFacet = contact.GetFacet <GoogleApiFacet>(GoogleApiFacet.FacetName); if (googleApiFacet == null) { googleApiFacet = new GoogleApiFacet(); googleApiFacet.GoogleApiFacetInfoList.Add(new GoogleApiFacetInfo { ZipCode = googleApiFacetInfo.ZipCode, RestaurantType = googleApiFacetInfo.RestaurantType }); } else { googleApiFacet.GoogleApiFacetInfoList.Add(new GoogleApiFacetInfo { ZipCode = googleApiFacetInfo.ZipCode, RestaurantType = googleApiFacetInfo.RestaurantType }); } client.SetFacet <GoogleApiFacet>(new FacetReference(contact, GoogleApiFacet.FacetName), googleApiFacet); Outcome outcome = new Outcome(new Guid(Constants.Offline_OtherEventChannelId), DateTime.UtcNow, "USD", 0) { EngagementValue = 10, Text = "Google Api Interaction" }; interaction.Events.Add(outcome); client.AddInteraction(interaction); client.Submit(); } }
/// <summary> /// Retrieve a created contact with interactions within the range provided /// </summary> /// <param name="cfg">The client configuration for connecting</param> /// <param name="twitterId">The identifier of the contact to create</param> /// <param name="interactionStartTime">The start range of interactions to return</param> /// <param name="interactionEndTime">The end range of interactions to return</param> /// <returns>The matching contact object</returns> public virtual async Task <Contact> GetContactWithInteractions(XConnectClientConfiguration cfg, string twitterId, DateTime?interactionStartTime, DateTime?interactionEndTime) { Contact existingContact = null; Logger.WriteLine("Retrieving Contact with Identifier:" + twitterId); // Initialize a client using the validated configuration using (var client = new XConnectClient(cfg)) { try { var contactOptions = new ContactExpandOptions(new string[] { PersonalInformation.DefaultFacetKey }); //Add interaction range if necessary if (interactionStartTime.HasValue || interactionEndTime.HasValue) { contactOptions.Interactions = new RelatedInteractionsExpandOptions(IpInfo.DefaultFacetKey) { StartDateTime = interactionStartTime, EndDateTime = interactionEndTime }; } //Build up options for the query var reference = new IdentifiedContactReference("twitter", twitterId); // Get a known contact existingContact = await client.GetAsync <Contact>(reference, contactOptions); if (existingContact == null) { Logger.WriteLine("No contact found with ID '{0}'", twitterId); return(null); } //Output information about the contact Logger.WriteContact(existingContact); } catch (XdbExecutionException ex) { // Deal with exception Logger.WriteError("Exception retrieving contact", ex); } } return(existingContact); }
private async static Task <Contact> CreateOrUpdateContact(XConnectClient client) { var identifiedContactReference = new IdentifiedContactReference(_fakeContact.Source, _fakeContact.EmailAddress); var options = new ContactExpandOptions(PersonalInformation.DefaultFacetKey, EmailAddressList.DefaultFacetKey, AddressList.DefaultFacetKey, PhoneNumberList.DefaultFacetKey, Avatar.DefaultFacetKey); Task <Contact> contactTask = client.GetAsync <Contact>(identifiedContactReference, options); Contact contact = await contactTask; if (contact == null) { contact = new Sitecore.XConnect.Contact(new Sitecore.XConnect.ContactIdentifier(_fakeContact.Source, _fakeContact.EmailAddress, Sitecore.XConnect.ContactIdentifierType.Known)); client.AddContact(contact); } return(contact); }
/// <summary> /// Get Contact /// </summary> /// <param name="identifier">Email</param> /// <returns></returns> public ContactModel GetContact(string identifier) { ContactModel result = null; using (XConnectClient client = GetClient()) { var contactReference = new IdentifiedContactReference(Constans.xConnectApiSource, identifier); // Note: Make sure to pass the required facets, if not sure then pass all facets. var contactFacets = client.Model.Facets.Where(c => c.Target == EntityType.Contact).Select(x => x.Name); var contact = client.Get <Contact>(contactReference, new ContactExpandOptions(contactFacets.ToArray())); if (contact == null) { return(result); } PersonalInformation personalInformation = contact.GetFacet <PersonalInformation>(PersonalInformation.DefaultFacetKey); if (personalInformation == null) { return(result); } result = new ContactModel { FirstName = personalInformation.FirstName, LastName = personalInformation.LastName }; GoogleApiFacet googleApiFacet = contact.GetFacet <GoogleApiFacet>(GoogleApiFacet.FacetName); if (googleApiFacet != null) { result.GoogleInteractions = new List <GoogleInteractionModel>(); foreach (var googleApiFacetInfo in googleApiFacet.GoogleApiFacetInfoList) { result.GoogleInteractions.Add(new GoogleInteractionModel { ZipCode = googleApiFacetInfo.ZipCode, RestaurantType = googleApiFacetInfo.RestaurantType }); } } return(result); } }
/// <summary> /// This method returns the contact details based on identifier passed. /// </summary> /// <param name="identifier"></param> /// <returns></returns> public Contact GetUserContactDetails(string identifier) { using (XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try { var reference = new IdentifiedContactReference("Identifier", identifier); return(client.Get <Contact>(reference, new ContactExpandOptions() { })); } catch (XdbExecutionException ex) { Sitecore.Diagnostics.Log.Error(message: ex.Message, exception: ex); } } return(null); }
public async Task <Contact> GetXConnectContactByIdentifierAsync(string source, string identifier) { Contact toReturn = null; if (!string.IsNullOrEmpty(identifier)) { var IdentifiedContactReference = new IdentifiedContactReference(source, identifier); if (Client != null) { try { var interactions = new RelatedInteractionsExpandOptions(IpInfo.DefaultFacetKey) { StartDateTime = DateTime.MinValue, EndDateTime = DateTime.MaxValue }; var expandOptions = CollectionConst.ContactExandOptions.AllContactExpandOptions; expandOptions.Interactions = interactions; toReturn = await Client.GetAsync(IdentifiedContactReference, expandOptions); } catch (Exception ex) { Errors.Add(ex.Message); } } else { Errors.Add("client was null"); } } else { Errors.Add("Identifier was null"); } if (Errors.Any()) { toReturn = null; } return(toReturn); }
public static Contact ToContact(this Sitecore.Analytics.Tracking.Contact contact, XConnectClient client, string[] facets = null) { var trackerIdentifier = new IdentifiedContactReference( Sitecore.Analytics.XConnect.DataAccess.Constants.IdentifierSource, contact.ContactId.ToString("N")); var ret = client.Get(trackerIdentifier, new ContactExpandOptions(facets)); if (ret == null) { ret = new Contact(new ContactIdentifier(trackerIdentifier.Source, trackerIdentifier.Identifier, ContactIdentifierType.Anonymous)); client.AddContact(ret); client.Submit(); } return(ret); }
public static Contact GetContactByIdentifier() { using (XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try { var reference = new IdentifiedContactReference("twitter", "myrtlesitecore"); return(client.Get <Contact>(reference, new ContactExpandOptions() { })); } catch (XdbExecutionException ex) { Sitecore.Diagnostics.Log.Error(ex.Message, ex); } } return(null); }
protected override bool Execute(UpdateContactData data, FormSubmitContext formSubmitContext) { Assert.ArgumentNotNull(data, nameof(data)); Assert.ArgumentNotNull(formSubmitContext, nameof(formSubmitContext)); var firstNameField = GetFieldById(data.FirstNameFieldId, formSubmitContext.Fields); var lastNameField = GetFieldById(data.LastNameFieldId, formSubmitContext.Fields); var emailField = GetFieldById(data.EmailFieldId, formSubmitContext.Fields); if (firstNameField == null && lastNameField == null && emailField == null) { return(false); } using (var client = CreateClient()) { try { var source = "Subscribe.Form"; var id = CurrentTracker.Contact.ContactId.ToString("N"); CurrentTracker.Session.IdentifyAs(source, id); var trackerIdentifier = new IdentifiedContactReference(source, id); var expandOptions = new ContactExpandOptions( PersonalInformation.DefaultFacetKey, CollectionModel.FacetKeys.EmailAddressList); XConnectContact contact = client.Get(trackerIdentifier, expandOptions); SetPersonalInformation(GetValue(firstNameField), GetValue(lastNameField), contact, client); SetEmail(GetValue(emailField), contact, client); client.Submit(); return(true); } catch (Exception ex) { Logger.LogError(ex.Message, ex); return(false); } } }
protected override bool Execute(UpdateContactData data, FormSubmitContext formSubmitContext) { Assert.ArgumentNotNull(data, nameof(data)); Assert.ArgumentNotNull(formSubmitContext, nameof(formSubmitContext)); var firstNameField = GetFieldById(data.FirstNameFieldId, formSubmitContext.Fields); var lastNameField = GetFieldById(data.LastNameFieldId, formSubmitContext.Fields); var emailField = GetFieldById(data.EmailFieldId, formSubmitContext.Fields); var twitterAccountField = GetFieldById(data.TwitterAccountFieldId, formSubmitContext.Fields); var twitterAccount = GetValue(twitterAccountField); if (!string.IsNullOrEmpty(twitterAccount)) { Tracker.Current.Session.IdentifyAs("twitter", twitterAccount); } if (firstNameField == null && lastNameField == null && emailField == null) { return(false); } using (var client = CreateClient()) { try { var trackerIdentifier = new IdentifiedContactReference("twitter", twitterAccount); var expandOptions = new ContactExpandOptions( CollectionModel.FacetKeys.PersonalInformation, CollectionModel.FacetKeys.EmailAddressList); var contact = client.Get(trackerIdentifier, expandOptions); SetPersonalInformation(GetValue(firstNameField), GetValue(lastNameField), GetValue(twitterAccountField), contact, client); SetEmail(GetValue(emailField), contact, client); client.Submit(); return(true); } catch (Exception ex) { Logger.LogError(ex.Message, ex); return(false); } } }
public Sitecore.XConnect.Contact GetContactByIdentifier(string identifier) { using (XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try { var reference = new IdentifiedContactReference("website", identifier); return(client.Get <Sitecore.XConnect.Contact>(reference, new ContactExpandOptions() { })); } catch (XdbExecutionException ex) { // Manage exceptions } return(null); } }
public void UpdateOrCreateXDbServiceContactWithEmail(IXDbContactWithEmail serviceContact) { using (var client = SitecoreXConnectClientConfiguration.GetClient()) { var reference = new IdentifiedContactReference(serviceContact.IdentifierSource, serviceContact.IdentifierValue); var contact = client.Get(reference, new ContactExpandOptions(CollectionModel.FacetKeys.EmailAddressList)); if (contact == null) { contact = new Contact(new ContactIdentifier(reference.Source, reference.Identifier, ContactIdentifierType.Known)); SetEmail(contact, serviceContact, client); client.AddContact(contact); client.Submit(); } else if (contact.Emails()?.PreferredEmail.SmtpAddress != serviceContact.Email) { SetEmail(contact, serviceContact, client); client.Submit(); } } }
// Update Cluster for Contact protected override async Task ConsumeEvaluationResultsAsync(IReadOnlyList <Contact> entities, IReadOnlyList <object> evaluationResults, CancellationToken token) { var contactIdentifiers = entities .SelectMany(x => x.Identifiers.Where(s => s.Source == XConnectService.IdentificationSourceEmail)); var predictionResults = evaluationResults.ToPredictionResults(); using (IServiceScope scope = _serviceProvider.CreateScope()) { using (var xdbContext = scope.ServiceProvider.GetRequiredService <IXdbContext>()) { foreach (var identifier in contactIdentifiers) { // filter unknown contacts (with Email=null) if (predictionResults.Any(x => x.Email.Equals(identifier.Identifier))) { var reference = new IdentifiedContactReference(identifier.Source, identifier.Identifier); var contact = await xdbContext.GetContactAsync(reference, new ContactExpandOptions( PersonalInformation.DefaultFacetKey, EmailAddressList.DefaultFacetKey, ContactBehaviorProfile.DefaultFacetKey, RfmContactFacet.DefaultFacetKey )); if (contact != null) { var rfmFacet = contact.GetFacet <RfmContactFacet>(RfmContactFacet.DefaultFacetKey) ?? new RfmContactFacet(); rfmFacet.Cluster = predictionResults.First(x => x.Email.Equals(identifier.Identifier)).Cluster; xdbContext.SetFacet(contact, RfmContactFacet.DefaultFacetKey, rfmFacet); _logger.LogInformation(string.Format("RFM info: email={0}, R={1}, F={2}, M={3}, Recency={4}, Frequency={5}, Monetary={6}, CLUSTER={7}", identifier.Identifier, rfmFacet.R, rfmFacet.F, rfmFacet.M, rfmFacet.Recency, rfmFacet.Frequency, rfmFacet.Monetary, rfmFacet.Cluster)); } } } await xdbContext.SubmitAsync(token); } } }
public List <VisitorOrderCreatedGoal> GetSubmittedOrderGoals(double?pastDaysAmount) { var submittedOrderOutcomes = new List <VisitorOrderCreatedGoal>(); using (var client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try { var reference = new IdentifiedContactReference("CommerceUser", Sitecore.Context.GetUserName()); var interactionFacets = client.Model.Facets.Where(c => c.Target == EntityType.Interaction).Select(x => x.Name); var contact = client.Get(reference, new ContactExpandOptions() { Interactions = new RelatedInteractionsExpandOptions(interactionFacets.ToArray()) { EndDateTime = DateTime.MaxValue, StartDateTime = DateTime.MinValue } }); if (contact != null) { foreach (var interaction in contact.Interactions) { var submittedOrderEvents = interaction.Events.OfType <VisitorOrderCreatedGoal>().OrderBy(ev => ev.Timestamp).ToList(); if (pastDaysAmount.HasValue) { submittedOrderEvents = submittedOrderEvents.Where(ev => ev.Timestamp > DateTime.Now.AddDays(-(pastDaysAmount.Value))).ToList(); } submittedOrderOutcomes.AddRange(submittedOrderEvents); } } } catch (XdbExecutionException ex) { Log.Error("Failed to get contact", ex, this); } } return(submittedOrderOutcomes); }
private static void AddContactTest(string source, string identifier) { using (XConnectClient client = GetClient()) { // Get a known contact IdentifiedContactReference reference = new IdentifiedContactReference(source, identifier); Contact existingContact = client.Get <Contact>( reference, new ContactExpandOptions(PersonalInformation.DefaultFacetKey)); if (existingContact != null) { return; } var contactIdentifier = new[] { new ContactIdentifier(source, identifier, ContactIdentifierType.Known) }; Contact knownContact = new Contact(contactIdentifier); PersonalInformation personalInformation = new PersonalInformation(); personalInformation.FirstName = "Test Firstname " + DateTime.Now.Ticks; personalInformation.LastName = "Test Lastname " + DateTime.Now.Ticks; personalInformation.Gender = "male"; client.SetFacet <PersonalInformation>(knownContact, PersonalInformation.DefaultFacetKey, personalInformation); client.AddContact(knownContact); client.Submit(); var operations = client.LastBatch; // Loop through operations and check status foreach (var operation in operations) { System.Console.WriteLine(operation.OperationType + operation.Target.GetType().ToString() + " Operation: " + operation.Status); } } }
private static void AddInteractionTest(string source, string identifier) { using (XConnectClient client = GetClient()) { try { // Get contact IdentifiedContactReference reference = new IdentifiedContactReference(source, identifier); Contact existingContact = client.Get <Contact>( reference, new ContactExpandOptions(PersonalInformation.DefaultFacetKey)); if (existingContact == null) { return; } //Creating even to add to interaction for testing purposes var interactionEvent = new Event(Settings.OnlineEventId, DateTime.UtcNow); interactionEvent.EngagementValue = 0; interactionEvent.Text = "Not available"; Interaction interaction = new Interaction(existingContact, InteractionInitiator.Contact, Settings.OnlineChannelId, "console demo test"); interaction.Events.Add(interactionEvent); client.AddInteraction(interaction); client.Submit(); } catch (Exception ex) { System.Console.WriteLine(ex.Message); System.Console.WriteLine(ex.StackTrace); } } }
public void UpdateContactFacets(ContactFacetData data) { var id = this.GetContactId(); if (id == null) { return; } var contactReference = new IdentifiedContactReference(id.Source, id.Identifier); using (var client = SitecoreXConnectClientConfiguration.GetClient()) { try { var contact = client.Get(contactReference, new ContactExpandOptions(this.facetsToUpdate)); if (contact == null) { return; } var changed = false; changed |= SetPersonalInfo(data, contact, client); changed |= this.SetPhone(data, contact, client); changed |= this.SetEmail(data, contact, client); changed |= this.SetAvatar(data, contact, client); changed |= SetSportsInterests(data, contact, client); if (changed) { client.Submit(); this.UpdateTracker(); } } catch (XdbExecutionException ex) { Log.Error($"Could not update the xConnect contact facets", ex, this); } } }
public void SetVolleyGroupExternalId(string externalId) { using (var client = SitecoreXConnectClientConfiguration.GetClient()) { try { var source = WebsiteSourceIdentifier; var reference = new IdentifiedContactReference(source, externalId); var existingContact = client.Get(reference, new ContactExpandOptions(VolleyGroupFacet.DefaultFacetKey)); if (existingContact == null) { var contact = new Contact( new ContactIdentifier(source, externalId, ContactIdentifierType.Known)); var customFacet = contact.GetVolleyGroupFacet() ?? new VolleyGroupFacet(); customFacet.ExternalId = externalId; client.SetFacet(contact, customFacet); client.AddContact(contact); client.Submit(); } Tracker.Current.Session.IdentifyAs(source, externalId); } catch (Exception ex) { Log.Error(ex.Message, this); } } }
private async Task <Contact> RetrieveContactAsync(XConnectClient client, string MarketingIdentifier) { Contact toReturn = null; try { var identifierContactReference = new IdentifiedContactReference(MarketingConst.XConnect.ContactIdentifiers.Sources.Marketing, MarketingIdentifier); var expandOptions = new ContactExpandOptions( AddressList.DefaultFacetKey, EmailAddressList.DefaultFacetKey, CinemaBusinessMarketing.DefaultFacetKey, PersonalInformation.DefaultFacetKey ); toReturn = await client.GetAsync(identifierContactReference, expandOptions); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(toReturn); }
public bool ForgetUser() { var id = _contactIdentificationRepository.GetContactId(); if (id == null) { return(false); } var contactReference = new IdentifiedContactReference(id.Source, id.Identifier); using (var client = _contactIdentificationRepository.CreateContext()) { var contact = client.Get(contactReference, new ContactExpandOptions()); if (contact != null) { client.ExecuteRightToBeForgotten(contact); client.Submit(); } } return(false); }
public void SetEmail(string key, string email, IdentifiedContactReference reference) { using (var client = SitecoreXConnectClientConfiguration.GetClient()) { var contact = client.Get(reference, new ExpandOptions(EmailAddressList.DefaultFacetKey)); var emailAddress = new EmailAddress(email, true); var emailAddressList = contact.GetFacet <EmailAddressList>(EmailAddressList.DefaultFacetKey); if (emailAddressList == null) { emailAddressList = new EmailAddressList(emailAddress, key); } else { emailAddressList.PreferredKey = key; emailAddressList.PreferredEmail = emailAddress; } client.SetFacet(contact, EmailAddressList.DefaultFacetKey, emailAddressList); client.Submit(); } }
public bool IsGoalTriggered(ID goalId, decimal hours) { Assert.IsNotNull(Tracker.Current, "Tracker.Current"); Assert.IsNotNull(Tracker.Current.Session, "Tracker.Current.Session"); Assert.IsNotNull(goalId, "goalId"); Assert.IsNotNull(hours, "hours"); using (XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try { var time = Decimal.ToDouble(hours); var allInteractionsExpandOptions = new ContactExpandOptions() { Interactions = new RelatedInteractionsExpandOptions() { Limit = int.MaxValue } }; var reference = new IdentifiedContactReference("xDB.Tracker", Tracker.Current.Session.Contact.ContactId.ToString("N")); var actualContact = client.Get(reference, allInteractionsExpandOptions); var interactions = actualContact.Interactions; var goals = interactions.Select(x => x.Events.OfType <Goal>()).SelectMany(x => x).OrderByDescending(x => x.Timestamp); var desiredGoal = goals.FirstOrDefault(x => TypeExtensions.ToID(x.DefinitionId) == goalId); return(desiredGoal?.Timestamp.AddHours(time) >= DateTime.UtcNow); } catch (XdbExecutionException ex) { Log.Error(ex.Message, ex, this); } } return(false); }
public bool DeleteContact() { var id = this.GetContactId(); if (id == null) { return(false); } var contactReference = new IdentifiedContactReference(id.Source, id.Identifier); using (var client = SitecoreXConnectClientConfiguration.GetClient()) { try { var contact = client.Get(contactReference, new Sitecore.XConnect.ContactExpandOptions() { }); if (contact == null) { return(false); } client.ExecuteRightToBeForgotten(contact); client.Submit(); return(true); } catch (XdbExecutionException ex) { Log.Error($"Could not delete the xConnect contact", ex, this); return(false); } } }