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

  1. Bundle Analytics-CSharp into your app (and remove your previous SDK)
  2. Change the namespaces
  3. Advanced: Run Analytics in Synchronous Mode

Start the Migration

  1. 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>
    
  2. Replace namespaces.


    Before:

         using Segment;
         using Segment.Flush;
         using Segment.Model;
         using Segment.Request;
    


    After:

         using Segment.Analytics;
         using Segment.Analytics.Compat;
    

Optional Changes

  1. 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);
    
  2. 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 called Identify and want to go back to anonymous, try:


    After:

     analytics.Reset();
    

This page was last modified: 22 Sep 2023



Get started with Segment

Segment is the easiest way to integrate your websites & mobile apps data to over 300 analytics and growth tools.
or
Create free account