コード例 #1
0
ファイル: Airship.cs プロジェクト: bhazen/xamarin-component
        public void AddCustomEvent(Portable.Analytics.CustomEvent customEvent)
        {
            if (customEvent == null || string.IsNullOrEmpty(customEvent.EventName))
            {
                return;
            }

            string eventName       = customEvent.EventName;
            double eventValue      = customEvent.EventValue;
            string transactionId   = customEvent.TransactionId;
            string interactionType = customEvent.InteractionType;
            string interactionId   = customEvent.InteractionId;

            UACustomEvent uaEvent = UACustomEvent.Event(eventName, eventValue);

            if (!string.IsNullOrEmpty(transactionId))
            {
                uaEvent.TransactionID = transactionId;
            }

            if (!string.IsNullOrEmpty(interactionId))
            {
                uaEvent.InteractionID = interactionId;
            }

            if (!string.IsNullOrEmpty(interactionType))
            {
                uaEvent.InteractionType = interactionType;
            }

            if (customEvent.PropertyList != null)
            {
                foreach (dynamic property in customEvent.PropertyList)
                {
                    if (string.IsNullOrEmpty(property.name))
                    {
                        continue;
                    }

                    if (property.value is string)
                    {
                        uaEvent.SetStringProperty(property.stringValue, property.name);
                    }
                    else if (property.value is double)
                    {
                        uaEvent.SetNumberProperty(property.doubleValue, property.name);
                    }
                    else if (property.value is bool)
                    {
                        uaEvent.SetBoolProperty(property.boolValue, property.name);
                    }
                    else if (property.value is string[])
                    {
                        uaEvent.SetStringArrayProperty(property.stringArrayValue, property.name);
                    }
                }
            }

            UAirship.Shared.Analytics.AddEvent(uaEvent);
        }
コード例 #2
0
        public void AddCustomEvent(Portable.Analytics.CustomEvent customEvent)
        {
            if (customEvent == null || customEvent.EventName == null)
            {
                return;
            }

            string eventName       = customEvent.EventName;
            double eventValue      = customEvent.EventValue;
            string transactionId   = customEvent.TransactionId;
            string interactionType = customEvent.InteractionType;
            string interactionId   = customEvent.InteractionId;

            var builder = new UrbanAirship.Analytics.CustomEvent.Builder(eventName)
                          .SetEventValue(eventValue);

            if (!string.IsNullOrEmpty(transactionId))
            {
                builder.SetTransactionId(transactionId);
            }

            if (!string.IsNullOrEmpty(interactionType) && !string.IsNullOrEmpty(interactionId))
            {
                builder.SetInteraction(interactionType, interactionId);
            }

            if (customEvent.PropertyList != null)
            {
                foreach (dynamic property in customEvent.PropertyList)
                {
                    if (string.IsNullOrEmpty(property.name))
                    {
                        continue;
                    }

                    builder.AddProperty(property.name, property.value);
                }
            }

            UAirship.Shared().Analytics.AddEvent(builder.Create());
        }