Пример #1
0
        protected override List <DimensionData> GenerateDimensionData(IVisitAggregationContext context, SegmentMetricsValue metrics, OrderModel orderModel)
        {
            List <DimensionData> dimensionDataList = new List <DimensionData>();

            if (orderModel.Event.Order != null & orderModel.Event.Order.CartLines != null && orderModel.Event.Order.CartLines.Any())
            {
                foreach (var cartLine in orderModel.Event.Order.CartLines)
                {
                    if (orderModel.Event.CustomValues.ContainsKey($"PersonalizationId|{cartLine.ExternalCartLineId}"))
                    {
                        var personalizationId = orderModel.Event.CustomValues[$"PersonalizationId|{cartLine.ExternalCartLineId}"];
                        if (!string.IsNullOrEmpty(personalizationId))
                        {
                            SegmentMetricsValue segmentMetricsValue = metrics.Clone();
                            segmentMetricsValue.Count = 1;
                            DimensionData dimensionData = new DimensionData()
                            {
                                DimensionKey = personalizationId,
                                MetricsValue = segmentMetricsValue
                            };
                            dimensionDataList.Add(dimensionData);
                        }
                    }
                }
            }
            return(dimensionDataList);
        }
Пример #2
0
        public override IEnumerable <DimensionData> GetData(IVisitAggregationContext context)
        {
            SegmentMetricsValue metrics = this.CalculateCommonMetrics(context, 0);
            ConcurrentDictionary <string, int> keyCount = this.GetDimensionKeys(context);

            foreach (string index in (IEnumerable <string>)keyCount.Keys)
            {
                int count = keyCount[index];
                SegmentMetricsValue metricsValue = metrics.Clone();
                metricsValue.Count = count;
                yield return(new DimensionData()
                {
                    DimensionKey = index,
                    MetricsValue = metricsValue
                });
            }
        }
        public override IEnumerable <DimensionData> GetData(IVisitAggregationContext context)
        {
            List <DimensionData> dimensionDataList   = new List <DimensionData>();
            DateTime             startTime           = this.LogStartProcessingDimension();
            Interaction          xconnectInteraction = this.ToXConnectInteraction(context.Visit);
            SegmentMetricsValue  metrics             = this.CalculateCommonMetrics(context, 0);

            if (metrics == null)
            {
                this.LogEndProcessingDimension(startTime, 0);
            }
            else
            {
                Guid eventDefinitionId = this.GetPageEventDefinitionId();
                int  numberOfEntries   = 0;
                foreach (var @event in xconnectInteraction.Events)
                {
                    if (@event.DefinitionId == eventDefinitionId && @event.CustomValues.ContainsKey("PersonalizationId") && !string.IsNullOrEmpty(@event.CustomValues["PersonalizationId"]))
                    {
                        var personalizationId = @event.CustomValues["PersonalizationId"];
                        if (!dimensionDataList.Any(dimensionData => dimensionData.DimensionKey.Equals(personalizationId, StringComparison.OrdinalIgnoreCase)))
                        {
                            SegmentMetricsValue segmentMetricsValue = metrics.Clone();
                            segmentMetricsValue.PageViews = xconnectInteraction.Events.Count(e => e.DefinitionId == eventDefinitionId &&
                                                                                             e.CustomValues.ContainsKey("PersonalizationId") &&
                                                                                             e.CustomValues["PersonalizationId"].Equals(personalizationId, StringComparison.OrdinalIgnoreCase));
                            dimensionDataList.Add(new DimensionData()
                            {
                                DimensionKey = personalizationId,
                                MetricsValue = segmentMetricsValue
                            });
                            ++numberOfEntries;
                        }
                    }
                }
                this.LogEndProcessingDimension(startTime, numberOfEntries);
            }
            return(dimensionDataList);
        }
        private static void ProcessDimensionSegments(AggregationPipelineArgs args, VisitData visit, Hash32 sitesHash, InteractionData interactionData)
        {
            foreach(Dimension dimension in Dimensions)
            {
                IEnumerable<Segment> segments = from segment in segmentDefinitionService.GetSegmentDefinitions()
                                                where segment.DimensionId == dimension.DimensionID
                                                select new Segment(segment, dimension);

                foreach(Segment segment in segments)
                {
                    ISegmentKeyProvider keyProvider = null;
                    
                    switch(segment.Dimension.DimensionType)
                    {
                        case DimensionType.Browser:
                            keyProvider = interactionData.Browser;
                            break;
                        case DimensionType.OS:
                            keyProvider = interactionData.OS;
                            break;
                        case DimensionType.Screen:
                            keyProvider = interactionData.Screen;
                            break;
                        case DimensionType.UserAgent:
                            keyProvider = interactionData.UserAgent;
                            break;
                    }

                    string segmentKeyValue = keyProvider.GetSegmentKeyValue();
                    Hash64 segmentDimensionKeyId = args.GetDimension<DimensionKeys>().Add(segmentKeyValue);
                    
                    Hash64 segmentRecordId = args.GetDimension<SegmentRecords>().Add(segment.Definition.Id, visit.StartDateTime, sitesHash, segmentDimensionKeyId);

                    SegmentMetrics segmentMetricsFact = args.GetFact<SegmentMetrics>();
                    byte contactTransitionType = 1;
                    if (visit.ContactVisitIndex > 1) contactTransitionType = 2;

                    SegmentMetrics.Key segmentMetricsKey = new SegmentMetrics.Key
                    {
                        ContactTransitionType = contactTransitionType,
                        SegmentRecordId = segmentRecordId
                    };

                    List<PageEventData> evts = (from page in visit.Pages select page.PageEvents).FirstOrDefault();

                    SegmentMetricsValue segmentMetricsValue = new SegmentMetricsValue
                    {
                        //Same exact code from DimensionBase.CalculateCommonMetrics
                        Visits = 1,
                        Value = visit.Value,
                        Bounces = visit.Pages.Count == 1 ? 1 : 0,
                        Conversions = evts.Count<PageEventData>(e => e.IsGoal),
                        TimeOnSite = visit.Pages.Sum<PageData>((Func<PageData, int>)(page => DimensionBase.ConvertDuration(page.Duration))),
                        Pageviews = visit.Pages.Count,
                        Count = visit.VisitPageCount
                    };

                    segmentMetricsFact.Emit(segmentMetricsKey, segmentMetricsValue);
                }
            }           
        }