public void SetUp()
        {
            MixpanelConfig.Global.Reset();

            _urls   = new List <string>();
            _client = new MixpanelClient(Token, GetConfig());

            _mixpanelMethods = new List <Action>
            {
                () => _client.Track(Event, DistinctId, DictionaryWithStringProperty),
                () => _client.Alias(DistinctId, Alias),
                () => _client.PeopleSet(DistinctId, DictionaryWithStringProperty),
                () => _client.PeopleSetOnce(DistinctId, DictionaryWithStringProperty),
                () => _client.PeopleAdd(DistinctId, DictionaryWithStringProperty),
                () => _client.PeopleAppend(DistinctId, DictionaryWithStringProperty),
                () => _client.PeopleUnion(DistinctId, DictionaryWithStringProperty),
                () => _client.PeopleUnset(DistinctId, StringPropertyArray),
                () => _client.PeopleDelete(DistinctId),
                () => _client.PeopleTrackCharge(DistinctId, DecimalPropertyValue),
                () => _client.Send(new MixpanelMessage
                {
                    Kind = MessageKind.PeopleSet,
                    Data = DictionaryWithStringProperty
                }),
            };
        }
        public void NETFX_TrackEventTest2()
        {
            MixpanelClient client = MixpanelClient.GetCurrentClient();
            TrackingEvent  evt    = GetEvent2();

            client.Track(evt);
        }
        public async Task UNIVERSAL_ProfileUpdateTest6()
        {
            MixpanelClient client = await MixpanelClient.GetCurrentClient();

            ProfileUpdate pu = GetProfileUpdate6();
            await client.Track <ProfileUpdate>(pu);
        }
Exemple #4
0
        // Main entry point
        public async Task <SkillResponse> GetResponse(SkillRequest request, ILambdaContext context)
        {
            context.Logger.LogLine(JsonConvert.SerializeObject(request));
            MixpanelConfig.Global.SerializeJsonFn = JsonConvert.SerializeObject;
            _mixpanel = new MixpanelClient(MixPanelToken);

            //await _mixpanel.TrackAsync("GetResponse.Begin", new {});

            try
            {
                _context = context;
                _state   = RestoreState(request);
                _client  = new Client(StackApiKey, request?.Session?.User?.AccessToken);                // StackExchange API client
                var response = await RouteRequest(request);

                context.Logger.LogLine(JsonConvert.SerializeObject(response));
                //await _mixpanel.TrackAsync("GetResponse.End", new {});
                return(response);
            }
            catch (Exception ex)
            {
                await _mixpanel.TrackAsync("GetResponse.Exception", new {});

                context.Logger.LogLine("Unhandled exception:");
                context.Logger.LogLine(ex.ToString());
                context.Logger.LogLine(JsonConvert.SerializeObject(ex));
                return(CreateResponse($"Sorry, there was a technical problem. Please try again later."));
            }
        }
        public async Task WP8SL_ProfileUpdateTest7()
        {
            MixpanelClient client = await MixpanelClient.GetCurrentClient();

            ProfileUpdate pu = GetProfileUpdate7();
            await client.Track <ProfileUpdate>(pu);
        }
        public void NETFX_ProfileUpdateTest7()
        {
            MixpanelClient client = MixpanelClient.GetCurrentClient();
            ProfileUpdate  pu     = GetProfileUpdate7();

            client.Track(pu);
        }
        public async Task WP8SL_TrySendLocalElementsTest()
        {
            MixpanelClient client = await MixpanelClient.GetCurrentClient();

            TrackingEvent e1 = GetEvent1();
            await client.SaveElement <TrackingEvent>(e1);

            TrackingEvent e2 = GetEvent2();
            await client.SaveElement <TrackingEvent>(e2);

            ProfileUpdate p1 = GetProfileUpdate1();
            await client.SaveElement <ProfileUpdate>(p1);

            ProfileUpdate p2 = GetProfileUpdate2();
            await client.SaveElement <ProfileUpdate>(p2);

            ProfileUpdate p3 = GetProfileUpdate3();
            await client.SaveElement <ProfileUpdate>(p3);

            ProfileUpdate p4 = GetProfileUpdate4();
            await client.SaveElement <ProfileUpdate>(p4);

            ProfileUpdate p5 = GetProfileUpdate5();
            await client.SaveElement <ProfileUpdate>(p5);

            ProfileUpdate p6 = GetProfileUpdate6();
            await client.SaveElement <ProfileUpdate>(p6);

            ProfileUpdate p7 = GetProfileUpdate7();
            await client.SaveElement <ProfileUpdate>(p7);

            await client.TrySendLocalElements();
        }
        private ProfileUpdate GetProfileUpdate2()
        {
            ProfileUpdate pu = new ProfileUpdate(Token, "13793", ProfileUpdateOperation.SetOnce);

            pu.OperationValues["First login date"] = MixpanelClient.ConvertToMixpanelDate(DateTime.Now);
            return(pu);
        }
 public void SetUp()
 {
     _httpPostEntries = new List<HttpPostEntry>();
     _client = new MixpanelClient(Token, GetConfig());
     _client.UtcNow = () => DateTime.UtcNow;
     _client.SetSuperProperties(new object());
 }
