Analytics-CSharp (C#) Migration Guide
If you’re currently using Analytics.NET or Analytics.Xamarin to send data to Segment, please follow the steps below to migrate to the Analytics-CSharp library.
Analytics-C# does not include v1 as part of the url address. If you are using the Segment EU endpoint, you will have to pass it manually. For instance, events.eu1.segmentapis.com/v1
You can update to Analytics-CSharp in 3 steps:
- Bundle Analytics-CSharp into your app and remove your previous SDK.
- Change the namespaces.
- (Optional) Use
Resetto stay anonymous.
Migration steps
-
Add the Analytics-CSharp dependency to your project.
Before:dotnet add package Analytics --version <VERSION>
Before (for Xamarin users only):git clone https://github.com/segmentio/Analytics.Xamarin.git
After:dotnet add package Segment.Analytics.CSharp --version <VERSION> -
Replace namespaces.
Before:using Segment; using Segment.Flush; using Segment.Model; using Segment.Request;
After:using Segment.Analytics; using Segment.Analytics.Compat; -
(Optional) Update calls that resets the anonymous ID.
The old SDK requires you to provide the anonymous ID. The new SDK generates an Anonymous ID for you if you never call
analytics.Identify. If you callIdentifyand want to go back to anonymous, the new SDK provides aResetfunction to achieve that.
Before:Analytics.Client.Page(null, "Login", new Properties(), new Options() .SetAnonymousId("some-id"));
After:analytics.Reset();
Optional changes for unit tests
Change your development settings if you would like to make analytics run synchronously for testing purposes.
Before:
Analytics.Initialize("YOUR_WRITE_KEY", new Config().SetAsync(false));
After:
var configuration = new Configuration("YOUR WRITE KEY",
useSynchronizeDispatcher: true);
var analytics = new Analytics(configuration);
This page was last modified: 01 Feb 2024
Need support?
Questions? Problems? Need more info? Contact Segment Support for assistance!