|
| 1 | +--- |
| 2 | +title: Analytics for CSharp (C#) |
| 3 | +strat: csharp |
| 4 | +--- |
| 5 | + |
| 6 | +If you’re using a different library such as Analytics .Net, follow these steps to migrate to the Analytics-CSharp library: |
| 7 | + |
| 8 | +1. Create a source in Segment. If you want to reuse your current source, skip to step 2. |
| 9 | + 1. Go to Connections > Sources > Add Source. |
| 10 | + 2. Search for Xamarin or Unity or .NET and click Add source. |
| 11 | +2. Add the Analytics CSharp dependency to your project. |
| 12 | + |
| 13 | + <br> Before: |
| 14 | + ```js |
| 15 | + dotnet add package Analytics --version <VERSION> |
| 16 | + ``` |
| 17 | + |
| 18 | + <br>After |
| 19 | + ```js |
| 20 | + dotnet add package Segment.Analytics.CSharp --version <VERSION> |
| 21 | + ``` |
| 22 | + |
| 23 | +3. Modify your tracking methods. |
| 24 | + - Identify |
| 25 | + |
| 26 | + <br> Before example |
| 27 | + ```c# |
| 28 | + Analytics.Client.Identify("019mr8mf4r", new Traits() { |
| 29 | + { "name", "#{ user.name }" }, |
| 30 | + { "email", "#{ user.email }" }, |
| 31 | + { "friends", 29 } |
| 32 | + }); |
| 33 | + ``` |
| 34 | + |
| 35 | + <br> After example |
| 36 | + ```c# |
| 37 | + // compatbile with the old way |
| 38 | + analytics.Identify("019mr8mf4r", new JsonObject() |
| 39 | + { |
| 40 | + { "name", "#{ user.name }" }, |
| 41 | + { "email", "#{ user.email }" }, |
| 42 | + { "friends", 29 } |
| 43 | + }); |
| 44 | +
|
| 45 | + // below is the new way |
| 46 | + analytics.Identify("019mr8mf4r", new JsonObject |
| 47 | + { |
| 48 | + ["name"] = "#{user.name}", |
| 49 | + ["email"] = "#{user.email}", |
| 50 | + ["friends"] = 29 |
| 51 | + }); |
| 52 | + ``` |
| 53 | + |
| 54 | + - Track |
| 55 | + <br> Before example |
| 56 | + ```c# |
| 57 | + Analytics.Client.Track("019mr8mf4r", "Item Purchased", new Properties() { |
| 58 | + { "revenue", 39.95 }, |
| 59 | + { "shipping", "2-day" } |
| 60 | + }); |
| 61 | + ``` |
| 62 | + |
| 63 | + <br> After example |
| 64 | + ```c# |
| 65 | + // compatbile with the old way |
| 66 | + analytics.Track("Item Purchased", new JsonObject() |
| 67 | + { |
| 68 | + { "revenue", 39.95 }, |
| 69 | + { "shipping", "2-day" } |
| 70 | + }); |
| 71 | +
|
| 72 | + // below is the new way |
| 73 | + analytics.Track("Item Purchased", new JsonObject |
| 74 | + { |
| 75 | + ["revenue"] = 39.95, |
| 76 | + ["shipping"] = "2-days" |
| 77 | + }); |
| 78 | + ``` |
| 79 | + **Note:** |
| 80 | + |
0 commit comments