.NET
Detailed technical documentation on using RudderStack’s .NET SDK to send events to various destinations.
The RudderStack .NET SDK lets you track your customer event data from your .NET applications and send it to your specified destinations via RudderStack.
Check the GitHub codebase to get a more hands-on understanding of the SDK.
SDK setup requirements
To set up the RudderStack .NET SDK, the following prerequisites must be met:
You will need to set up a RudderStack account.
Once signed up, set up a .NET source in the dashboard. For more information, follow this guide. You should then see a Write Key for this source, as shown below:
You will also need a data plane URL. Follow this section for more information on the data plane URL and where to get it.
Installing the .NET SDK
You can use NuGet to install the .NET SDK into your project.
Our library depends on Newton.JSON library for JSON processing.
Initializing the RudderStack client
To initialize the RudderStack client, run the following code snippet:
Sending events from RudderStack
Once the RudderStack client is initialized, you can then use it to send relevant customer events.
A sample track
call is as shown:
Identify
The identify
call lets you associate a user to their actions as well as captures the relevant traits or properties related to that user.
A sample identify
call is shown below:
The identify
method parameters are as described below:
Field | Type | Presence | Description |
| String | Required, unless | Unique identifier for a particular user in your database. |
| Object | Optional | Dictionary of the traits associated with the user, such as |
| Object | Optional | Object containing |
Refer to The options parameter section below for more information on the options
object and its fields.
Track
The track
call lets you record the user actions along with their associated properties. Each user action is called an event.
A sample track
call is shown below:
The track
method parameters are:
Name | Type | Presence | Description |
---|---|---|---|
| String | Required, unless | The developer identification for your user. |
| String | Required | Name of the event being performed by the user. |
| Object | Optional | Dictionary of the properties associated with a particular event. |
| Object | Optional | Object containing |
Refer to The options parameter section below for more information on the options
object and its fields.
Page
The page
call allows you to record the page views on your website along with the other relevant information about the viewed page.
A sample page
call is as shown:
The page
method parameters are as described below:
Field | Type | Presence | Description |
| String | Required, unless | Unique identifier for a particular user in your database. |
| String | Required | Name of the page being viewed. |
| String | Optional | The category of the page. |
| Object | Optional | Dictionary of the properties associated with the page being viewed, such as |
| Object | Optional | Object containing |
Refer to The options parameter section below for more information on the options
object and its fields.
Screen
The screen
call is the mobile equivalent of the page
call. It allows you to record the screen views on your mobile app along with the other relevant information about the app screen.
A sample screen
call is as shown:
The screen
method parameters are as described below:
Field | Type | Presence | Description |
| String | Required, unless | Unique identifier for a particular user in your database. |
| String | Required | Name of the screen being viewed. |
| String | Optional | The category of the screen. |
| Object | Optional | Dictionary of the properties associated with the page being viewed, such as |
| Object | Optional | Object containing |
Refer to The options parameter section below for more information on the options
object and its fields.
Group
The group
call lets you associate an identified user to a group - either a company, project, or a team, and record any custom traits or properties associated with that group.
A sample group
call is as shown:
The group
method parameters are as follows:
Field | Type | Presence | Description |
| String | Required, unless | Unique identifier for a particular user in your database. |
| String | Required | Unique identifier of the group, as present in your database. |
| Object | Optional | Dictionary of the properties or traits associated with the group, such as |
| Object | Optional | Object containing |
Refer to The options parameter section below for more information on the options
object and its fields.
Alias
The alias
call allows you to associate one identity with another.
alias
is an advanced method that lets you change the tracked user's ID explicitly. This method is useful when managing identities for some of the downstream destinations.
For a detailed explanation of the alias
call, refer to the RudderStack API Specification guide.
A sample alias
call is as shown:
The alias
method parameters are as mentioned below:
Field | Type | Presence | Description |
| String | Required | The previous unique identifier of the user. |
| String | Required, unless | Unique identifier for a particular user in your database. |
| Object | Optional | Object containing |
Refer to The options parameter section below for more information on the options
object and its fields.
The options
parameter
options
parameterThe options
object contains the following fields:
Field | Type | Presence | Description |
| String | Optional | Sets the user ID for cases where there is no unique identifier for the user. Either |
| Object | Optional | A dictionary containing the destinations to be either enabled or disabled. |
| Date | Optional | The timestamp of the message's arrival. |
| Object | Optional | Dictionary of information that provides context about a message. However, it is not directly related to the API call. |
Flushing events
To make sure no events are left in the queue, you can flush the events explicitly by using the SDK's flush()
method, as shown:
Calling flush()
again is blocked until all the messages are flushed from the queue.
Logging
The RudderStack .NET SDK supports detailed logging. You can enable this feature as shown:
The logger must be on a minimum version of .NET Core 2.1.
Contact us
For queries on any of the sections covered in this guide, you can contact us or start a conversation in our Slack community.
If you come across any issues while using the .NET SDK, you can open a new issue on our GitHub Issues page.
Last updated