> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hightouch.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C# SDK

> Hightouch's C# SDK for collecting events

The C# SDK makes it easy to track events from all C#/.NET applications.

## Installation

The C# SDK can be installed from [NuGet](https://www.nuget.org/packages/Hightouch.Events.CSharp):

```sh theme={null}
dotnet add package Hightouch.Events.CSharp
```

To initialize the C# SDK in your application, create a new `Analytics` instance:

```c# theme={null}
using Hightouch.Events;
using Hightouch.Events.Serialization;

var configuration = new Configuration("WRITE_KEY",
  apiHost: "https://us-east-1.hightouch-events.com",
  flushAt: 1);

var analytics = new Analytics(configuration);
```

## API

### Identify

The `analytics.Identify` method sends an [`identify`](https://docs.hightouch.com/events/event-spec#identify-events) event.

**Example usage**:

```c# theme={null}
analytics.Identify("user-123", new JsonObject {
    ["username"] = "MisterWhiskers",
    ["email"] = "hello@test.com",
    ["plan"] = "premium"
});
```

### Track

The `analytics.Track` method sends a [`track`](https://docs.hightouch.com/events/event-spec#track-events) event.

**Example usage**:

```c# theme={null}
analytics.Track("View Product", new JsonObject {
    ["productId"] = 123,
    ["productName"] = "Striped trousers"
});
```

### Page

The `analytics.Page` method sends a [`page`](https://docs.hightouch.com/events/event-spec#page-events) event.

**Example usage**:

```c# theme={null}
analytics.Page("PageName", new JsonObject {
    ["productSlug"] = "example-product-123"
});
```

### Screen

The `analytics.Screen` method sends a [`screen`](https://docs.hightouch.com/events/event-spec#screen-events) event.

**Example usage**:

```c# theme={null}
analytics.Screen("ScreenName", new JsonObject {
    ["productSlug"] = "example-product-123"
});
```

### Group

The `analytics.Group` method sends a [`group`](https://docs.hightouch.com/events/event-spec#group-events) event.

**Example usage**:

```c# theme={null}
analytics.Group("user-123", new JsonObject {
    ["username"] = "MisterWhiskers",
    ["email"] = "hello@test.com",
    ["plan"] = "premium"
});
```

### Flush

The C# SDK buffers events locally, either in-memory or on disk, before sending them to Hightouch's servers.
This minimizes the number of requests made by the SDK and makes the tracking non-blocking.

To force the local buffer to be sent to Hightouch immediately call the `Flush()`
method. `Flush()` should be called when shutting down your app to make sure no events are lost.

**Example usage**:

```c# theme={null}
analytics.Flush()
```
