Ejemplo n.º 1
0
        /// <summary>
        /// Logs an app event.
        /// </summary>
        /// <param name="eventName">event name.</param>
        /// <param name="data">event data.</param>
        public static void LogEvent(string eventName, IDictionary <string, object> data)
        {
#if AN_FIREBASE_ANALYTICS && (UNITY_IOS || UNITY_ANDROID)
            Debug.Log("LogEvent with data sent");
            List <Fire.Parameter> parameters = new List <Fire.Parameter>();
            foreach (var pair in data)
            {
                string         key   = pair.Key;
                object         value = pair.Value;
                Fire.Parameter p     = null;

                if (value is double || value is float)
                {
                    p = new Fire.Parameter(key, System.Convert.ToDouble(value));
                }

                if (value is short || value is int || value is long)
                {
                    p = new Fire.Parameter(key, System.Convert.ToInt64(value));
                }

                if (p == null)
                {
                    p = new Fire.Parameter(key, System.Convert.ToString(value));
                }

                parameters.Add(p);
            }


            Fire.FirebaseAnalytics.LogEvent(eventName, parameters.ToArray());
#endif
        }
Ejemplo n.º 2
0
    public void EventLog(string eventName, AnalyticsEventParam analyticsEventParam)
    {
        // Log an event with an int parameter.
        if (_app != null)
        {
            if (eventName.Length > 0 && analyticsEventParam.ParamDic.Count > 0)
            {
                Parameter[] LevelUpParameters = new Parameter[analyticsEventParam.ParamDic.Count];
                int         index             = 0;
                foreach (string paramName in analyticsEventParam.ParamDic.Keys)
                {
                    object paramValueObject = analyticsEventParam.ParamDic[paramName];
                    if (paramValueObject is int)
                    {
                        LevelUpParameters[index] = new Firebase.Analytics.Parameter(paramName, (int)paramValueObject);
                        index++;
                    }
                    else if (paramValueObject is float)
                    {
                        LevelUpParameters[index] = new Firebase.Analytics.Parameter(paramName, (float)paramValueObject);
                        index++;
                    }
                    else if (paramValueObject is string)
                    {
                        LevelUpParameters[index] = new Firebase.Analytics.Parameter(paramName, (string)paramValueObject);
                        index++;
                    }
                }

                Firebase.Analytics.FirebaseAnalytics.LogEvent(eventName, LevelUpParameters);
            }
        }
    }