Exemple #1
0
        public void TriggerGoal(ID goalId, string movieid, string genre, string rating)
        {
            Assert.IsNotNull(Tracker.Current, "Tracker.Current");
            Assert.IsNotNull(Tracker.Current.Session, "Tracker.Current.Session");
            Assert.IsNotNull(goalId, "goalId");

            using (XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
            {
                try
                {
                    var reference     = new IdentifiedContactReference("xDB.Tracker", Tracker.Current.Session.Contact.ContactId.ToString("N"));
                    var actualContact = client.Get(reference, new ContactExpandOptions());

                    string userAgent   = System.Web.HttpContext.Current?.Request.UserAgent;
                    var    interaction = new Sitecore.XConnect.Interaction(actualContact, InteractionInitiator.Brand, ChannelIds.OnlineDirectChannelId, userAgent);

                    var goal = new Goal(goalId.ToGuid(), DateTime.UtcNow);
                    goal.CustomValues.Add("movieId", movieid);
                    goal.CustomValues.Add("rating", rating);
                    goal.CustomValues.Add("genre", genre);
                    interaction.Events.Add(goal);
                    client.AddInteraction(interaction);
                    client.Submit();
                }
                catch (Exception ex)
                {
                    Log.Error(ex.Message, ex, this);
                }
            }
        }
        private void CreateInteraction(Contact contact, Guid goalId, string goalData)
        {
            using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
            {
                try
                {
                    var newContact = new Sitecore.XConnect.Contact();
                    client.AddContact(newContact);

                    // Create new interaction for this contact
                    Guid   channelId   = Guid.NewGuid(); // Replace with channel ID from Sitecore
                    string userAgent   = "Mozilla/5.0 (Nintendo Switch; ShareApplet) AppleWebKit/601.6 (KHTML, like Gecko) NF/4.0.0.5.9 NintendoBrowser/5.1.0.13341";
                    var    interaction = new Sitecore.XConnect.Interaction(newContact, InteractionInitiator.Brand, channelId, userAgent);


                    // Create new instance of goal
                    Sitecore.XConnect.Goal goal = new Goal(goalId, DateTime.UtcNow);
                    {
                    };
                    goal.Data = goalData;
                    // Add goal to interaction
                    interaction.Events.Add(goal);

                    // Add interaction operation to client
                    client.AddInteraction(interaction);

                    // Submit interaction
                    client.Submit();
                }
                catch (Exception ex)
                {
                    // Handle exception
                }
            }
        }
Exemple #3
0
        public void RegisterGoal(Guid channelID, Guid goalID, string userAgent)
        {
            using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
            {
                try
                {
                    // var contact = new Sitecore.XConnect.Contact();
                    //Guid channelID = Guid.NewGuid();
                    //string userAgent = "Sample User Agent";

                    //string globalCookie = Request.Cookies["SC_ANALYTICS_GLOBAL_COOKIE"].Value;
                    //var reference = new IdentifiedContactReference(Sitecore.XConnect.Constants.AliasIdentifierSource, globalCookie.Split('|')[0]);

                    string trackerID = Sitecore.Analytics.Tracker.Current.Contact.ContactId.ToString();

                    //var reference = new IdentifiedContactReference(Sitecore.XConnect.Constants.AliasIdentifierSource,trackerID);
                    var reference = new IdentifiedContactReference("xDB.Tracker", trackerID);

                    Sitecore.XConnect.Contact contact = client.Get <Sitecore.XConnect.Contact>(reference, new ContactExpandOptions()
                    {
                    });

                    if (contact == null)
                    {
                        contact = new Sitecore.XConnect.Contact();
                    }

                    var interaction = new Sitecore.XConnect.Interaction(contact, InteractionInitiator.Brand, channelID, userAgent);

                    // Guid goalID = Guid.Parse("{9B6DC6A2-EB41-47B5-B10F-39AC37DE214F}"); // ID of goal item

                    var goal = new Goal(goalID, DateTime.UtcNow);

                    goal.EngagementValue = 20; // Manually setting engagement value rather than going to defintion item

                    interaction.Events.Add(goal);



                    client.AddContact(contact);
                    client.AddInteraction(interaction);

                    client.Submit();
                }
                catch (XdbExecutionException ex)
                {
                    // Handle exception
                }
            }
        }
        /// <summary>
        /// Save goal linked to the contat user
        /// </summary>
        /// <param name="interactionType">Goal type</param>
        /// <param name="productId">Product sitecore id</param>
        public void SaveGoal(InteractionType interactionType, Guid productId)
        {
            using (var client = SitecoreXConnectClientConfiguration.GetClient())
            {
                var id = this.GetContactId();
                if (id == null)
                {
                    return;
                }

                var contactReference = new IdentifiedContactReference(id.Source, id.Identifier);
                var contact          = client.Get(contactReference, new ContactExpandOptions()
                {
                    Interactions = new RelatedInteractionsExpandOptions()
                    {
                        StartDateTime = DateTime.MinValue,
                        EndDateTime   = DateTime.MaxValue,
                        Limit         = int.MaxValue
                    }
                });

                if (contact == null)
                {
                    return;
                }

                // Create new interaction for this contact
                Guid   channelId   = Guid.NewGuid(); // Replace with channel ID from Sitecore
                string userAgent   = "Mozilla/5.0 (Nintendo Switch; ShareApplet) AppleWebKit/601.6 (KHTML, like Gecko) NF/4.0.0.5.9 NintendoBrowser/5.1.0.13341";
                var    interaction = new Sitecore.XConnect.Interaction(contact, InteractionInitiator.Brand, channelId, userAgent);

                var goalId = this.GetGoalId(interactionType);

                // Create new instance of goal
                Goal goal = new Goal(goalId, DateTime.UtcNow);

                //Add aditional information like the page id
                goal.CustomValues.Add("page", productId.ToString());

                // Add goal to interaction
                interaction.Events.Add(goal);

                // Add interaction operation to client
                client.AddInteraction(interaction);

                // Submit interaction
                client.Submit();
            }
        }
Exemple #5
0
        public void RegisterInteractionEvent(Event interactionEvent)
        {
            var trackerIdentifier = GetContactReference();

            using (XConnectClient client = SitecoreXConnectClientConfiguration.GetClient())
            {
                var contact = client.Get <Contact>(trackerIdentifier, new ExpandOptions());

                if (contact != null)
                {
                    var interaction = new Sitecore.XConnect.Interaction(contact, InteractionInitiator.Brand, Guid.NewGuid(), "Experience Forms");

                    interaction.Events.Add(interactionEvent);

                    client.AddInteraction(interaction);

                    client.Submit();

                    ReloadContactDataIntoSession();
                }
            }
        }