protected override void OnProcess(AggregationPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            var visit = args.Context.Visit;

            if (visit.Pages != null && 0 < visit.Pages.Count)
            {
                var accountId = UpdateAccountDimension(args);
                var contactId = visit.ContactId;
                var items     = args.GetDimension <Items>();
                var fact      = args.GetFact <ContactsByAccountFact>();

                var key = new ContactsByAccountKey
                {
                    AccountId = accountId,
                    ContactId = contactId,
                    Date      = args.DateTimeStrategy.Translate(visit.StartDateTime),
                };
                var value = new ContactsByAccountValue
                {
                    Bounces     = (visit.VisitPageCount == 1) ? 1 : 0, // If only this page visited, it is a bounce
                    Conversions = visit.Pages.Sum(page => page.PageEvents.Count(x => x.IsGoal)),
                    Duration    = visit.Pages.Sum(page => page.Duration),
                    Value       = visit.Value,
                    Views       = visit.VisitPageCount,
                    Visits      = 1
                };
                fact.Emit(key, value);
            }
        }
        protected override void OnProcess(AggregationPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            var visit   = args.Context.Visit;
            var itemIds = new List <Guid>();

            if (visit.Pages != null && 0 < visit.Pages.Count)
            {
                var accountId = UpdateAccountDimension(args);
                var items     = args.GetDimension <Items>();
                var fact      = args.GetFact <PageViewsByAccountFact>();

                foreach (var page in visit.Pages)
                {
                    if (page.Item.Id == Guid.Empty)
                    {
                        continue;
                    }

                    var itemId = items.Add(page.Item.Id, page.Url.Path);

                    var key = new PageViewsByAccountKey
                    {
                        AccountId = accountId,
                        Date      = args.DateTimeStrategy.Translate(page.DateTime),
                        ItemId    = itemId
                    };
                    var value = new PageViewsByAccountValue
                    {
                        Bounces     = (visit.Pages.Count == 1) ? 1 : 0, // If only this page visited, it is a bounce
                        Conversions = page.PageEvents.Count(x => x.IsGoal),
                        Duration    = page.Duration,
                        Value       = (itemIds.Contains(itemId) ? 0 : visit.Value), // Only add value once to any given page.
                        Views       = 1,
                        Visits      = (itemIds.Contains(itemId)) ? 0 : 1            // Only add a visit once to any given page.
                    };
                    fact.Emit(key, value);
                    itemIds.Add(itemId);
                }
            }
        }
        protected override void OnProcess(AggregationPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            VisitData visit = args.Context.Visit;

            if (visit.Browser == null || visit.OperatingSystem == null || visit.Screen == null || string.IsNullOrEmpty(visit.UserAgent))
            {
                return;
            }            

            Hash32 languageHash = AggregationProcessor.UpdateLanguagesDimension(args);
            Hash32 sitesHash = AggregationProcessor.UpdateSiteNamesDimension(args);

            InteractionData interactionData = new InteractionData(args, visit);

            try
            {
                ProcessDimensionSegments(args, visit, sitesHash, interactionData);
            }
            catch { }
        }
Example #4
0
        protected override void OnProcess(AggregationPipelineArgs args)
        {
            var dimension = args.GetDimension <MediaFrameworkMedia>();
            var fact      = args.GetFact <MediaFrameworkEvents>();

            VisitData visit = args.Context.Visit;

            DateTime date = args.DateTimeStrategy.Translate(visit.StartDateTime);

            foreach (PageEventData pageEvent in this.GetPageEvents(visit))
            {
                var mediaEvent = MediaEventData.Parse(pageEvent);
                if (mediaEvent == null)
                {
                    continue;
                }

                Hash128    mediaId  = dimension.AddValue(mediaEvent);
                Sites.Site site     = Sites.SiteManager.GetSite(visit.SiteName);
                var        encoder  = new Hash32Encoder();
                string     hashName = encoder.Encode(visit.SiteName);

                var key = new MediaFrameworkEventsKey
                {
                    Date    = date,
                    MediaId = mediaId,
                    PageEventDefinitionId = pageEvent.PageEventDefinitionId,
                    EventParameter        = mediaEvent.EventParameter,
                    SiteNameId            = int.Parse(hashName)
                };

                var value = new MediaFrameworkEventsValue {
                    Count = 1
                };

                fact.Emit(key, value);
            }
        }
        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);
                }
            }           
        }
            public InteractionData(AggregationPipelineArgs args, VisitData visit)
            {
                Browsers browserDimension = args.GetDimension<Browsers>();
                OS osDimension = args.GetDimension<OS>();
                Screens screenDimension = args.GetDimension<Screens>();
                UserAgents userAgentDimension = args.GetDimension<UserAgents>();

                Browser = browserDimension.Add(visit.Browser.BrowserMajorName, visit.Browser.BrowserMinorName, visit.Browser.BrowserVersion);                
                OS = osDimension.Add(visit.OperatingSystem.Name);
                Screen = screenDimension.Add(visit.Screen.ScreenHeight, visit.Screen.ScreenWidth);
                UserAgent = userAgentDimension.Add(visit.UserAgent);
            }