Exemple #1
0
        public static async void SendBaseEventRequest()
        {
            var defaultInteraction = UTEntitiesBuilder.Interaction()
                                     .ChannelId("27b4e611-a73d-4a95-b20a-811d295bdf65")
                                     .Initiator(InteractionInitiator.Contact)
                                     .Contact("jsdemo", "demo")
                                     .Build();

            using (var session = SitecoreUTSessionBuilder.SessionWithHost("https://utwebtests")
                                 .DefaultInteraction(defaultInteraction)
                                 .BuildSession()
                   )
            {
                string definitionId = "01f8ffbf-d662-4a87-beee-413307055c48";

                var eventRequest = UTRequestBuilder.EventWithDefenitionId(definitionId)
                                   .AddCustomValues("key1", "value1")
                                   .Timestamp(DateTime.Now)
                                   .AddCustomValues("igk", "demo")
                                   .Build();

                var eventResponse = await session.TrackEventAsync(eventRequest);

                Console.WriteLine("Track EVENT RESULT: " + eventResponse.StatusCode.ToString());
            }
        }
Exemple #2
0
        public void TestCancelEvent()
        {
            var request = UTRequestBuilder.EventWithDefenitionId(TestEndpointsConfig.HomeItemID)
                          //  .AddCustomValues("1", "1")
                          .Build();


            var        cancelToken = CreateCancelTokenWithDelay(standardDelay);
            UTResponse response    = null;

            // do not use Task.WaitAll() since it may cause deadlocks
            TestDelegate testCode = async() =>
            {
                var task = this.session.TrackEventAsync(request, cancelToken);
                response = await task;
            };

            var exception = Assert.Catch <OperationCanceledException>(testCode);

            Debug.WriteLine("Expected token : " + cancelToken);
            Debug.WriteLine("Received token : " + exception.CancellationToken);


            Assert.IsNull(response);
            //      Desktop (Windows) : "A task was canceled."
            //      iOS               : "The Task was canceled"
            Assert.IsTrue(exception.Message.ToLowerInvariant().Contains("task was canceled"));

            // CancellationToken class comparison or scheduling works differently on iOS
            // Assert.AreEqual(cancelToken, exception.CancellationToken);
        }
Exemple #3
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;

        }
Exemple #4
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);
            }
        }
Exemple #5
0
        private async void SendBaseEventRequest()
        {
            var eventRequest = UTRequestBuilder.EventWithDefenitionId(someUDID)
                               .AddCustomValues("key1", "value1")
                               .Timestamp(DateTime.Now)
                               .AddCustomValues("igk", "demo")
                               .Build();

            var eventResponse = await session.TrackEventAsync(eventRequest);


            var okCancelAlertController = UIAlertController.Create("Event response code", eventResponse.StatusCode.ToString(), UIAlertControllerStyle.Alert);

            okCancelAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, alert => Console.WriteLine("Ok")));
            PresentViewController(okCancelAlertController, true, null);


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

            var completeResponse = await session.CompleteCurrentInteractionAsync();

            Console.WriteLine("COMPLETE INTERACTION RESULT: " + completeResponse.StatusCode.ToString());
        }
