private static void AddInteraction( IXdbContext client, Contact contact, IEnumerable <Guid> goalIds, IEnumerable <Guid> outcomeIds, IEnumerable <Guid> eventIds, Guid campaignId) { var interaction = new Interaction(contact, InteractionInitiator.Brand, SystemChannelId, UserAgent); foreach (Guid goalId in goalIds) { var goal = new Goal(goalId, DateTime.UtcNow) { Duration = new TimeSpan(0, 0, 30) }; interaction.Events.Add(goal); } foreach (Guid outcomeId in outcomeIds) { var outcome = new Outcome(outcomeId, DateTime.UtcNow, "usd", 100.00m); interaction.Events.Add(outcome); } foreach (Guid eventId in eventIds) { var pageEvent = new Event(eventId, DateTime.UtcNow) { Duration = new TimeSpan(0, 0, 30) }; interaction.Events.Add(pageEvent); } interaction.CampaignId = campaignId; client.AddInteraction(interaction); }
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); }
public async Task <ActionResult> GenerateData(int amountOfContacts = 10, int amountOfInteractions = 10) { using (IXdbContext xdbContext = SitecoreXConnectClientConfiguration.GetClient()) { for (var c = 0; c < amountOfContacts; c++) { var contact = new Contact(new ContactIdentifier("sitecore.demo", Guid.NewGuid().ToString(), ContactIdentifierType.Known)); var currentDate = DateTime.UtcNow; xdbContext.AddContact(contact); for (var i = 1; i <= amountOfInteractions; i++) { // Even are morning runners. 10AM for morning runner and 6PM for evening one. : var startTime = 10 + c % 2 * 8; var startDate = currentDate.Date.AddDays(-i).AddHours(startTime); var endDate = startDate.AddHours(1); var interaction = new Interaction(contact, InteractionInitiator.Contact, /*TODO: Channel ID*/ Guid.NewGuid(), "Some Agent") { Events = { new RunStarted(/*TODO: Definition ID*/ Guid.NewGuid(), startDate) { Time = startDate }, new RunEnded(/*TODO: Definition ID*/ Guid.NewGuid(), endDate) { Time = endDate } } }; xdbContext.AddInteraction(interaction); } } await xdbContext.SubmitAsync(); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
private void AddEngagementValue(IXdbContext client, Contact contact) { if (string.IsNullOrWhiteSpace(tbEngagementValue.Text)) { return; } int engagementValue = int.Parse(tbEngagementValue.Text, CultureInfo.CurrentCulture); var interaction = new Interaction(contact, InteractionInitiator.Brand, SystemChannelId, UserAgent); var engagementValueEvent = new Event(Guid.NewGuid(), DateTime.UtcNow) { EngagementValue = engagementValue }; interaction.Events.Add(engagementValueEvent); client.AddInteraction(interaction); }