Example #1
0
        /// <summary>
        /// Tracks the specified element (event or profile update).
        /// More info: https://mixpanel.com/help/reference/http#tracking-via-http
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">element</exception>
        public void Track(MixpanelEntity element)
        {
            if (element == null)
                throw new ArgumentNullException("element");

            WriteToFile(element);
            SendFile(element.EndpointName, element.FileName);
        }
Example #2
0
        private static void WriteToFile(MixpanelEntity element)
        {
            Dictionary<string, object> values = new Dictionary<string, object>();
            element.CopyTo(values);
            string json = JsonConvert.SerializeObject(values);
            string b64 = Utilities.ToBase64(json);

            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForAssembly())
            {
                if (!store.DirectoryExists(element.EndpointName))
                {
                    store.CreateDirectory(element.EndpointName);
                }

                string path = element.EndpointName + "\\" + element.FileName;
                using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(path, FileMode.Create, store))
                {
                    using (StreamWriter writer = new StreamWriter(stream))
                    {
                        writer.Write(b64);
                    }
                }
            }
        }
Example #3
0
 public void SaveElement(MixpanelEntity element);
Example #4
0
        /// <summary>
        /// Saves element locally. Event will be sent on next call of "TrySendLocalElements".
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns></returns>
        public void SaveElement(MixpanelEntity element)
        {
            if (element == null)
                throw new ArgumentNullException("element");

            WriteToFile(element);
        }
Example #5
0
 public void Track(MixpanelEntity element);
Example #6
0
        private void WriteToFile(MixpanelEntity element)
        {
            string b64 = ToMixpanelData(element);
            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForAssembly())
            {
                if (!store.DirectoryExists(element.EndpointName))
                {
                    store.CreateDirectory(element.EndpointName);
                }

                string path = element.EndpointName + "\\" + element.FileName;
                using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(path, FileMode.Create, store))
                {
                    using (StreamWriter writer = new StreamWriter(stream))
                    {
                        writer.Write(b64);
                    }
                }
            }
        }
Example #7
0
 private string ToMixpanelData(MixpanelEntity element)
 {
     Dictionary<string, object> values = new Dictionary<string, object>();
     element.CopyTo(values);
     string json = JsonConvert.SerializeObject(values);
     return Utilities.ToBase64(json);
 }
Example #8
0
        private bool SendFile(MixpanelEntity element)
        {
            if (element == null)
                throw new ArgumentNullException("element");

            string data = ToMixpanelData(element);
            using (WebClient client = new WebClient()) {
                client.Headers[HttpRequestHeader.UserAgent] = UserAgent;
                string urlFormat = GetUrlFormat();
                string url = string.Format(CultureInfo.InvariantCulture, urlFormat, element.EndpointName, data);
                try {
                    client.DownloadString(url);
                }
                catch (Exception ex) {
                    Debug.WriteLine("MixpanelClient.Track failed: could not send event (endpoint=" + element.EndpointName + ", data=" + data + "). Error: " + ex);
                    return false;
                }
            }

            return true;
        }
Example #9
0
        /// <summary>
        /// Tracks the specified element (event or profile update).
        /// More info: https://mixpanel.com/help/reference/http#tracking-via-http
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">element</exception>
        public void Track(MixpanelEntity element)
        {
            if (element == null)
                throw new ArgumentNullException("element");

            if (_isOfflineEnabled) {
                WriteToFile(element);
                SendFile(element.EndpointName, element.FileName);
            } else {
                SendFile(element);
            }
        }