A Segment.io .NET client
Inheritance: IDisposable
Example #1
0
		private void RunTests(Client client, int trials)
		{
			for (int i = 0; i < trials; i += 1)
			{
				Actions.Random(client);
			}
		}
Example #2
0
        /// <summary>
        /// Initialized the default Segment.io client with your API writeKey.
        /// </summary>
        /// <param name="writeKey"></param>
		public static void Initialize(string writeKey, Config config)
        {
            lock (padlock)
            {
                if (Client == null)
                {
                    Client = new Client(writeKey, config);
                }
            }
        }
Example #3
0
 /// <summary>
 /// Disposes of the current client and allows the creation of a new one
 /// </summary>
 public static void Dispose()
 {
     lock (padlock)
     {
         if (Client != null)
         {
             Client.Dispose();
             Client = null;
         }
     }
 }
Example #4
0
 /// <summary>
 /// Initialized the default Segment.io client with your API writeKey.
 /// </summary>
 /// <param name="writeKey"></param>
 public static void Initialize(string writeKey)
 {
     // avoiding double locking as recommended:
     // http://www.yoda.arachsys.com/csharp/singleton.html
     lock (padlock)
     {
         if (Client == null)
         {
             Client = new Client(writeKey);
         }
     }
 }
		public static void Main (string[] args)
		{
			Console.WriteLine ("Started!");
			Debugger.Break ();
			using (Client analytics = new Client("r7bxis28wy")) 
			{
				analytics.Identify ("user123", new Traits () {
					{ "hey", 123 }
				});

				analytics.Track ("user123", "Ran away");

				analytics.Track ("user123", "Engaged a bear", new Properties () {
					{ "bearWeight", 865 }
				});

				analytics.Track ("user123", "Engaged a bear", new Options ()
					.SetContext (new Context () {
						{ "app", new Dict() {
							{ "name", "test" } 
						}}
				}));

				analytics.Track ("user123", "Is Not Alive", new Properties () {
					{ "why", "bear attack" }
				}, new Options()
					.SetIntegration("Salesforce", true)
				);

				analytics.Track ("user123", "Is Not Alive", new Properties () {
					{ "why", "bear attack" }
				}, new Options()
					.SetIntegration("Salesforce", true)
					.SetAnonymousId("cookie-id")
					.SetContext(new Context()
						.Add("ip", "192.144.23.2"))
				);

				analytics.Flush ();
			}
		}
Example #6
0
		public static void Random(Client client)
		{
			switch (random.Next(0, 6))
			{
			case 0:
				Identify(client);
				return;
			case 1:
				Track(client);
				return;
			case 2:
				Alias(client);
				return;
			case 3:
				Group(client);
				return;
			case 4:
				Page(client);
				return;
			case 5:
				Screen(client);
				return;
			}
		}
Example #7
0
		public void Init()
		{
			client = new Client("foo");
		}
Example #8
0
		public static void Screen(Client client)
		{
			client.Screen("user", "name", "category", Properties(), Options());
		}
Example #9
0
		public static void Page(Client client)
		{
			client.Page("user", "name", "category", Properties(), Options());
		}
Example #10
0
		public static void Alias(Client client)
		{
			client.Alias("previousId", "to");
		}
Example #11
0
		public static void Track(Client client)
		{
			client.Track("user", "Ran .NET test", Properties(), Options());
		}
Example #12
0
		public static void Group(Client client)
		{
			client.Group("user", "group", Traits(), Options());
			Analytics.Client.Flush();
		}
Example #13
0
		public static void Identify(Client client)
		{
			client.Identify("user", Traits(), Options());
			Analytics.Client.Flush();
		}