Skip to content

Instantly share code, notes, and snippets.

@gooley
Created September 29, 2014 19:04
Show Gist options
  • Save gooley/0fe1278edf90b2d9ce34 to your computer and use it in GitHub Desktop.
Save gooley/0fe1278edf90b2d9ce34 to your computer and use it in GitHub Desktop.
Segment.io Server Side example - .NET
private static void LogAction(string username, string action, string item = "None", Segmentio.Model.Properties properties = null)
{
// Segment.IO Properties
if (properties == null)
{
properties = new Segmentio.Model.Properties();
}
properties.Add("ProductName", "Example WebApp");
properties.Add("URL", "http://www.example.com");
// Segment.IO Context
var context = new Segmentio.Model.Context();
// This identity info is required for Preact integration, even though
// we've already identified the user at login
// Also, the trait names are Preact specific - Don't change case, etc
var traits = new Segmentio.Model.Traits();
traits.Add("username", "Mr. Example");
traits.Add("email", "[email protected]");
traits.Add("account_id", 42);
traits.Add("account_name", "Example Inc.");
context.Add("Traits", traits);
// Track
Segmentio.Analytics.Client.Track(
"theuserid",
string.Format(
"{0}{1}",
action,
(item == "None") ? "" : (" " + item)
),
properties,
null,
context
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment