Exemplo n.º 1
0
        private GoalProperty <string> CreateCustomEventGoalProperty(string propertyName, string value, byte?comparisonOperatorByte)
        {
            GoalProperty <string> eventCategoryProperty = null;
            var valueColumnName    = String.Format("Event{0}", propertyName);
            var operatorColumnName = String.Format("{0}ComparisonOperator", propertyName);

            if (value != null)
            {
                if (comparisonOperatorByte == null)
                {
                    throw new Exception(String.Format("{0} value cannot be null when {1} value is not null.", operatorColumnName, valueColumnName));
                }

                if (!GoalUtils.IsValidComparisonOperator((byte)comparisonOperatorByte))
                {
                    throw new Exception(String.Format("{0} value {1} is outside of range.", operatorColumnName, comparisonOperatorByte));
                }

                var comparisonOperator = (GoalComparisonOperator)comparisonOperatorByte;

                if (!GoalUtils.IsValidStringOperator(comparisonOperator))
                {
                    throw new Exception(String.Format("Comparison operator value {0} is not supported by {1} goal type.", comparisonOperator.ToString(), GoalType));
                }

                eventCategoryProperty = new GoalProperty <string>
                {
                    ComparisonOperator = comparisonOperator,
                    PropertyValue      = value.Trim()
                };
            }
            return(eventCategoryProperty);
        }
Exemplo n.º 2
0
        public override List <Conversion> FindConversionsIn(Visit visit, out bool isAchieved)
        {
            isAchieved = false; // Always false because Custom Event goal can be achieved multiple times per visit
            List <Conversion> conversions = null;

            // At least one property to check against: EventCategoryProperty, EventActionProperty, EventLabelProperty, EventValueProperty is not null
            if (EventCategoryProperty != null || EventActionProperty != null || EventLabelProperty != null || EventValueProperty != null)
            {
                // For each custom event (evnt.customEvent != null)
                // TODO: Drop the EventsIndex32 and EventsIndex properties. They are not used anywhere. And we are putting a List of int for it?
                int evntIndex = -1;

                foreach (var evnt in visit.Events)
                {
                    evntIndex++;

                    if (evnt.customEvent != null)
                    {
                        // For those properties to check against which is also not null, the values in the customEvent must match. If the property to check against is null, then we assume it is a match by default
                        bool isConversion = (EventCategoryProperty == null ? true : GoalUtils.CompareStringProperty(EventCategoryProperty, evnt.customEvent.EventCategory)) &&
                                            (EventActionProperty == null ? true : GoalUtils.CompareStringProperty(EventActionProperty, evnt.customEvent.EventAction)) &&
                                            (EventLabelProperty == null ? true : GoalUtils.CompareStringProperty(EventLabelProperty, evnt.customEvent.EventLabel)) &&
                                            (EventValueProperty == null ? true : (evnt.customEvent.EventValue.HasValue ? GoalUtils.CompareNumericProperty(EventValueProperty, evnt.customEvent.EventValue.Value) : false));

                        if (isConversion)
                        {
                            double?goalValue  = FetchGoalValue(GoalValue, evnt.GoalValue, GoalValueSourceId);
                            var    conversion = new Conversion
                            {
                                GoalId             = GoalId,
                                GoalLookbackWindow = LookbackWindow,
                                GoalValue          = goalValue,
                                EventsIndex32      = new List <int> {
                                    evntIndex
                                },
                                ConversionDateTime = evnt.EventDateTime,
                                GoalTrackingType   = GoalTrackingType,
                                AccountId          = AccountId,
                                GoalValueSourceId  = GoalValueSourceId
                            };

                            if (conversions == null)
                            {
                                conversions = new List <Conversion>();
                            }

                            conversions.Add(conversion);
                        }
                    }
                }
            }

            return(conversions);
        }
Exemplo n.º 3
0
        public override List <Conversion> FindConversionsIn(Visit visit, out bool isAchieved)
        {
            isAchieved = false;
            List <Conversion> conversions = null;

            if (visit != null && visit.Events != null && visit.Events.Count > 0 &&
                visit.Statistic != null &&
                (visit.Statistic.AchievedGoals == null ||
                 !visit.Statistic.AchievedGoals.Contains(GoalId)))  // Duration Per Visit goal can be achieved only once
            {
                // TODO: Drop the EventsIndex32 and EventsIndex properties. They are not used anywhere. And we are putting a List of int for it?
                int evntIndex          = -1;
                var visitStartDateTime = visit.Statistic.VisitStartDateTime;

                foreach (var evnt in visit.Events)
                {
                    evntIndex++;
                    var elapsedTicks = evnt.EventDateTime - visitStartDateTime;
                    var elapsedSpan  = new TimeSpan(elapsedTicks);

                    var isConversion = GoalUtils.CompareNumericProperty(NumberOfSecondsProperty, (int)elapsedSpan.TotalSeconds);
                    if (isConversion)
                    {
                        double?goalValue  = FetchGoalValue(GoalValue, evnt.GoalValue, GoalValueSourceId);
                        var    conversion = new Conversion
                        {
                            GoalId             = GoalId,
                            GoalLookbackWindow = LookbackWindow,
                            GoalValue          = goalValue,
                            EventsIndex32      = new List <int> {
                                evntIndex
                            },
                            ConversionDateTime = evnt.EventDateTime,
                            GoalTrackingType   = GoalTrackingType,
                            AccountId          = AccountId,
                            GoalValueSourceId  = GoalValueSourceId
                        };

                        if (conversions == null)
                        {
                            conversions = new List <Conversion>();
                        }

                        conversions.Add(conversion);
                        isAchieved = true;
                        break;
                    }
                }
            }

            return(conversions);
        }
