Skip to content

Instantly share code, notes, and snippets.

@azcoov
Created May 16, 2013 23:51
Show Gist options
  • Save azcoov/5596023 to your computer and use it in GitHub Desktop.
Save azcoov/5596023 to your computer and use it in GitHub Desktop.
Example C# Preact Logging Helper
// TODO - update the doc to use your own internal User model class, instead of the example UserInfo class.
public static class Preact
{
public static void LogEvent(UserInfo user, string eventName, string note = null)
{
try
{
Preact.Api.Client.LogEvent(new Preact.ActionEventCreateRequest()
{
Event = new Preact.ActionEvent()
{
Name = eventName,
Note = note
},
Person = UserToPerson(user)
});
}
catch(Exception ex) {
#if DEBUG
throw ex;
#endif
}
}
public static Preact.Person UserToPerson(UserInfo user)
{
// TODO - update this to build a Person from your user data model
return new Preact.Person()
{
Email = user.Email,
Name = user.FullName,
Uid = user.Username,
Properties = GetAccountProperties(user)
};
}
public static Dictionary<string, object> GetAccountProperties(UserInfo user)
{
Dictionary<string, object> properties = new Dictionary<string, object>();
// TODO - update this to create a nice dictionary to describe your user's relevant attributes
properties["subscription_level"] = user.AccountLevel;
properties["subscription_level_name"] = user.AccountLevelName;
properties["custom_domain"] = user.CustomDomainName;
properties["is_paying"] = user.IsPaying ? "1" : "0";
properties["created_at"] = user.DateCreated;
return properties;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment