.NET
Detailed technical documentation on using RudderStack’s .NET SDK to send events to various destinations.
Last updated
Was this helpful?
Detailed technical documentation on using RudderStack’s .NET SDK to send events to various destinations.
Last updated
Was this helpful?
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.
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.
You can use NuGet to install the .NET SDK into your project.
Our library depends on Newton.JSON library for JSON processing.
To initialize the RudderStack client, run the following code snippet:
Once the RudderStack client is initialized, you can then use it to send relevant customer events.
A sample track
call is as shown:
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
userId
String
Required, unless anonymousId
is set
Unique identifier for a particular user in your database.
traits
Object
Optional
Dictionary of the traits associated with the user, such as name
or email
.
options
Object
Optional
Object containing anonymousId
, integrations
, timestamp
, and context
.
Refer to The options parameter section below for more information on the options
object and its fields.
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:
userId
String
Required, unless anonymousId
is set
The developer identification for your user.
eventName
String
Required
Name of the event being performed by the user.
properties
Object
Optional
Dictionary of the properties associated with a particular event.
options
Object
Optional
Object containing anonymousId
, integrations
, timestamp
, and context
.
Refer to The options parameter section below for more information on the options
object and its fields.
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
userId
String
Required, unless anonymousId
is set
Unique identifier for a particular user in your database.
name
String
Required
Name of the page being viewed.
category
String
Optional
The category of the page.
properties
Object
Optional
Dictionary of the properties associated with the page being viewed, such as url
and referrer
.
options
Object
Optional
Object containing anonymousId
, integrations
, timestamp
, and context
.
Refer to The options parameter section below for more information on the options
object and its fields.
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
userId
String
Required, unless anonymousId
is set
Unique identifier for a particular user in your database.
name
String
Required
Name of the screen being viewed.
category
String
Optional
The category of the screen.
properties
Object
Optional
Dictionary of the properties associated with the page being viewed, such as url
and referrer
.
options
Object
Optional
Object containing anonymousId
, integrations
, timestamp
, and context
.
Refer to The options parameter section below for more information on the options
object and its fields.
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
userId
String
Required, unless anonymousId
is set
Unique identifier for a particular user in your database.
groupId
String
Required
Unique identifier of the group, as present in your database.
traits
Object
Optional
Dictionary of the properties or traits associated with the group, such as email
or name
.
options
Object
Optional
Object containing anonymousId
, integrations
, timestamp
, and context
.
Refer to The options parameter section below for more information on the options
object and its fields.
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
previousId
String
Required
The previous unique identifier of the user.
userId
String
Required, unless anonymousId
is set
Unique identifier for a particular user in your database.
options
Object
Optional
Object containing anonymousId
, integrations
, timestamp
, and context
.
Refer to The options parameter section below for more information on the options
object and its fields.
options
parameterThe options
object contains the following fields:
Field
Type
Presence
Description
anonymousId
String
Optional
Sets the user ID for cases where there is no unique identifier for the user. Either userId
or anonymousId
is required.
integrations
Object
Optional
A dictionary containing the destinations to be either enabled or disabled.
timestamp
Date
Optional
The timestamp of the message's arrival.
context
Object
Optional
Dictionary of information that provides context about a message. However, it is not directly related to the API call.
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.
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.
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.