Created
May 16, 2013 23:51
-
-
Save azcoov/5596023 to your computer and use it in GitHub Desktop.
Example C# Preact Logging Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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