Exemplo n.º 4
0
        public override List <Conversion> FindConversionsIn(Visit visit, out bool isAchieved)
        {
            isAchieved = false; // Always false because Destination URL goal can be achieved multiple times per visit
            List <Conversion> conversions = null;

            if (visit != null && visit.Events != null && visit.Events.Count > 0)
            {
                // TODO: Drop the EventsIndex32 and EventsIndex properties. They are not used anywhere. And we are putting a List of int for it?
                int evntIndex = -1;

                // For each page_load event (evnt.customEvent == null)
                foreach (var evnt in visit.Events)
                {
                    evntIndex++;

                    // Skip custom events
                    if (evnt.customEvent == null)
                    {
                        var isConversion = GoalUtils.CompareStringProperty(DestinationUrlProperty, evnt.ReferrerURL, compareUrls: true);
                        if (isConversion)
                        {
                            double?goalValue  = FetchGoalValue(GoalValue, evnt.GoalValue, GoalValueSourceId);
                            var    conversion = new Conversion
                            {
                                GoalId             = GoalId,
                                GoalLookbackWindow = LookbackWindow,
                                GoalValue          = goalValue,
                                EventsIndex32      = new List <int> {
                                    evntIndex
                                },
                                ConversionDateTime = evnt.EventDateTime,
                                GoalTrackingType   = GoalTrackingType,
                                AccountId          = AccountId,
                                GoalValueSourceId  = GoalValueSourceId
                            };

                            if (conversions == null)
                            {
                                conversions = new List <Conversion>();
                            }

                            conversions.Add(conversion);
                        }
                    }
                }
            }

            return(conversions);
        }
Exemplo n.º 5
0
        public TagToGoalRecordDestinationUrl(IReadOnlyDictionary <string, int> columnMetadata, IList <object> row)
            : base(columnMetadata, row)
        {
            GoalType = GoalType.DestinationUrl;

            if (_destinationUrlOrdinal == -1)
            {
                _destinationUrlOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "DestinationURL");
            }

            if (_comparisonOperatorOrdinal == -1)
            {
                _comparisonOperatorOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "DestinationURLOperator");
            }

            var destinationUrl         = (string)row[_destinationUrlOrdinal];
            var comparisonOperatorByte = (byte)row[_comparisonOperatorOrdinal];

            if (!GoalUtils.IsValidComparisonOperator(comparisonOperatorByte))
            {
                throw new Exception(String.Format("DestinationUrl comparison operator value {0} is outside of range.", comparisonOperatorByte));
            }

            var comparisonOperator = (GoalComparisonOperator)comparisonOperatorByte;

            if (!GoalUtils.IsValidStringOperator(comparisonOperator))
            {
                throw new Exception(String.Format("Comparison operator value {0} is not supported by {1} goal type.", comparisonOperator.ToString(), GoalType));
            }

            DestinationUrlProperty = new GoalProperty <string>
            {
                ComparisonOperator = comparisonOperator,
                PropertyValue      = destinationUrl.Trim()
            };
        }
        public TagToGoalRecordPagesPerVisit(IReadOnlyDictionary <string, int> columnMetadata, IList <object> row)
            : base(columnMetadata, row)
        {
            GoalType = GoalType.PagesPerVisit;

            if (_numberOfPagesOrdinal == -1)
            {
                _numberOfPagesOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "PageVisitGoal");
            }

            if (_comparisonOperatorOrdinal == -1)
            {
                _comparisonOperatorOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "PageVisitOperator");
            }

            var numberOfPages     = (short)row[_numberOfPagesOrdinal];
            var valueOperatorByte = (byte)row[_comparisonOperatorOrdinal];

            if (!GoalUtils.IsValidValueOperator(valueOperatorByte))
            {
                throw new Exception(String.Format("NumberOfPages comparison operator value {0} is outside of range.", valueOperatorByte));
            }

            var valueComparisonOperator = (ValueComparisonOperator)valueOperatorByte;

            if (!GoalUtils.IsValidNumericOperator(valueComparisonOperator))
            {
                throw new Exception(String.Format("Value operator value {0} is not supported by {1} goal type.", valueComparisonOperator.ToString(), GoalType));
            }

            NumberOfPagesProperty = new GoalProperty <short>
            {
                ValueComparisionOperator = valueComparisonOperator,
                PropertyValue            = numberOfPages
            };
        }
        public override List <Conversion> FindConversionsIn(Visit visit, out bool isAchieved)
        {
            isAchieved = false;
            List <Conversion> conversions = null;

            if (visit != null && visit.Events != null && visit.Events.Count > 0 &&
                visit.Statistic != null &&
                (visit.Statistic.AchievedGoals == null ||
                 !visit.Statistic.AchievedGoals.Contains(GoalId))) // Pages Per Visit goal can be achieved only once
            {
                var numberOfPages = visit.Statistic.NumberOfPages;
                var referralPage  = string.Empty;

                // For each page_load event (evnt.customEvent == null)
                // TODO: Drop the EventsIndex32 and EventsIndex properties. They are not used anywhere. And we are putting a List of int for it?
                int evntIndex = -1;
                foreach (var evnt in visit.Events)
                {
                    evntIndex++;

                    if (evnt.customEvent == null)
                    {
                        if (!String.Equals(evnt.ReferrerURL, referralPage, StringComparison.OrdinalIgnoreCase))
                        {
                            // Don't count if the same page was re-loaded
                            referralPage = evnt.ReferrerURL;
                            numberOfPages++;
                        }

                        // Convert numberOfPages to short to make it compatible with the goal schema.
                        var isConversion = GoalUtils.CompareNumericProperty(NumberOfPagesProperty, (short)numberOfPages);
                        if (isConversion)
                        {
                            double?goalValue = FetchGoalValue(GoalValue, evnt.GoalValue, GoalValueSourceId);

                            var conversion = new Conversion
                            {
                                GoalId             = GoalId,
                                GoalLookbackWindow = LookbackWindow,
                                GoalValue          = goalValue,
                                EventsIndex32      = new List <int> {
                                    evntIndex
                                },
                                ConversionDateTime = evnt.EventDateTime,
                                GoalTrackingType   = GoalTrackingType,
                                AccountId          = AccountId,
                                GoalValueSourceId  = GoalValueSourceId
                            };

                            if (conversions == null)
                            {
                                conversions = new List <Conversion>();
                            }

                            conversions.Add(conversion);
                            isAchieved = true;
                            break;
                        }
                    }
                }
            }

            return(conversions);
        }
