Esempio n. 1
0
        private bool Engage(string distinctId, IDictionary <string, object> setProperties = null,
                            IDictionary <string, object> incrementProperties = null)
        {
            // Standardize token and time values for Mixpanel
            var dictionary =
                new Dictionary <string, object> {
                { "$token", token }, { "$distinct_id", distinctId }
            };

            if (setProperties != null)
            {
                dictionary.Add("$set", setProperties);
            }

            if (incrementProperties != null)
            {
                dictionary.Add("$add", incrementProperties);
            }

            var data = new JavaScriptSerializer().Serialize(dictionary);

            var values = "data=" + data.Base64Encode();

            var contents = _options.UseGet
        ? http.Get(Resources.Engage(_options.ProxyUrl), values)
        : http.Post(Resources.Engage(_options.ProxyUrl), values);

            return(contents == "1");
        }
Esempio n. 2
0
        public bool Track(string @event, IDictionary <string, object> properties)
        {
            var propertyBag = new Dictionary <string, object>(properties);

            // Standardize token and time values for Mixpanel
            propertyBag["token"] = token;
            if (_options.SetEventTime)
            {
                StandardiseMixpanelTime(propertyBag);
            }

            var data =
                new JavaScriptSerializer()
                .Serialize(new Dictionary <string, object>
            {
                { "event", @event },
                { "properties", propertyBag }
            });

            var values = "data=" + data.Base64Encode();

            if (_options.Test)
            {
                values += "&test=1";
            }

            var contents = _options.UseGet
              ? http.Get(Resources.Track(_options.ProxyUrl), values)
              : http.Post(Resources.Track(_options.ProxyUrl), values);

            return(contents == "1");
        }
Esempio n. 3
0
        public bool Track(string @event, IDictionary <string, object> properties)
        {
            var propertyBag = properties.FormatProperties();

            // Standardize token and time values for Mixpanel
            propertyBag["token"] = token;

            if (_options.SetEventTime && !properties.Keys.Any(x => x.ToLower() == "time"))
            {
                propertyBag["time"] = DateTime.UtcNow.FormatDate();
            }

            var data = new JavaScriptSerializer().Serialize(new Dictionary <string, object>
            {
                { "event", @event },
                { "properties", propertyBag }
            });

            var values = "data=" + data.Base64Encode();

            if (_options.Test)
            {
                values += "&test=1";
            }

            var contents = _options.UseGet
              ? http.Get(Resources.Track(_options.ProxyUrl), values)
              : http.Post(Resources.Track(_options.ProxyUrl), values);

            return(contents == "1");
        }
Esempio n. 4
0
        public bool Flush()
        {
            var data = new JavaScriptSerializer().Serialize(batch);

            var values = "data=" + data.Base64Encode();

            // For send a batch, we need to use Post method
            var contents = http.Post(Resources.Engage(_options.ProxyUrl), values);

            batch.Clear();

            return(contents == "1");
        }
Esempio n. 5
0
        public bool Track(string @event, IDictionary <string, object> properties)
        {
            var data = new JavaScriptSerializer().Serialize(PrepareData(@event, properties));

            var values = "data=" + data.Base64Encode();

            if (_options.Test)
            {
                values += "&test=1";
            }

            var contents = _options.UseGet
              ? http.Get(Resources.Track(_options.ProxyUrl), values)
              : http.Post(Resources.Track(_options.ProxyUrl), values);

            return(contents == "1");
        }
Esempio n. 6
0
        private bool Engage(string distinctId,
                            IDictionary <string, object> setProperties         = null,
                            IDictionary <string, object> setOnceProperties     = null,
                            IDictionary <string, object> incrementProperties   = null,
                            IDictionary <string, object> appendProperties      = null,
                            IDictionary <string, object> transactionProperties = null,
                            bool delete = false, string aliasId = null,
                            string ip   = null)
        {
            // Standardize token and time values for Mixpanel
            var data = new JavaScriptSerializer().Serialize(
                PrepareData(distinctId, setProperties, setOnceProperties,
                            incrementProperties, appendProperties, transactionProperties,
                            delete, aliasId, ip));

            var values = "data=" + data.Base64Encode();

            var contents = _options.UseGet
                ? http.Get(Resources.Engage(_options.ProxyUrl), values)
                : http.Post(Resources.Engage(_options.ProxyUrl), values);

            return(contents == "1");
        }
Esempio n. 7
0
        public bool Track(string @event, IDictionary <string, object> properties)
        {
            var propertyBag = new Dictionary <string, object>(properties);

            // Standardize token and time values for Mixpanel
            propertyBag["token"] = token;
            if (_options.SetEventTime)
            {
                propertyBag["time"] =
                    propertyBag.Where(x => x.Key.ToLower() == "time")
                    .Select(x => x.Value)
                    .FirstOrDefault() ?? DateTime.UtcNow;

                propertyBag.Remove("Time");
            }

            var data =
                new JavaScriptSerializer()
                .Serialize(new Dictionary <string, object>
            {
                { "event", @event },
                { "properties", propertyBag }
            });

            var values = "data=" + data.Base64Encode();

            if (_options.Test)
            {
                values += "&test=1";
            }

            var contents = _options.UseGet
              ? http.Get(Resources.Track(_options.ProxyUrl), values)
              : http.Post(Resources.Track(_options.ProxyUrl), values);

            return(contents == "1");
        }