Exemple #6
0
        public static void Main(string[] args)
        {
            string instanceUrl = "https://Hackathon-Sitecore-Tracking-Collection-Service.local.com";
            //string channelId = "6d3d2374-af56-44fe-b99a-20843b440b58";
            string channelId = "6d3d2374-af56-44fe-b99a-20843b440b58";         // Channel Id of the channel: /sitecore/system/Marketing Control Panel/Taxonomies/Channel/Online/Social community/Twitter social community
            //string definitionId = "55555555-d662-4a87-beee-413307055c48";
            string eventDefinitionId = "ff1d9360-8a31-4779-ad1a-d4a8178b865a"; // Goal definitionId of the goal: /sitecore/system/Marketing Control Panel/Goals/Sandbox/Twitter Hackathon

            Auth.SetUserCredentials(TwitterApiKey, TwitterApiSecretKey, TwitterAccessToken, TwitterAccessTokenSecret);
            var user = User.GetAuthenticatedUser();

            // Get all twitter filters and put them in a list
            var filtersFromSitecore = GetFilters();

            // Use the channel from the filter.
            var hashTags               = filtersFromSitecore.Select(p => p.Product_Hashtag.Trim()).Distinct();
            var hashtagString          = string.Join(" OR ", hashTags);
            var accountAgeFilter       = filtersFromSitecore.Select(p => p.Twitter_Account_Age).Distinct();
            var filterOutRetweets      = filtersFromSitecore.FirstOrDefault(p => p.Filter_Out_Retweets);
            var filterMinimumFollowers = filtersFromSitecore.Select(p => p.Minimum_Followers).Distinct();

            System.Console.WriteLine(user);

            var stream = Stream.CreateFilteredStream();

            //stream.AddTrack("\ud83d\udd25"); //fire emoji
            hashTags.ForEach(ht => stream.AddTrack(ht));
            stream.AddTweetLanguageFilter(LanguageFilter.English);

            System.Console.WriteLine("I am listening to Twitter for Product Hashtags:" + hashtagString + "...");

            stream.MatchingTweetReceived += (sender, arguments) =>
            {
                var theTweet = arguments.Tweet;

                //stringify hashtags
                var hashtags      = theTweet.Hashtags.ToList();
                var tweetHashtags = hashtags.Count > 0 ? string.Join(", ", hashtags) : "Not Available";

                // Name
                var name = theTweet.CreatedBy.Name;

                // Name
                var twitterHandle = theTweet.CreatedBy.ScreenName;

                // Number of followers
                var followersCount = theTweet.CreatedBy.FollowersCount;

                // Account Description
                var twitterHandleDescription = theTweet.CreatedBy.Description ?? "Not Available";

                // Created At - Account
                var twitterHandleCreated = theTweet.CreatedBy.CreatedAt;

                // Tweet Full Text
                var tweetFullText = theTweet.FullText;

                // Is Retweet
                var isRetweet = theTweet.IsRetweet;

                // var verified
                var isVerified = theTweet.CreatedBy.Verified;

                System.Console.WriteLine(theTweet.FullText);
                System.Console.WriteLine(hashtagString);
                System.Console.WriteLine(theTweet.CreatedBy);
                System.Console.WriteLine("-------------------------------");
                System.Console.WriteLine();

                if (!theTweet.Retweeted)
                {
                    var defaultInteraction = UTEntitiesBuilder.Interaction()
                                             .ChannelId(channelId)
                                             .Initiator(InteractionInitiator.Contact)
                                             .Contact("twitter", twitterHandle)
                                             .CampaignId("33333333-d662-4a87-beee-413307055c48")
                                             .VenueId("44444444-d662-4a87-beee-413307055c48")
                                             .UserAgent("ConsoleApp not a browser")
                                             .Build();
                    using (var session = SitecoreUTSessionBuilder.SessionWithHost(instanceUrl)
                                         .DefaultInteraction(defaultInteraction)
                                         .TokenValue("mytokenvalue")
                                         .BuildSession()
                           )
                    {
                        var dict = new Dictionary <string, string>();

                        dict.Add("twitterhandle", "@" + twitterHandle);
                        dict.Add("hashtags", tweetHashtags);
                        dict.Add("name", name);
                        dict.Add("followerscount", followersCount.ToString());
                        dict.Add("twitterhandledescription", twitterHandleDescription);
                        dict.Add("twitterhandlecreated", twitterHandleCreated.ToShortDateString());
                        dict.Add("tweetfulltext", tweetFullText);
                        dict.Add("isretweet", isRetweet.ToString());
                        dict.Add("isverified", isVerified.ToString());
                        dict.Add("accountagefilter", accountAgeFilter.ToString());
                        dict.Add("filteroutretweets", filterOutRetweets.ToString());
                        dict.Add("filterminimumfollowers", filterMinimumFollowers.ToString());

                        var eventRequest = UTRequestBuilder.EventWithDefenitionId(eventDefinitionId)
                                           .Timestamp(DateTime.Now)
                                           .AddCustomValues(dict)
                                           .Text(theTweet.FullText)
                                           .Build();
                        var eventResponse = session.TrackEventAsync(eventRequest);
                        System.Console.WriteLine("Track EVENT RESULT: " + eventResponse.Result.StatusCode);
                    }
                }
            };

            stream.StartStreamMatchingAllConditions();

            System.Console.ReadLine();
        }
Exemple #7
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
        }