public void TestHostCanNotBeNull()
        {
            Assert.Throws <ArgumentNullException>(() =>
                                                  SitecoreUTSessionBuilder.SessionWithHost(null)

                                                  );
        }
Ejemplo n.º 2
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());
            }
        }
        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");
        }
        public void TestTokenValueCanBeNull()
        {
            var session = SitecoreUTSessionBuilder.SessionWithHost("localhost")
                          .TokenValue(null)
                          .BuildSession();

            Assert.IsNotNull(session);
        }
 public void TestTokenIsWriteOnce()
 {
     Assert.Throws <InvalidOperationException>(() =>
                                               SitecoreUTSessionBuilder.SessionWithHost("localhost")
                                               .TokenValue("blablalbal")
                                               .TokenValue("bugaga")
                                               );
 }
        public void TestSessionShouldBeCreatedByTheBuilder()
        {
            var session = SitecoreUTSessionBuilder.SessionWithHost("localhost")
                          .TokenValue("blablalbal")
                          .BuildSession();

            Assert.IsNotNull(session);
        }
Ejemplo n.º 7
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;

        }
Ejemplo n.º 8
0
        private void CreateSession()
        {
            var defaultInteraction = UTEntitiesBuilder.Interaction()
                                     .ChannelId("27b4e611-a73d-4a95-b20a-811d295bdf65")
                                     .Initiator(InteractionInitiator.Contact)
                                     .Contact("jsdemo", "demo")
                                     .Build();

            this.session = SitecoreUTSessionBuilder.SessionWithHost("https://sitecore.tracking.collection.service")  //https://utwebtests
                           .DefaultInteraction(defaultInteraction)
                           .DeviceIdentifier(UIDevice.CurrentDevice.IdentifierForVendor.ToString())
                           .BuildSession();
        }
Ejemplo n.º 9
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);
            }
        }
Ejemplo n.º 10
0
 public void Setup()
 {
     this.session = SitecoreUTSessionBuilder.SessionWithHost(TestEndpointsConfig.InstanceUrl)
                    .BuildSession();
 }
Ejemplo n.º 11
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();
        }