Exemple #10
0
        public async Task WP8SL_TrackEventTest2()
        {
            MixpanelClient client = await MixpanelClient.GetCurrentClient();

            TrackingEvent evt = GetEvent2();
            await client.Track <TrackingEvent>(evt);
        }
 public async Task TestMixpanel()
 {
     MixpanelConfig.Global.SerializeJsonFn = JsonConvert.SerializeObject;
     var mc = new MixpanelClient("<token>");
     await mc.TrackAsync("TestEvent", new {
         Time = DateTime.UtcNow
     });
 }
Exemple #12
0
        public void NETFX_RevenueTrackingTest()
        {
            MixpanelClient client = MixpanelClient.GetCurrentClient();
            ProfileUpdate  pu     = GetRevenueTracking();

            client.IsVerboseEnabled     = true;
            client.IsGeolocationEnabled = false;
            client.Track(pu);
        }
Exemple #13
0
        public void TrackSimpleEvent()
        {
            var token          = "";
            var mixpanelClient = new MixpanelClient(token);
            var eventData      = new Dictionary <string, Object>();

            eventData["Time"] = DateTime.UtcNow.AddMinutes(-7);
            var success = mixpanelClient.Track("test event", "1234", eventData);
        }
        public MainWindow()
        {
            InitializeComponent();
            Loaded   += MainWindow_Loaded;
            Unloaded += MainWindow_Unloaded;

            // get mixpanel project token
            client = new MixpanelClient("");
        }
        public void SetUp()
        {
            _mc = new MixpanelClient(Token,
                                     new MixpanelConfig
            {
#if !JSON
                SerializeJsonFn = obj => JsonConvert.SerializeObject(obj)
#endif
            });
        }
Exemple #16
0
        public void ImportSimpleEvent()
        {
            var token          = "";
            var api_key        = "";
            var mixpanelClient = new MixpanelClient(token, api_key);
            var eventData      = new Dictionary <string, Object>();

            eventData["Time"] = DateTime.UtcNow.AddDays(-7);
            var success = mixpanelClient.Import("test import event", "1234", eventData);
        }
Exemple #17
0
        public async Task WP8SL_RevenueTrackingTest()
        {
            MixpanelClient client = await MixpanelClient.GetCurrentClient();

            client.IsGeolocationEnabled = false;
            ProfileUpdate pu = GetRevenueTracking();

            client.IsVerboseEnabled = true;

            await client.Track <ProfileUpdate>(pu);
        }
