コード例 #1
0
        private void SetContactFacets(User user)
        {
            IContactPersonalInfo personalFacet = Tracker.Current.Contact.GetFacet <IContactPersonalInfo>("Personal");

            personalFacet.FirstName = string.Empty;
            personalFacet.Surname   = user.LocalName;
        }
コード例 #2
0
        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";
                }
            }
        }
コード例 #3
0
        public TrackerDetails GetTracker(PageDetails data)
        {
            var Tracker = this.GetTracker(false);

            if (Tracker == null || !Tracker.IsActive)
            {
                throw new ArgumentException("Context is invalid");
            }

            var pageId = Guid.Empty;

            Guid.TryParse(data.pageId, out pageId);

            var pageInteraction = Tracker.Interaction.Pages.LastOrDefault(a => a.Item.Id == pageId);
            var page            = pageInteraction != null?Tracker.Interaction.GetPage(pageInteraction.VisitPageIndex) : Tracker.Interaction.PreviousPage;

            var details = new TrackerDetails();

            foreach (var pageEvent in page.PageEvents)
            {
                EventDetails eventDetails = new EventDetails();
                eventDetails.name   = pageEvent.Name;
                eventDetails.text   = pageEvent.Text;
                eventDetails.value  = pageEvent.Value.ToString();
                eventDetails.isGoal = pageEvent.IsGoal ? "1" : "0";
                details.events.Add(eventDetails);
            }

            details.contactId = Tracker.Contact.ContactId.ToString();
            details.userName  = Tracker.Contact.Identifiers.Identifier;

            try
            {
                Contact contact = Tracker.Contact;
                IContactPersonalInfo personal = contact.GetFacet <IContactPersonalInfo>("Personal");
                details.name = string.Format("{0} {1} {2}", personal.FirstName, personal.MiddleName, personal.Surname);
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error("Could not get Name", ex);
            }

            try
            {
                Contact contact = Tracker.Contact;
                IContactEmailAddresses emails = contact.GetFacet <IContactEmailAddresses>("Personal");
                details.email = emails.Entries[emails.Preferred].SmtpAddress;
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error("Could not get Preferred Email Address", ex);
            }

            Tracker.CurrentPage.Cancel();

            return(details);
        }
コード例 #4
0
 public void ShouldSetContactProfile([Frozen] IContactProfileProvider contactProfileProvider, string key, IPhoneNumber phoneNumber, string firstName, string lastName, IContactPersonalInfo personalInfo, Sitecore.Analytics.Tracking.Contact contact)
 {
   contactProfileProvider.Contact.Returns(contact);
   var contactProfileService = new ContactProfileService(contactProfileProvider);
   contactProfileProvider.PersonalInfo.Returns(personalInfo);
   var profile = new EditProfile();
   profile.FirstName = firstName;
   profile.LastName = lastName;
   profile.PhoneNumber = phoneNumber.Number;
   contactProfileService.SetProfile(profile);
   contactProfileProvider.PersonalInfo.FirstName.ShouldBeEquivalentTo(profile.FirstName);
   contactProfileProvider.PersonalInfo.Surname.ShouldBeEquivalentTo(profile.LastName);
   contactProfileProvider.PhoneNumbers.Entries[contactProfileProvider.PhoneNumbers.Preferred].Number.ShouldBeEquivalentTo(profile.PhoneNumber);
 }
コード例 #5
0
        public static void SaveContact(string userName, string firstName, string lastName, DateTime birthDate, string emailAddress, string workEmailAddress)
        {
            Contact contact = Tracker.Current.Contact;

            contact.Identifiers.AuthenticationLevel = AuthenticationLevel.PasswordValidated;
            Tracker.Current.Session.Identify(userName);

            IContactPersonalInfo personal = contact.GetFacet <IContactPersonalInfo>("Personal");

            personal.FirstName = firstName;
            personal.Surname   = lastName;
            personal.BirthDate = birthDate;

            // Storing multiple email address
            IContactEmailAddresses email = contact.GetFacet <IContactEmailAddresses>("Emails");
            var personalEmail            = email.Entries.Create("personal");

            personalEmail.SmtpAddress = emailAddress;

            var workEmail = email.Entries.Create("work");

            workEmail.SmtpAddress = emailAddress;

            email.Preferred = "personal";

            // Storing multiple Addresses
            IContactAddresses address     = contact.GetFacet <IContactAddresses>("Addresses");
            IAddress          homeAddress = address.Entries.Create("home");

            homeAddress.StreetLine1   = "Address 1 - Home";
            homeAddress.City          = "New York";
            homeAddress.StateProvince = "NY";
            homeAddress.PostalCode    = "03587";

            IAddress officeAddress = address.Entries.Create("office");

            officeAddress.StreetLine1   = "Address 1 - Office";
            officeAddress.City          = "New York";
            officeAddress.StateProvince = "NY";
            officeAddress.PostalCode    = "03587";

            address.Preferred = "home";

            // Add custom details in System Facets - Tag and Extensions
            contact.Tags.Add("Username", userName);
            contact.Tags.Add("Full name", firstName + " " + lastName);

            contact.Extensions.SimpleValues["Username"]  = userName;
            contact.Extensions.SimpleValues["Full Name"] = firstName + " " + lastName;
        }
