コード例 #1
0
        static void Main(string[] args)
        {
            var authsome = new AuthsomeService();
            var testApp  = new AmplitudeService(authsome);

            Task.Run(async() =>
            {
                var user_properties = new Dictionary <string, string>();
                user_properties.Add("LoginButton", "Clicked");
                user_properties.Add("CreateUserButton", "Clicked");

                await testApp.PostEvent(apiKey, new Event()
                {
                    user_id         = "0",
                    event_type      = "LoginView",
                    user_properties = user_properties,
                    time            = DateTime.Now.Ticks
                });

                Console.WriteLine("Post Sent!");
                Console.ReadLine();
            });

            Console.ReadLine();
            Console.WriteLine("Hello World!");
        }
コード例 #2
0
        private async Task <SendResult> DoApiCall(string endPoint, string paramName, string paramData)
        {
            SendResult result = SendResult.Success;

            if (!OfflineMode)
            {
                string boundary = "----" + DateTime.Now.Ticks;

                MultipartFormDataContent content = new MultipartFormDataContent(boundary);
                var keyContent = new StringContent(apiKey, UTF8Encoding.UTF8, "text/plain");
                content.Add(keyContent, "api_key");

                var data = new StringContent(paramData, UTF8Encoding.UTF8, "application/json");
                content.Add(data, paramName);

                try
                {
                    var postResult = await httpClient.PostAsync($"https://api.amplitude.com/{endPoint}", content);

                    if (postResult.StatusCode >= HttpStatusCode.InternalServerError)
                    {
                        result = SendResult.ServerError;
                    }
                    if (postResult.StatusCode >= HttpStatusCode.BadRequest)
                    {
                        switch (postResult.StatusCode)
                        {
                        case HttpStatusCode.ProxyAuthenticationRequired:
                            result = SendResult.ProxyNeeded;
                            break;

                        case (HttpStatusCode)429:
                            result = SendResult.Throttled;
                            break;

                        default:
                            result = SendResult.ServerError;
                            break;
                        }
                    }
                }
                catch (HttpRequestException)
                {
                    // Ignore connection errors
                    result = SendResult.ServerError;
                }
                catch (Exception e)
                {
                    result = SendResult.ServerError;
                    AmplitudeService.s_logger(LogLevel.Warning, $"Failed to get device make/model: {e}");
                }
            }

            return(result);
        }
コード例 #3
0
        protected override void OnStartup(StartupEventArgs e)
        {
            if (File.Exists("event.store"))
            {
                using (var s = File.OpenRead("event.store"))
                {
                    analytics = AmplitudeService.Initialize(AmplitudeApiKey, persistenceStream: s);
                }
            }
            else
            {
                analytics = AmplitudeService.Initialize(AmplitudeApiKey);
            }

            base.OnStartup(e);
        }