Avo Functions in C#

5 minute read

Platforms

Avo can code generate Avo Functions in C# targeted at the following platforms

  • .NET Server
  • Unity

Step 1. Include the Avo file

Pull the generated code with the Avo CLI

To get the Avo generated C# file you must be a member of an Avo workspace with a C# source. Ask for an invite from a colleague or create a new workspace

Terminal
Copy
$
$
$
npm install -g avo
avo login
avo pull --branch my-branch-name

Learn more about the CLI here.

You can also download the file manually from your Avo workspace.

Step 2. Initialize Avo

Initialize Avo by creating an object using constructor from the generated Avo file

C#
Copy
1
2
3
using Avo;
Avo.Avo avo = new Avo.Avo(Avo.AvoEnv.Dev/*, other parameters depending on your tracking plan setup*/);

The actual parameters depend on your tracking plan setup, see the parameters explanation in the reference below.

Step 3. Call Avo functions to track your product usage

Every event in your tracking plan, marked with the "Implement with Avo" checkbox, gets a function in the generated code, named according to the event name, in PascalCase.

For example, if you have a "Signup Start" event defined like this in Avo:

Event 'Signup Start' defined in Avo with referral string property and implement with Avo check

You'll be able to call it like this from the generated code

C#
Copy
1
avo.SignupStart(referral = "direct")

Notice, that you are not passing the System property with the call. System properties are defined on the init step and then automatically included with all events. You can update the system properties with setSystemProperties function.

Step 4. Verify the implementation

Use the Implementation status in your Avo workspace to verify that your implementation is correct.

Reference

Constructor

C#
Copy
1
2
3
4
5
6
public Avo(AvoEnv env,
// Other parameters may not be present, depending on your tracking plan
int systemProperty0, bool systemProperty1,
IDestination customDestination,
bool strict = true
)

Creates the Avo object that will be used to track. This method will initialize the SDKs for all destinations that are managed by Avo, and call the Make(env) callback in all custom destinations.

Arguments

AvoEnv env: Can be set to dev, prod and staging.

systemProperties: a number of parameters equal to the number of system properties defined in your Avo workspace. The parameters are named the same as system properties, in camelCase, and require corresponding types: string, int, long, float, bool and list.

IDestination customDestination: object, required if target source has a custom destination set up in Avo. Otherwise not present.

Custom destination interface format:

C#
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
interface ICustomDestination {
void Make(AvoEnv env);
Task LogEvent(string eventName, IDictionary<string, object> eventProperties);
Task SetUserProperties(string userId, IDictionary<string, object> userProperties);
// Group analytics methods
Task AddCurrentUserToGroup(string anonymousId, string userId, string groupType, string groupId, IDictionary<string, object> groupProperties) {return Task.CompletedTask;}
Task SetGroupProperties(string anonymousId, string userId, string groupType, string groupId, IDictionary<string, object> groupProperties) {return Task.CompletedTask;}
Task LogEventWithGroups(string anonymousId, string userId, string eventName, IDictionary<string, object> eventProperties, IDictionary<string, object> groupTypesToGroupIds) {return Task.CompletedTask;}
// Unity specific methods
void Identify(string userId);
void Unidentify();
}

Read more about custom destinations here.

strict: Boolean: bool, if true, Avo will throw an exception when it detects a tracking problem in development or staging. Note that the strict flag is ignored in production.

setAvoLogger

C#
Copy
1
public static ILogger __LOGGER__ = null;

This field allows you to provide a custom implementation of the logger used by the Avo Functions. Can for example be used to disable logs or change which logging method is used.

Arguments

Microsoft.Extensions.Logging.ILogger __LOGGER__: custom implementation of the logger.

setSystemProperties

C#
Copy
1
public void SetSystemProperties(int systemProperty0, bool systemProperty1, ...)

A method to update system properties after initialization.

Arguments

systemProperties: a number of parameters equal to the number of system properties defined in your Avo workspace. The parameters are named the same as system properties, in camelCase, and require corresponding types: string, int, long, float, bool and list.

Event tracking functions

C#
Copy
1
public void [YourEventName](int eventProperty0, double? eventProperty1, ..., bool? userProperty0, IList<int> userProperty1, ..., string userId_, string anonymousId_)

Every event you define in your tracking plan in Avo gets a function named after the event in PascalCase. The arguments of the function depend on how it's defined in your tracking plan

Arguments

eventProperty: type defined in the Avo tracking plan, can be string, int, long, float, bool and list. Every event property attached to the event in the Avo UI gets a corresponding argument. The argument key is camelCase version of the property name. Pass the value of the property to track here.

userProperty: type defined in the Avo tracking plan as a user property, can be string, int, long, float, bool and list. Every user property attached to the event in the Avo UI gets a corresponding argument. The argument key is camelCase version of the property name. Pass the value of the property to update here.

userId_: String: used to connect event to specific user. Unity: Added if the event has the Identify User action .NET: added to all events, you have to either provide it or the anonymousId_

Additional arguments

anonymousId_: string, .NET only, this argument is automatically added if corresponding setting is enabled, used to track anonymous users

Destinations

You can send your data using the Avo generated C# code to any data destination that accepts custom events, including:

  • Amplitude
  • FacebookAnalytics
  • FullStory
  • Mixpanel
  • Mixpanel
  • Permutive
  • Segment
  • Snowplow
  • ZendeskConnect
  • Adobe Analytics
  • Apptelemetry
  • Rudderstack
  • Freshpaint
  • Posthog
  • Google Analytics 4 / Firebase Analytics
  • Heap
  • Keen
  • Kissmetrics
  • LaunchDarkly Events
  • Pendo
  • Fivetran
  • AppsFlyer
  • Braze
  • Intercom
  • A home made SDK
  • Internal API