Exemple #18
0
        /// <summary>
        /// Gets the user.
        /// </summary>
        /// <returns></returns>
        internal async Task <MixpanelClient> GetMixpanelClient()
        {
            if (_client != null)
            {
                return(_client);
            }

            _client = await MixpanelClient.GetCurrentClient();

            return(_client);
        }
        public async Task TrackAsync_CanSendSingleEvent()
        {
            var client = new MixpanelClient(Token, new HttpClient());

            var mixpanelEvent = client.CreateEvent();

            mixpanelEvent.Name = nameof(TrackAsync_CanSendSingleEvent);

            var outcome = await client.TrackAsync(mixpanelEvent).ConfigureAwait(false);

            Assert.True(outcome.Successful);
        }
Exemple #20
0
        public void SetUp()
        {
            _mc = new MixpanelClient(Token,
                                     new MixpanelConfig
            {
#if (PORTABLE || PORTABLE40)
                HttpPostFn      = (endpoint, data) => true,
                AsyncHttpPostFn = (endpoint, data) => Task.Run(() => true),
                SerializeJsonFn = obj => JsonConvert.SerializeObject(obj)
#endif
            });
        }
Exemple #21
0
        private TrackingEvent GetEvent2()
        {
            // other sample using special & custom properties

            TrackingEvent evt = new TrackingEvent("Level Complete");

            evt.Properties                     = new TrackingEventProperties(Token);
            evt.Properties.DistinctId          = "13793";
            evt.Properties.Time                = MixpanelClient.ToEpochTime(DateTime.Now);
            evt.Properties.IP                  = "203.0.113.9";
            evt.Properties.Tag                 = "Tim Trefren";
            evt.Properties.All["Level Number"] = 9;
            return(evt);
        }
Exemple #22
0
        public void NETFX_TrySendLocalElementsTest()
        {
            MixpanelClient client = MixpanelClient.GetCurrentClient();

            TrackingEvent e1 = GetEvent1();

            client.SaveElement(e1);

            TrackingEvent e2 = GetEvent2();

            client.SaveElement(e2);

            ProfileUpdate p1 = GetProfileUpdate1();

            client.SaveElement(p1);

            ProfileUpdate p2 = GetProfileUpdate2();

            client.SaveElement(p2);

            ProfileUpdate p3 = GetProfileUpdate3();

            client.SaveElement(p3);

            ProfileUpdate p4 = GetProfileUpdate4();

            client.SaveElement(p4);

            ProfileUpdate p5 = GetProfileUpdate5();

            client.SaveElement(p5);

            ProfileUpdate p6 = GetProfileUpdate6();

            client.SaveElement(p6);

            ProfileUpdate p7 = GetProfileUpdate7();

            client.SaveElement(p7);

            client.TrySendLocalElements();
        }
        public void SetUp()
        {
            _httpPostEntries = new List<HttpPostEntry>();
            _client = new MixpanelClient(Token,
                new MixpanelConfig
                {
                    HttpPostFn = (endpoint, data) =>
                    {
                        _httpPostEntries.Add(new HttpPostEntry(endpoint, data));
                        return true;
                    },
#if !(NET40 || NET35)
                    AsyncHttpPostFn = (endpoint, data) =>
                    {
                        _httpPostEntries.Add(new HttpPostEntry(endpoint, data));
                        return Task.Run(() => true);
                    }
#endif
                });
            _client.UtcNow = () => DateTime.UtcNow;
            _client.SetSuperProperties(new object());
        }
        public async Task TrackAsync_SendsSuccessfully_WhenEventIsNotNull()
        {
            var httpMessageHandlerMock = new Mock <HttpMessageHandler>();

            httpMessageHandlerMock.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent("{\"status\": 1, \"error\": null}")
            })
            .Verifiable();

            var httpClient = new HttpClient(httpMessageHandlerMock.Object);

            IMixpanelClient client = new MixpanelClient(EmptyToken, httpClient);

            var @event = client.CreateEvent();

            var outcome = await client.TrackAsync(@event).ConfigureAwait(false);

            Assert.True(outcome.Successful);

            httpMessageHandlerMock.Protected().Verify("SendAsync", Times.Once(), ItExpr.Is <HttpRequestMessage>(request => request.Method == HttpMethod.Get), ItExpr.IsAny <CancellationToken>());
        }
        public void SuperProperties_FromClientConstructor_AddedToMessage()
        {
            var client = new MixpanelClient(Token, null, new Dictionary<string, object>
            {
                {MixpanelProperty.DistinctId, DistinctId},
                {DoublePropertyName, DoublePropertyValue},
                {StringPropertyName, StringPropertyValue}
            });

            var msg = client.PeopleSetTest(new Dictionary<string, object>
            {
                {DecimalPropertyName, DecimalPropertyValue}
            });

            Assert.That(msg.Data.Count, Is.EqualTo(3));
            Assert.That(msg.Data[MixpanelProperty.PeopleToken], Is.EqualTo(Token));
            Assert.That(msg.Data[MixpanelProperty.PeopleDistinctId], Is.EqualTo(DistinctId));
            Assert.That(msg.Data[MixpanelProperty.PeopleSet], Is.TypeOf<Dictionary<string, object>>());
            var set = (Dictionary<string, object>)msg.Data[MixpanelProperty.PeopleSet];
            Assert.That(set.Count, Is.EqualTo(3));
            Assert.That(set[DoublePropertyName], Is.EqualTo(DoublePropertyValue));
            Assert.That(set[StringPropertyName], Is.EqualTo(StringPropertyValue));
            Assert.That(set[DecimalPropertyName], Is.EqualTo(DecimalPropertyValue));
        }
        public void Track_AsyncHttpPostFnNotSet_ThrowsException()
        {
            var config = GetConfig();
            config.AsyncHttpPostFn = null;
            var mc = new MixpanelClient(Token, config);

            var aggregate = Assert.Throws<AggregateException>(
                () => mc.TrackAsync(Event, DistinctId, GetTrackDictionary()).Wait());
            Assert.That(aggregate.InnerExceptions.Single(), Is.InstanceOf<MixpanelConfigurationException>());
        }
        public void Track_HttpPostFnNotSet_ThrowsException()
        {
            var config = GetConfig();
            config.HttpPostFn = null;
            var mc = new MixpanelClient(Token, config);

            Assert.That(
                () => { mc.Track(Event, DistinctId, GetTrackDictionary()); },
                Throws.TypeOf<MixpanelConfigurationException>());
        }
        public void SuperProperties_FromClientConstructor_AddedToMessage()
        {
            var client = new MixpanelClient(Token, GetConfig(), GetSuperPropertiesDictionary(includeDistinctId: true));

            MixpanelMessage msg = client.GetTrackMessage(Event, GetTrackDictionary());
            CheckTrackMessage(msg, CheckOptions.SuperPropsSet | CheckOptions.SuperPropsDistinctIdSet);
        }
 public void SetUp()
 {
     _mc = new MixpanelClient(Token,
            new MixpanelConfig
            {
     #if (PORTABLE || PORTABLE40)
                HttpPostFn = (endpoint, data) => true,
                AsyncHttpPostFn = (endpoint, data) => Task.Run(() => true),
                SerializeJsonFn = obj => JsonConvert.SerializeObject(obj)
     #endif
            });
 }
        public void TrackAsync_ThrowsArgumentNullException_WhenEventIsNull()
        {
            IMixpanelClient client = new MixpanelClient(EmptyToken, EmptyHttpClientMock.Object);

            Assert.ThrowsAsync <ArgumentNullException>(async() => await client.TrackAsync(null).ConfigureAwait(false));
        }
 public void SetUp()
 {
     _mc = new MixpanelClient(Token);
 }
 public void Constructor_Constructs()
 {
     IMixpanelClient client = new MixpanelClient(EmptyToken, EmptyHttpClientMock.Object);
 }