Exemplo n.º 8
0
        public TagToGoalRecordCustomEvent(Dictionary <string, int> columnMetadata, object[] row)
            : base(columnMetadata, row)
        {
            GoalType = GoalType.CustomEvent;

            if (_eventCategoryOrdinal == -1)
            {
                _eventCategoryOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "EventCategory");
            }

            if (_categoryComparisonOperatorOrdinal == -1)
            {
                _categoryComparisonOperatorOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "EventCategoryOperator");
            }

            if (_eventNameOrdinal == -1)
            {
                _eventNameOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "EventName");
            }

            if (_nameComparisonOperatorOrdinal == -1)
            {
                _nameComparisonOperatorOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "EventNameOperator");
            }

            if (_eventLabelOrdinal == -1)
            {
                _eventLabelOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "EventLabel");
            }

            if (_labelComparisonOperatorOrdinal == -1)
            {
                _labelComparisonOperatorOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "EventLabelOperator");
            }

            if (_eventValueOrdinal == -1)
            {
                _eventValueOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "EventValue");
            }

            if (_valueComparisonOperatorOrdinal == -1)
            {
                _valueComparisonOperatorOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "EventValueOperator");
            }

            var eventCategory = (string)row[_eventCategoryOrdinal];
            var categoryComparisonOperatorByte = (byte?)row[_categoryComparisonOperatorOrdinal];

            EventCategoryProperty = CreateCustomEventGoalProperty("Category", eventCategory, categoryComparisonOperatorByte);

            var eventName = (string)row[_eventNameOrdinal];
            var nameComparisonOperatorByte = (byte?)row[_nameComparisonOperatorOrdinal];

            EventActionProperty = CreateCustomEventGoalProperty("Name", eventName, nameComparisonOperatorByte);

            var eventLabel = (string)row[_eventLabelOrdinal];
            var labelComparisonOperatorByte = (byte?)row[_labelComparisonOperatorOrdinal];

            EventLabelProperty = CreateCustomEventGoalProperty("Label", eventLabel, labelComparisonOperatorByte);

            var eventValue = (double?)row[_eventValueOrdinal];
            var valueComparisonOperatorByte = (byte?)row[_valueComparisonOperatorOrdinal];

            if (eventValue != null)
            {
                if (valueComparisonOperatorByte == null)
                {
                    throw new Exception("ValueComparisonOperator value cannot be null when EventValue value is not null.");
                }

                if (!GoalUtils.IsValidValueOperator((byte)valueComparisonOperatorByte))
                {
                    throw new Exception(String.Format("ValueComparisonOperator value {0} is outside of range.", valueComparisonOperatorByte));
                }

                var valueOperator = (ValueComparisonOperator)valueComparisonOperatorByte;

                if (!GoalUtils.IsValidNumericOperator(valueOperator))
                {
                    throw new Exception(String.Format("ValueOperator value {0} is not supported by {1} goal type.", valueOperator.ToString(), GoalType));
                }

                EventValueProperty = new GoalProperty <double>
                {
                    ValueComparisionOperator = valueOperator,
                    PropertyValue            = (double)eventValue
                };
            }
        }