private async Task PushCustomer(string IdentificationSource, string channelId, IGrouping <string, Interaction> interaction)
        {
            var events = interaction.Select(x => x.GetEvent()).ToArray();
            var defaultInteractionQuery = UTEntitiesBuilder.Interaction()
                                          .ChannelId(channelId)
                                          .Initiator(InteractionInitiator.Brand)
                                          .Contact(IdentificationSource, interaction.Key);

            var defaultInteraction = defaultInteractionQuery.Build();

            using (var session = SitecoreUTSessionBuilder.SessionWithHost(instanceUrl)
                                 .DefaultInteraction(defaultInteraction)
                                 .BuildSession())
            {
                foreach (var e in events)
                {
                    var eventRequest = UTRequestBuilder.GoalEvent(e.DefinitionId, e.Timestamp.GetValueOrDefault())
                                       .EngagementValue(e.EngagementValue.GetValueOrDefault())
                                       .AddCustomValues(e.CustomValues)
                                       .Duration(new TimeSpan(3000))
                                       .ItemId(e.ItemId)
                                       .Text(e.Text).Build();
                    var eventResponse = await session.TrackGoalAsync(eventRequest);

                    Console.WriteLine("Track EVENT RESULT: " + eventResponse.StatusCode);
                }
            }
            Console.WriteLine($"Customer {interaction.Key} imported");
        }
Example #2
0
        private async Task<bool> SendInteraction(SmsRequest incomingMessage)
        {
            //TODO: Move to config
            string instanceUrl = Sitecore.Configuration.Settings.GetSetting("FGSMS.UTInstanceURL");
            string channelId = Sitecore.Configuration.Settings.GetSetting("FGSMS.UTChannelId"); ;
            string definitionId = Sitecore.Configuration.Settings.GetSetting("FGSMS.UTEventDefinitionId");
            string contactIdentifierName = Sitecore.Configuration.Settings.GetSetting("FGSMS.ContactIdentifierName");
            string apiUserAgent = Sitecore.Configuration.Settings.GetSetting("FGSMS.APIUserAgent");
            string customValueBodyKey = Sitecore.Configuration.Settings.GetSetting("FGSMS.CustomValueBodyKey");


            var defaultInteraction = UTEntitiesBuilder.Interaction()
                                            .ChannelId(channelId)
                                            .Initiator(InteractionInitiator.Contact)
                                            .Contact(contactIdentifierName, incomingMessage.From)
                                            .UserAgent(apiUserAgent)
                                            .Build();

            using (var session = SitecoreUTSessionBuilder.SessionWithHost(instanceUrl)
                                    .DefaultInteraction(defaultInteraction)
                                    .BuildSession())
            {

                var timestamp = DateTime.Now;
                var eventRequest = UTRequestBuilder.EventWithDefenitionId(definitionId)
                .Timestamp(timestamp)
               .Build();

                await session.TrackEventAsync(eventRequest);

                if (incomingMessage.Body.ToUpper().StartsWith("QUOTE"))
                {
                    var goalRequest = UTRequestBuilder.GoalEvent("1640AD87-4087-4CBA-8A62-7D8062877E78", timestamp)
                   
                   .AddCustomValues(new Dictionary<string, string>{
                                        { customValueBodyKey, incomingMessage.Body }
                   }).Build();
                    await session.TrackGoalAsync(goalRequest);
                }
                else if (incomingMessage.Body.ToUpper().StartsWith("BUY"))
                {
                    var goalRequest = UTRequestBuilder.GoalEvent("644AC72C-A006-4819-BE52-EE3ECA4FB54E", timestamp)
                 
                  .AddCustomValues(new Dictionary<string, string>{
                                        { customValueBodyKey, incomingMessage.Body }
                  }).Build();
                    await session.TrackGoalAsync(goalRequest);

                }

                await session.CompleteCurrentInteractionAsync();
            }
            return true;

        }
Example #3
0
        public async void Register()
        {
            try
            {
                RegisterInteractions ri = new RegisterInteractions();
                TrackerSettings      trackerSettings = await ri.GetTrackerSettings();

                if (trackerSettings.IsTrackingActive)
                {
                    string instanceUrl        = trackerSettings.ServiceURL; //Collection service url
                    string channelId          = trackerSettings.ChannelID;  //channel id must be add in config.json
                    string eventDefinitionId  = trackerSettings.Event;      //event id
                    string goalDefinitionId   = trackerSettings.Goals;      //goal id
                    var    defaultInteraction = UTEntitiesBuilder.Interaction()
                                                .ChannelId(channelId)
                                                .Initiator(InteractionInitiator.Contact)
                                                .Contact("MobileAPP", "Anonymous")
                                                .Build();

                    using (var session = SitecoreUTSessionBuilder.SessionWithHost(instanceUrl)
                                         .DefaultInteraction(defaultInteraction)
                                         .BuildSession()
                           )
                    {
                        //trigerring the event
                        var eventRequest = UTRequestBuilder.EventWithDefenitionId(eventDefinitionId)
                                           .AddCustomValues("MobileAppUniversalTraker", "10")
                                           .Timestamp(DateTime.Now)
                                           .Build();
                        var eventResponse = await session.TrackEventAsync(eventRequest);

                        //Triggering the goal
                        var goalRequest  = UTRequestBuilder.GoalEvent(goalDefinitionId, DateTime.Now).Build();
                        var goalResponse = await session.TrackGoalAsync(goalRequest);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("Error occurred in Regitser methos of RegisterInteraction", ex.Message);
            }
        }
Example #4
0
        private async void SendAllRequests()
        {
            //#region Track_Interaction

            var interactionRequest = UTRequestBuilder.Interaction(new UTEvent(null, null, null, null, null, null, null, null, null))
                                     .ChannelId("27b4e611-a73d-4a95-b20a-811d295bdf65")
                                     .Initiator(InteractionInitiator.Contact)
                                     .Contact("jsdemo", "demo")
                                     .Build();

            var interactionResponse = await session.TrackInteractionAsync(interactionRequest);

            Console.WriteLine("Track INTERACTION RESULT: " + interactionResponse.StatusCode.ToString());


            //#endregion Track_Interaction

            #region Track_Base_Event

            Dictionary <string, string> customParameters = new Dictionary <string, string>();
            customParameters.Add("param11", "paramValue11");
            customParameters.Add("param22", "paramValue22");
            customParameters.Add("param33", "paramValue33");
            //customParameters.Add("key2", "value2"); //error expected, testing duplicated keys

            var eventRequest = UTRequestBuilder.EventWithDefenitionId("01f8ffbf-d662-4a87-beee-413307055c48")
                               .AddCustomValues("key1", "value1")
                               .AddCustomValues("key2", "value2")
                               .AddCustomValues(customParameters)
                               .ParentEventId("01f8ffbf-d662-4a87-beee-413307055c48")
                               .Timestamp(DateTime.Now)
                               .Build();

            var eventResponse = await session.TrackEventAsync(eventRequest);

            Console.WriteLine("Track EVENT RESULT: " + eventResponse.StatusCode.ToString());

            #endregion Track_Base_Event

            #region Track_PageView

            var pageViewRequest = UTRequestBuilder.PageViewWithDefenitionId("01f8ffbf-d662-4a87-beee-413307055c48")
                                  .Timestamp(DateTime.Now)
                                  .ItemId("01f8ffbf-d662-4a87-beee-413307055c48")
                                  .ItemVersion(1)
                                  .ItemLanguage("en")
                                  .AddCustomValues("key", "value")
                                  .Build();

            var pageViewResponse = await this.session.TrackPageViewEventAsync(pageViewRequest);

            Console.WriteLine("Track PAGEVIEW EVENT RESULT: " + pageViewResponse.StatusCode.ToString());

            #endregion Track_PageView

            #region Track_Search

            var searchRequest = UTRequestBuilder.SearchEvent("some keywords")
                                .DefinitionId("01f8ffbf-d662-4a87-beee-413307055c48")
                                .Timestamp(DateTime.Now)
                                .AddCustomValues("key", "value")
                                .Build();

            var searchResponse = await session.TrackSearchEventAsync(searchRequest);

            Console.WriteLine("Track SEARCH EVENT RESULT: " + searchResponse.StatusCode.ToString());

            #endregion Track_search

            #region Track_Location_Event

            double lat = 37.342454;
            double lon = -122.342454;

            var locationEventRequest = UTRequestBuilder.LocationEvent(lat, lon)
                                       .DefinitionId("01f8ffbf-d662-4a87-beee-413307055c48")
                                       .Timestamp(DateTime.Now)
                                       .Build();

            var locationEventResponse = await session.TrackLocationEventAsync(locationEventRequest);

            Console.WriteLine("Track LOCATION EVENT RESULT: " + locationEventResponse.StatusCode.ToString());

            #endregion Track_Location_Event

            #region Track_Error_Event

            string error            = "PARSER_EXEPTION";
            string errorDescription = "something went wrong while parsing event response";

            var errorEventRequest = UTRequestBuilder.ErrorEvent(error, errorDescription)
                                    .DefinitionId("01f8ffbf-d662-4a87-beee-413307055c48")
                                    .Timestamp(DateTime.Now)
                                    .Build();

            var errorEventResponse = await session.TrackErrorEventAsync(errorEventRequest);

            Console.WriteLine("Track ERROR EVENT RESULT: " + errorEventResponse.StatusCode.ToString());

            #endregion Track_Error_Event

            #region App_Launched_Event

            var appLaunchedEventRequest = UTRequestBuilder.AppLaunchedEvent()
                                          .DefinitionId("01f8ffbf-d662-4a87-beee-413307055c48")
                                          .Timestamp(DateTime.Now)
                                          .Build();

            var appLaunchedEventResponse = await session.TrackEventAsync(appLaunchedEventRequest);

            Console.WriteLine("Track APP LAUNCHED EVENT RESULT: " + appLaunchedEventResponse.StatusCode.ToString());

            #endregion App_Launched_Event

            #region App_Finished_Event

            var appFinishedEventRequest = UTRequestBuilder.AppFinishedEvent()
                                          .DefinitionId("01f8ffbf-d662-4a87-beee-413307055c48")
                                          .Timestamp(DateTime.Now)
                                          .Build();

            var appFinishedEventResponse = await session.TrackEventAsync(appFinishedEventRequest);

            Console.WriteLine("Track APP FINISHED EVENT RESULT: " + appFinishedEventResponse.StatusCode.ToString());

            #endregion App_Finished_Event

            #region Page_Opened_Event

            DateTime timeStamp = DateTime.UtcNow;

            var pageOpenedEventRequestRB = UTRequestBuilder.PageOpenedEvent("pageId", timeStamp)
                                           .DefinitionId("01f8ffbf-d662-4a87-beee-413307055c48");
            var pageOpenedEventRequest = pageOpenedEventRequestRB.Build();


            var pageOpenedEventResponse = await session.TrackEventAsync(pageOpenedEventRequest);

            å
            Console.WriteLine("Track PAGE OPENED EVENT RESULT: " + pageOpenedEventResponse.StatusCode.ToString());

            #endregion Page_Opened_Event

            #region Page_Closed_Event

            var pageClosedEventRequest = UTRequestBuilder.PageClosedEvent("pageId", timeStamp)
                                         .DefinitionId("01f8ffbf-d662-4a87-beee-413307055c48")
                                         .Timestamp(DateTime.Now)
                                         .Build();

            var pageClosedEventResponse = await session.TrackEventAsync(pageClosedEventRequest);

            Console.WriteLine("Track PAGE CLOSED EVENT RESULT: " + pageClosedEventResponse.StatusCode.ToString());

            #endregion Page_Closed_Even


            #region Outcome_Event

            var outcome = UTRequestBuilder.OutcomeWithDefenitionId("01f8ffbf-d662-4a87-beee-413307055c48")
                          .Text("")
                          .CurrencyCode("bla")
                          .MonetaryValue(11)
                          .Build();

            var outcomeResponse = await session.TrackOutcomeEventAsync(outcome);

            Console.WriteLine("Track OUTCOME EVENT RESULT: " + outcomeResponse.StatusCode.ToString());

            #endregion Outcome_Event


            #region Device_Info

            UIDevice deviceInfo = UIDevice.CurrentDevice;

            var deviceInfoRequest = UTRequestBuilder.DeviceInformationEvent(deviceInfo.Name)
                                    .DefinitionId("01f8ffbf-d662-4a87-beee-413307055c48")
                                    .DeviceIdentifier("bugaga")
                                    .BatteryLevel(deviceInfo.BatteryLevel)
                                    .OperatingSystem(deviceInfo.SystemName, deviceInfo.SystemVersion)
                                    .Build();

            var deviceInfoResponse = await session.TrackEventAsync(deviceInfoRequest);

            Console.WriteLine("Track DEVICE INFO EVENT RESULT: " + deviceInfoResponse.StatusCode.ToString());

            #endregion Device_Info


            #region Goal_Event

            var goalEvent = UTRequestBuilder.GoalEvent("01f8ffbf-d662-4a87-beee-413307055c48", DateTime.Now)
                            .Text("bla")
                            .Build();

            var goalResponse = await session.TrackGoalAsync(goalEvent);

            Console.WriteLine("Track GOAL EVENT RESULT: " + goalResponse.StatusCode.ToString());

            #endregion Goal_Event

            #region Campaign_Event

            var campaignEvent = UTRequestBuilder.CampaignEvent("01f8ffbf-d662-4a87-beee-413307055c48")
                                .DefinitionId("01f8ffbf-d662-4a87-beee-413307055c48")
                                .Text("")
                                .Build();

            var campaignResponse = await session.TrackCampaignEventAsync(campaignEvent);

            Console.WriteLine("Track CAMPAIGN EVENT RESULT: " + campaignResponse.StatusCode.ToString());

            #endregion Campaign_Event

            #region Download_Event

            var downloadEvent = UTRequestBuilder.DownloadEvent()
                                .DefinitionId("01f8ffbf-d662-4a87-beee-413307055c48")
                                .ItemId("01f8ffbf-d662-4a87-beee-413307055c48")
                                .Text("")
                                .Build();

            var downloadResponse = await session.TrackDownloadEventAsync(downloadEvent);

            Console.WriteLine("Track DOWNLOAD EVENT RESULT: " + downloadResponse.StatusCode.ToString());

            #endregion Download_Event
        }