コード例 #6
0
        private static void SetPersonalInfo(Session session, IPrincipalClaimsInformation principalClaimsInformation)
        {
            IContactPersonalInfo personalInfo = session.Contact.GetFacet <IContactPersonalInfo>("Personal");

            personalInfo.FirstName = principalClaimsInformation.GivenName;
            personalInfo.Surname   = principalClaimsInformation.Surname;

            // if neither the given name nor the surname are specified for the user and
            // the display name is then we fall back to that field
            if (string.IsNullOrEmpty(principalClaimsInformation.GivenName) &&
                string.IsNullOrEmpty(principalClaimsInformation.Surname) &&
                !string.IsNullOrEmpty(principalClaimsInformation.DisplayName))
            {
                personalInfo.Surname = principalClaimsInformation.DisplayName;
            }
        }
コード例 #7
0
        public void ShouldSetContactProfile([Frozen] IContactProfileProvider contactProfileProvider, string key, IPhoneNumber phoneNumber, string firstName, string lastName, IContactPersonalInfo personalInfo, Sitecore.Analytics.Tracking.Contact contact)
        {
            contactProfileProvider.Contact.Returns(contact);
            var contactProfileService = new ContactProfileService(contactProfileProvider);

            contactProfileProvider.PersonalInfo.Returns(personalInfo);
            var profile = new EditProfile();

            profile.FirstName   = firstName;
            profile.LastName    = lastName;
            profile.PhoneNumber = phoneNumber.Number;
            contactProfileService.SetProfile(profile);
            contactProfileProvider.PersonalInfo.FirstName.ShouldBeEquivalentTo(profile.FirstName);
            contactProfileProvider.PersonalInfo.Surname.ShouldBeEquivalentTo(profile.LastName);
            contactProfileProvider.PhoneNumbers.Entries[contactProfileProvider.PhoneNumbers.Preferred].Number.ShouldBeEquivalentTo(profile.PhoneNumber);
        }
コード例 #8
0
 protected virtual void ConfirmContactPersonalInfo(NameValueCollection collection, IContactPersonalInfo info)
 {
     //
     //confirm dob
     DateTime? dob = null;
     DateTime tmpDate;
     var success = DateTime.TryParse(collection["dob"], out tmpDate);
     if (success)
     {
         dob = tmpDate;
     }
     Assert.AreEqual(dob, info.BirthDate);
     //
     //
     ConfirmStringProperty(collection["first"], info.FirstName);
     ConfirmStringProperty(collection["gender"], info.Gender);
     ConfirmStringProperty(collection["job"], info.JobTitle);
     ConfirmStringProperty(collection["middle"], info.MiddleName);
     ConfirmStringProperty(collection["nickname"], info.Nickname);
     ConfirmStringProperty(collection["suffix"], info.Suffix);
     ConfirmStringProperty(collection["last"], info.Surname);
     ConfirmStringProperty(collection["title"], info.Title);
 }
コード例 #9
0
        protected virtual void ConfirmContactPersonalInfo(NameValueCollection collection, IContactPersonalInfo info)
        {
            //
            //confirm dob
            DateTime?dob = null;
            DateTime tmpDate;
            var      success = DateTime.TryParse(collection["dob"], out tmpDate);

            if (success)
            {
                dob = tmpDate;
            }
            Assert.AreEqual(dob, info.BirthDate);
            //
            //
            ConfirmStringProperty(collection["first"], info.FirstName);
            ConfirmStringProperty(collection["gender"], info.Gender);
            ConfirmStringProperty(collection["job"], info.JobTitle);
            ConfirmStringProperty(collection["middle"], info.MiddleName);
            ConfirmStringProperty(collection["nickname"], info.Nickname);
            ConfirmStringProperty(collection["suffix"], info.Suffix);
            ConfirmStringProperty(collection["last"], info.Surname);
            ConfirmStringProperty(collection["title"], info.Title);
        }