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.
You can update to Analytics-CSharp in 3 easy steps
- Bundle Analytics-CSharp into your app (and remove your previous SDK)
- Change the namespaces
- Advanced: Run Analytics in Synchronous Mode
Start the Migration
-
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 Changes
-
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);
-
Review your anonymous ID settings.
Before:Analytics.Client.Page(null, "Login", new Properties(), new Options() .SetAnonymousId("some-id"));
The new SDK by default, generates an Anonymous ID for you if you never call
analytics.Identify
. If you’ve calledIdentify
and want to go back to anonymous, try:
After:analytics.Reset();
This page was last modified: 22 Sep 2023
Need support?
Questions? Problems? Need more info? Contact Segment Support for assistance!