Ejemplo n.º 1
0
        private void AddProfileScore(IXdbContext client, Contact contact)
        {
            if (string.IsNullOrWhiteSpace(tbProfileScore.Text) || string.IsNullOrWhiteSpace(tbProfileKeyId.Text) || string.IsNullOrWhiteSpace(tbProfileId.Text))
            {
                return;
            }

            Guid profileId    = Guid.Parse(tbProfileId.Text);
            Guid profileKeyId = Guid.Parse(tbProfileKeyId.Text);
            int  score        = int.Parse(tbProfileScore.Text, CultureInfo.CurrentCulture);

            var interaction          = new Interaction(contact, InteractionInitiator.Brand, SystemChannelId, UserAgent);
            var engagementValueEvent = new Event(ProfileScoreChangeEventDefinitionId, DateTime.UtcNow);

            interaction.Events.Add(engagementValueEvent);
            client.AddInteraction(interaction);

            var profileScores = new ProfileScores();
            var profileScore  = new ProfileScore
            {
                Values =
                {
                    [profileKeyId] = score
                }
            };

            profileScores.Scores.Add(profileId, profileScore);
            client.SetProfileScores(interaction, profileScores);
        }
        private ProfileScores GetProfileScores(IContactProcessingContext context)
        {
            //ContactBehaviorProfile contactFacet = this.GetContactFacet<ContactBehaviorProfile>(context.Contact);

            XConnectClient client = XConnectClientReference.GetClient();

            Contact existingContact = client.Get <Contact>(
                (IEntityReference <Contact>)context.Contact,
                new ContactExpandOptions(ContactBehaviorProfile.DefaultFacetKey));

            ContactBehaviorProfile contactFacet = existingContact.GetFacet <ContactBehaviorProfile>(ContactBehaviorProfile.DefaultFacetKey);

            if (contactFacet == null)
            {
                contactFacet = new ContactBehaviorProfile();
            }

            ChangeContactBehaviorProfileValue.UpdateContactBehaviorProfile(contactFacet.Scores, (IEnumerable <BehaviorProfileValue>) this.BehaviorProfileValues);
            ProfileScores profileScores = new ProfileScores();

            foreach (KeyValuePair <Guid, ProfileScore> keyValuePair in contactFacet.Scores)
            {
                profileScores.Scores.Add(keyValuePair.Key, keyValuePair.Value);
            }

            foreach (var profileScore in profileScores.Scores)
            {
                Log.Debug("profileScore kv Key = " + profileScore.Key);
                Log.Debug("profileScore kv Value = " + profileScore.Value);
            }

            return(profileScores);
        }
        private void Page_Load(object sender, EventArgs e)
        {
            // Put user code to initialize the page here
            ScoreList.DataSource =
                Sitecore.Context.Database.GetItem("/sitecore/content/Repository/Profile Gathering Pages").Children;
            ScoreList.DataBind();

            TrackerDataContext tc = Sitecore.Analytics.Tracker.DataContext;
            StringBuilder      sb = new StringBuilder();

            if (Tracker.CurrentVisit == null)
            {
                return;
            }
            if (Tracker.CurrentVisit.Keywords != null &&
                !String.IsNullOrEmpty(Tracker.CurrentVisit.Keywords.Text))
            {
                sb.Append("Search keywords for current visit: " +
                          Tracker.CurrentVisit.Keywords.Text + ".<br/>");
            }
            const int checkVisits = 10;

            Sitecore.Analytics.Data.DataAccess.VisitorLoadOptions vOptions =
                new Sitecore.Analytics.Data.DataAccess.VisitorLoadOptions
            {
                Start            = Tracker.CurrentVisit.VisitorVisitIndex - 1,
                Count            = Tracker.CurrentVisit.VisitorVisitIndex - checkVisits,
                VisitLoadOptions = VisitLoadOptions.Visits
            };
            foreach (VisitorDataSet.VisitsRow visit in
                     Tracker.Visitor.GetVisits(vOptions).Where(
                         visit => visit.VisitId !=
                         Tracker.CurrentVisit.VisitId).OrderByDescending(
                         visit => visit.VisitorVisitIndex))
            {
                if (visit.Keywords != null &&
                    !String.IsNullOrEmpty(visit.Keywords.Text))
                {
                    sb.Append("Last search keywords from " +
                              visit.StartDateTime + " visit: " +
                              visit.Keywords.Text + "<br/>");
                    return;
                }
            }
            sb.Append("No search keywords for current or last " +
                      checkVisits + " visits.<br/>");


            DMS.Text = sb.ToString();
            var profilesRows = tc.Profiles;

            ProfileScores.DataSource = GetProfileKeys("Keynotes");
            ProfileScores.DataBind();
        }
        public static void AddProfileScore(string contactIdentifier, string occupation)
        {
            if (string.IsNullOrEmpty(contactIdentifier))
            {
                Console.WriteLine("Unable to find contact with empty identifier");
                return;
            }

            using (var client = Client.GetClient())
            {
                var contactReference = new IdentifiedContactReference("VoiceApp", contactIdentifier);
                var contact          = client.Get(contactReference, new ExpandOptions()
                {
                    FacetKeys = { "Personal" }
                });

                if (contact == null)
                {
                    Console.WriteLine("Unable to find contact with identifier:" + contactIdentifier);
                }

                var profileScores = new ProfileScores();

                if (occupation.ToLower() == ProfileConstants.ProfileKeys.DeveloperKeyName)
                {
                    profileScores.Scores.Add(ProfileConstants.ProfileKeys.DeveloperKeyId, ProfileConstants.ProfileScores.DeveloperProfileScore);
                }
                else if (occupation.ToLower() == ProfileConstants.ProfileKeys.MarketerKeyName)
                {
                    profileScores.Scores.Add(ProfileConstants.ProfileKeys.MarketerKeyId, ProfileConstants.ProfileScores.MarketerProfileScore);
                }
                else
                {
                    profileScores.Scores.Add(ProfileConstants.ProfileKeys.DeveloperKeyId, ProfileConstants.ProfileScores.OtherProfileScore);
                }

                //online channel sitecore/system/Marketing Control Panel/Taxonomies/Channel/Online/Apps/Voice App
                var interaction = new Interaction(contact, InteractionInitiator.Contact, Guid.Parse("{BB2CBE9B-C9CD-4A75-8069-E4D72652399B}"), "Voice Transcript");
                // Voice Identification Outcome Guid
                // sitecore/system/Marketing Control Panel/Outcomes/Voice Identification
                var voiceIdentificationOutcomeId = Guid.Parse("{4CDA8824-94A3-45B8-BE0B-920497DBA3DA}");
                var outcome = new Outcome(voiceIdentificationOutcomeId, DateTime.UtcNow, "USD", 50);

                interaction.Events.Add(outcome);

                client.AddInteraction(interaction);

                client.SetProfileScores(interaction, profileScores);
                client.Submit();
            }
        }