示例#1
0
        private static void Main2(string[] args)
        {
            Randomness.Seed(1337);


            var segment = new VisitorSegment("Test");

            segment.VisitorVariables.Add(Variables.Fixed("Country", "DK"));

            //Simulate visitors from Jan 1 2012 until now
            segment.StartDateTime(new DateTime(2012, 1, 1), DateTime.Now,
                                  //Create a linear trend in year
                                  d => d.Year(trend => trend.SetLevel(0).LineRelativePercentage(1, 1))
                                  //Add a peak in the summer
                                  .PartOfYear(trend => trend.AddPeak(0.5, 0.1, pct: true)));


            var simulator = new SegmentBasedSimulator(segment);

            //Create a 1000 visitors. These are ordered by start date
            foreach (var visitor in simulator.NextVisitors(1000))
            {
                System.Console.Out.WriteLine(".");
                var ctx = new SitecoreRequestContext("http://sc80rev150209/", visitor);

                using (var visit = ctx.NewVisit())
                {
                    //Request home page as if coming from Google
                    visit.Request("/", TimeSpan.FromSeconds(2), new { Referrer = "http://www.google.com" });


                    //Request home page again
                    var info = visit.Request("/", TimeSpan.FromSeconds(2));

                    //"info" contains information from Sitecore, including the item displayed, it's fields, the visit's current VisitData from the tracker etc.
                    //This can be used to change the behavior of the visit
                    if (info.VisitData.ContactVisitIndex == 2)
                    {
                    }
                }

                //Wait 14 days before making the next visit
                ctx.Pause(TimeSpan.FromDays(14));


                using (var visit = ctx.NewVisit())
                {
                    visit.Request("/", TimeSpan.FromSeconds(2));

                    System.Console.Out.WriteLine(visit.VisitData.ContactVisitIndex);
                }
            }
        }
示例#2
0
        protected override IEnumerable <Visit> Commit(SitecoreRequestContext ctx)
        {
            using (var visitContext = ctx.NewVisit())
            {
                var outcomes = visitContext.Visit.GetVariable <IEnumerable <TriggerOutcomeData> >("TriggerOutcomes")?.ToArray();
                visitContext.Visit.Variables.Remove("TriggerOutcomes");

                UploadContactPicture(visitContext.Visit.Variables);

                for (var i = 0; i < this.pages.Count; i++)
                {
                    var page = this.pages[i];

                    if (outcomes != null && i == this.pages.Count - 2)
                    {
                        foreach (var oc in outcomes)
                        {
                            oc.DateTime = visitContext.Visit.End;
                        }
                        page.RequestVariables.Add("TriggerOutcomes", outcomes);
                    }

                    visitContext.Request(page.Path.Replace("/sitecore/media library/", "/-/media/"), TimeSpan.FromSeconds(Randomness.Random.Next(10, 200)), page.RequestVariables);
                }

                yield return(visitContext.Visit);
            }
        }
示例#3
0
        protected override IEnumerable <Visit> Commit(SitecoreRequestContext ctx)
        {
            var visits = ctx.Visitor.GetVariable <double>("VisitCount", 1);

            for (var i = 0; i < visits; i++)
            {
                double pause = 0;
                using (var visitContext = ctx.NewVisit())
                {
                    var outcomes = visitContext.Visit.GetVariable <IEnumerable <TriggerOutcomeData> >("TriggerOutcomes");
                    visitContext.Visit.Variables.Remove("TriggerOutcomes");

                    pause = visitContext.Visit.GetVariable <double>("Pause");

                    var landingPage = visitContext.Visit.GetVariable <string>("LandingPage");
                    if (string.IsNullOrEmpty(landingPage))
                    {
                        throw new Exception("Expected LandingPage");
                    }

                    var history  = new List <string>();
                    var response = visitContext.Request(landingPage);
                    history.Add(landingPage);

                    var pageViews = (int)visitContext.Visit.GetVariable <double>("PageViews") - 1;

                    if (visitContext.Visit.GetVariable("Bounce", false))
                    {
                        pageViews = 1;
                    }

                    var internalSearchIndex = Randomness.Random.Next(0, pageViews);

                    for (var j = 0; j < pageViews; j++)
                    {
                        var nextUrl = this.GetNextUrl(response);
                        if (string.IsNullOrEmpty(nextUrl))
                        {
                            nextUrl = history.Count > 1 ? history[history.Count - 2] : history[0];
                        }
                        else
                        {
                            history.Add(nextUrl);
                        }

                        //Add outcomes to last visit
                        var variables = new Dictionary <string, object>();
                        if (j == pageViews - 1 && outcomes != null)
                        {
                            foreach (var oc in outcomes)
                            {
                                oc.DateTime = visitContext.Visit.End;
                            }
                            variables.Add("TriggerOutcomes", outcomes);
                        }

                        var events = new List <TriggerEventData>();
                        if (j == internalSearchIndex)
                        {
                            var internalKeywords = visitContext.Visit.GetVariable <string>("InternalSearch");
                            if (!string.IsNullOrEmpty(internalKeywords))
                            {
                                events.Add(new TriggerEventData
                                {
                                    Name = "Local search",
                                    Id   = AnalyticsIds.SearchEvent.ToGuid(),
                                    Text = internalKeywords
                                });
                            }
                        }

                        if (events.Count > 0)
                        {
                            variables.Add("TriggerEvents", events);
                        }

                        response = visitContext.Request(nextUrl, variables: variables);
                    }

                    yield return(visitContext.Visit);
                }

                ctx.Pause(TimeSpan.FromDays(pause));
            }
        }