diff --git a/src/connections/sources/catalog/libraries/mobile/android/android-faqs.md b/src/connections/sources/catalog/libraries/mobile/android/android-faqs.md index 5ae67b2af6..f4be8545ab 100644 --- a/src/connections/sources/catalog/libraries/mobile/android/android-faqs.md +++ b/src/connections/sources/catalog/libraries/mobile/android/android-faqs.md @@ -1,8 +1,14 @@ --- title: 'Analytics-Android frequently asked questions' strat: android +custom_ranking: + heading: 0 + position: 99999 --- +> warning "End-of-Support for Analytics-Android in March 2026" +> End-of-support for the Analytics-Android SDK is scheduled for March 2026. Segment's future development efforts concentrate on the new [Analytics-Kotlin](/docs/connections/sources/catalog/libraries/mobile/kotlin-android/) SDK. If you'd like to upgrade to Analytics-Kotlin, see the [migration guide](/docs/connections/sources/catalog/libraries/mobile/kotlin-android/migration/). + ## What is the latest version of the library? Analytics-Android is published to [Maven Central](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.segment.analytics.android%22%20AND%20a%3A%22analytics%22) where you can see all published releases. diff --git a/src/connections/sources/catalog/libraries/mobile/android/changelog.md b/src/connections/sources/catalog/libraries/mobile/android/changelog.md index 7a2bc56345..651dd6b48d 100644 --- a/src/connections/sources/catalog/libraries/mobile/android/changelog.md +++ b/src/connections/sources/catalog/libraries/mobile/android/changelog.md @@ -2,5 +2,8 @@ title: Analytics-Android Changelog repo: analytics-android strat: android +custom_ranking: + heading: 0 + position: 99999 --- {% include content/changelog.html %} \ No newline at end of file diff --git a/src/connections/sources/catalog/libraries/mobile/android/index.md b/src/connections/sources/catalog/libraries/mobile/android/index.md index 818392abc1..34470ffb10 100644 --- a/src/connections/sources/catalog/libraries/mobile/android/index.md +++ b/src/connections/sources/catalog/libraries/mobile/android/index.md @@ -2,16 +2,19 @@ title: 'Analytics-Android' strat: android repo: analytics-android -support_type: maintenance +support_type: community id: wXNairW5xX +custom_ranking: + heading: 0 + position: 99999 --- Analytics-Android makes it easier for you to send data to any tool without having to learn, test or implement a new API every time. Analytics-Android only supports any Android device running API 14 (Android 4.0) and higher. This includes Amazon Fire devices. -> info "Analytics-Kotlin" -> The Analytics-Kotlin library is in General Availability. You can use Analytics-Kotlin for [mobile](/docs/connections/sources/catalog/libraries/mobile/kotlin-android/) or [server](/docs/connections/sources/catalog/libraries/server/kotlin) applications. If you'd like to upgrade to Analytics-Kotlin, see the [migration guide](/docs/connections/sources/catalog/libraries/mobile/kotlin-android/migration/). Segment's future development efforts concentrate on the new Analytics-Kotlin SDK, and will only ship security updates for the Analytics-Android SDK. +> warning "End-of-Support for Analytics-Android in March 2026" +> End-of-support for the Analytics-Android SDK is scheduled for March 2026. Segment's future development efforts concentrate on the new [Analytics-Kotlin](/docs/connections/sources/catalog/libraries/mobile/kotlin-android/) SDK. If you'd like to upgrade to Analytics-Kotlin, see the [migration guide](/docs/connections/sources/catalog/libraries/mobile/kotlin-android/migration/). > success "" > In addition to the documentation here, you can also [read the Javadocs for all versions of Analytics-Android on Javadoc.io](https://javadoc.io/doc/com.segment.analytics.android/analytics/latest/index.html). diff --git a/src/connections/sources/catalog/libraries/mobile/android/middleware.md b/src/connections/sources/catalog/libraries/mobile/android/middleware.md index a336962f35..b786f26601 100644 --- a/src/connections/sources/catalog/libraries/mobile/android/middleware.md +++ b/src/connections/sources/catalog/libraries/mobile/android/middleware.md @@ -1,8 +1,14 @@ --- title: 'Middleware for Analytics-Android' strat: android +custom_ranking: + heading: 0 + position: 99999 --- +> warning "End-of-Support for Analytics-Android in March 2026" +> End-of-support for the Analytics-Android SDK is scheduled for March 2026. Segment's future development efforts concentrate on the new [Analytics-Kotlin](/docs/connections/sources/catalog/libraries/mobile/kotlin-android/) SDK. If you'd like to upgrade to Analytics-Kotlin, see the [migration guide](/docs/connections/sources/catalog/libraries/mobile/kotlin-android/migration/). + Middlewares are a powerful mechanism that can augment the events collected by the SDK. A middleware is a simple function that is invoked by the Segment SDK and can be used to monitor, modify, augment or reject events. Source Middleware are available on analytics-android 4.3.0 and later. Destination Middleware are available on analytics-android 4.7.0 and later. You can register source middleware during construction with the `.useSourceMiddleware` method on the builder. These middleware are invoked for all events, including automatically tracked events, and external event sources like Adjust and Optimizely. diff --git a/src/connections/sources/catalog/libraries/mobile/android/quickstart.md b/src/connections/sources/catalog/libraries/mobile/android/quickstart.md index f26b9eccbc..e75e23018b 100644 --- a/src/connections/sources/catalog/libraries/mobile/android/quickstart.md +++ b/src/connections/sources/catalog/libraries/mobile/android/quickstart.md @@ -2,8 +2,14 @@ title: 'Quickstart: Analytics-Android' hidden: true strat: android +custom_ranking: + heading: 0 + position: 99999 --- +> warning "End-of-Support for Analytics-Android in March 2026" +> End-of-support for the Analytics-Android SDK is scheduled for March 2026. Segment's future development efforts concentrate on the new [Analytics-Kotlin](/docs/connections/sources/catalog/libraries/mobile/kotlin-android/) SDK. If you'd like to upgrade to Analytics-Kotlin, see the [migration guide](/docs/connections/sources/catalog/libraries/mobile/kotlin-android/migration/). + [](https://maven-badges.herokuapp.com/maven-central/com.segment.analytics.android/analytics) This tutorial will help you start sending analytics data from your Android app to Segment and any of our destinations, using our Android library. As soon as you're set up you'll be able to turn on any new destinations with the flip of a switch! diff --git a/src/connections/sources/catalog/libraries/mobile/android/troubleshooting.md b/src/connections/sources/catalog/libraries/mobile/android/troubleshooting.md index b7d4d3b611..802b3b23ee 100644 --- a/src/connections/sources/catalog/libraries/mobile/android/troubleshooting.md +++ b/src/connections/sources/catalog/libraries/mobile/android/troubleshooting.md @@ -1,8 +1,14 @@ --- title: 'Troubleshooting Analytics-Android' strat: android +custom_ranking: + heading: 0 + position: 99999 --- +> warning "End-of-Support for Analytics-Android in March 2026" +> End-of-support for the Analytics-Android SDK is scheduled for March 2026. Segment's future development efforts concentrate on the new [Analytics-Kotlin](/docs/connections/sources/catalog/libraries/mobile/kotlin-android/) SDK. If you'd like to upgrade to Analytics-Kotlin, see the [migration guide](/docs/connections/sources/catalog/libraries/mobile/kotlin-android/migration/). + ## No events in my debugger 1. Check that you followed all of the [Getting Started](/docs/connections/sources/catalog/libraries/mobile/android/#getting-started) steps correctly diff --git a/src/connections/sources/catalog/libraries/mobile/android/wear.md b/src/connections/sources/catalog/libraries/mobile/android/wear.md index 4e8727560d..e9ec90f0ee 100644 --- a/src/connections/sources/catalog/libraries/mobile/android/wear.md +++ b/src/connections/sources/catalog/libraries/mobile/android/wear.md @@ -2,8 +2,14 @@ title: 'Analytics-Android Wear' strat: android hidden: true +custom_ranking: + heading: 0 + position: 99999 --- +> warning "End-of-Support for Analytics-Android in March 2026" +> End-of-support for the Analytics-Android SDK is scheduled for March 2026. Segment's future development efforts concentrate on the new [Analytics-Kotlin](/docs/connections/sources/catalog/libraries/mobile/kotlin-android/) SDK. If you'd like to upgrade to Analytics-Kotlin, see the [migration guide](/docs/connections/sources/catalog/libraries/mobile/kotlin-android/migration/). + Analytics-Android Wear makes it simple to send your data to any tool without having to learn, test, or implement a new API every time. All of Segment's client libraries are open-source, so you can [view Analytics-Android on GitHub](https://github.com/segmentio/analytics-android), or check out our [browser and server-side libraries](/docs/connections/sources/catalog/) too. diff --git a/src/connections/sources/catalog/libraries/mobile/ios/changelog.md b/src/connections/sources/catalog/libraries/mobile/ios/changelog.md index e364e2df7a..85a8312245 100644 --- a/src/connections/sources/catalog/libraries/mobile/ios/changelog.md +++ b/src/connections/sources/catalog/libraries/mobile/ios/changelog.md @@ -2,5 +2,8 @@ title: Analytics-iOS Changelog repo: analytics-ios strat: ios +custom_ranking: + heading: 0 + position: 99999 --- {% include content/changelog.html %} \ No newline at end of file diff --git a/src/connections/sources/catalog/libraries/mobile/ios/index.md b/src/connections/sources/catalog/libraries/mobile/ios/index.md index 2d224e2cb4..4e8d09d9c6 100644 --- a/src/connections/sources/catalog/libraries/mobile/ios/index.md +++ b/src/connections/sources/catalog/libraries/mobile/ios/index.md @@ -2,21 +2,24 @@ title: Analytics-iOS strat: ios repo: analytics-ios -support_type: maintenance +support_type: community id: UBrsG9RVzw +custom_ranking: + heading: 0 + position: 99999 --- With Analytics-iOS, you can send your data to analytics or marketing tool, without needing to learn, test, or implement a new API with each update or addition. <br /> <br /> <br /> +> warning "End-of-Support for Analytics-iOS in March 2026" +> End-of-support for the Analytics-iOS SDK is scheduled for March 2026. Segment's future development efforts concentrate on the new [Analytics-Swift](/docs/connections/sources/catalog/libraries/mobile/swift/){:target="_blank”} SDK. If you'd like to migrate to Analytics-Swift, see the [migration guide](/docs/connections/sources/catalog/libraries/mobile/swift/migration/){:target="_blank”}. + > info "Watchkit extensions currently unsupported" > Segment does not currently support tracking of watchkit extensions for the Apple Watch. [Email Segment](https://segment.com/requests/integrations/){:target="_blank”}. if you're interested in a Watchkit SDK. For now Segment recommends tracking watch interactions using the iPhone app code. -> info "Analytics-Swift" -> The [Analytics-Swift](/docs/connections/sources/catalog/libraries/mobile/swift/){:target="_blank”}. library is in General Availability. If you'd like to migrate to Analytics-Swift, see the [migration guide](/docs/connections/sources/catalog/libraries/mobile/swift/migration/){:target="_blank”}.. Segment's future development efforts concentrate on the new Analytics-Kotlin SDK, and will only ship security updates for the Analytics-Android SDK. - ## Analytics-iOS and Unique Identifiers One of the most important parts of any analytics platform is the ability to consistently and accurately identify users. To do this, the platform must assign and persist some form of identification on the device, so you can analyze user actions effectively. This is especially important for funnel conversion analysis and retention analysis. diff --git a/src/connections/sources/catalog/libraries/mobile/ios/ios-faqs.md b/src/connections/sources/catalog/libraries/mobile/ios/ios-faqs.md index 3edf802f60..93004e11aa 100644 --- a/src/connections/sources/catalog/libraries/mobile/ios/ios-faqs.md +++ b/src/connections/sources/catalog/libraries/mobile/ios/ios-faqs.md @@ -1,8 +1,14 @@ --- title: Analytics-iOS Frequently asked questions strat: ios +custom_ranking: + heading: 0 + position: 99999 --- +> warning "End-of-Support for Analytics-iOS in March 2026" +> End-of-support for the Analytics-iOS SDK is scheduled for March 2026. Segment's future development efforts concentrate on the new [Analytics-Swift](/docs/connections/sources/catalog/libraries/mobile/swift/){:target="_blank”} SDK. If you'd like to migrate to Analytics-Swift, see the [migration guide](/docs/connections/sources/catalog/libraries/mobile/swift/migration/){:target="_blank”}. + ## How big is the Segment SDK? The core Segment SDK is extremely lightweight. It weighs in at about 212KB. diff --git a/src/connections/sources/catalog/libraries/mobile/ios/ios14-guide.md b/src/connections/sources/catalog/libraries/mobile/ios/ios14-guide.md index 78ce64d22a..c05be97519 100644 --- a/src/connections/sources/catalog/libraries/mobile/ios/ios14-guide.md +++ b/src/connections/sources/catalog/libraries/mobile/ios/ios14-guide.md @@ -1,8 +1,14 @@ --- title: iOS 14 Guide strat: ios +custom_ranking: + heading: 0 + position: 99999 --- +> warning "End-of-Support for Analytics-iOS in March 2026" +> End-of-support for the Analytics-iOS SDK is scheduled for March 2026. Segment's future development efforts concentrate on the new [Analytics-Swift](/docs/connections/sources/catalog/libraries/mobile/swift/){:target="_blank”} SDK. If you'd like to migrate to Analytics-Swift, see the [migration guide](/docs/connections/sources/catalog/libraries/mobile/swift/migration/){:target="_blank”}. + > warning "" > You should update your `analytics-ios` and device-mode destinations to adapt to iOS 14 changes explained in this guide. For information about iOS 14.5, see [What's new in iOS 14.5](#whats-new-with-ios-145) below. diff --git a/src/connections/sources/catalog/libraries/mobile/ios/middleware.md b/src/connections/sources/catalog/libraries/mobile/ios/middleware.md index 7afe275a69..129d4654bc 100644 --- a/src/connections/sources/catalog/libraries/mobile/ios/middleware.md +++ b/src/connections/sources/catalog/libraries/mobile/ios/middleware.md @@ -1,8 +1,14 @@ --- title: Middleware for iOS strat: ios +custom_ranking: + heading: 0 + position: 99999 --- +> warning "End-of-Support for Analytics-iOS in March 2026" +> End-of-support (EoS) for the Analytics-iOS SDK is scheduled for March 2026. Segment's future development efforts concentrate on the new [Analytics-Swift](/docs/connections/sources/catalog/libraries/mobile/swift/){:target="_blank”} SDK. If you'd like to migrate to Analytics-Swift, see the [migration guide](/docs/connections/sources/catalog/libraries/mobile/swift/migration/){:target="_blank”}. + Middlewares are simple functions invoked by the Segment libraries, which give you a way to add information to the events you collect using the Segment SDKs. They can be used to monitor, modify, or reject events. Source Middlewares are available on `analytics-ios` 3.6.0 and later. You can access the middleware API in both Objective-C and Swift. diff --git a/src/connections/sources/catalog/libraries/mobile/ios/quickstart.md b/src/connections/sources/catalog/libraries/mobile/ios/quickstart.md index 6ff95a8a3f..8e393b8acc 100644 --- a/src/connections/sources/catalog/libraries/mobile/ios/quickstart.md +++ b/src/connections/sources/catalog/libraries/mobile/ios/quickstart.md @@ -2,8 +2,14 @@ title: 'Quickstart: iOS' hidden: true strat: ios +custom_ranking: + heading: 0 + position: 99999 --- +> warning "End-of-Support for Analytics-iOS in March 2026" +> End-of-support for the Analytics-iOS SDK is scheduled for March 2026. Segment's future development efforts concentrate on the new [Analytics-Swift](/docs/connections/sources/catalog/libraries/mobile/swift/){:target="_blank”} SDK. If you'd like to migrate to Analytics-Swift, see the [migration guide](/docs/connections/sources/catalog/libraries/mobile/swift/migration/){:target="_blank”}. + This tutorial gets you started sending data from your iOS app to Segment. When you're done you can turn on [any of Segment's destinations](/docs/connections/destinations/) with the flip of a switch! No more waiting for App Store approval. If you want to dive deeper at any point, check out the [iOS Library Reference](/docs/connections/sources/catalog/libraries/mobile/ios/). diff --git a/src/connections/sources/catalog/libraries/mobile/ios/troubleshooting.md b/src/connections/sources/catalog/libraries/mobile/ios/troubleshooting.md index 4f51dd8f55..6557997b51 100644 --- a/src/connections/sources/catalog/libraries/mobile/ios/troubleshooting.md +++ b/src/connections/sources/catalog/libraries/mobile/ios/troubleshooting.md @@ -1,8 +1,14 @@ --- title: Troubleshooting Analytics-iOS strat: ios +custom_ranking: + heading: 0 + position: 99999 --- +> warning "End-of-Support for Analytics-iOS in March 2026" +> End-of-support for the Analytics-iOS SDK is scheduled for March 2026. Segment's future development efforts concentrate on the new [Analytics-Swift](/docs/connections/sources/catalog/libraries/mobile/swift/){:target="_blank”} SDK. If you'd like to migrate to Analytics-Swift, see the [migration guide](/docs/connections/sources/catalog/libraries/mobile/swift/migration/){:target="_blank”}. + ## Target has transitive dependencies that include static binaries This was due to an old [CocoaPods limitation](https://github.com/CocoaPods/CocoaPods/issues/2926). diff --git a/src/connections/sources/catalog/libraries/mobile/react-native/index.md b/src/connections/sources/catalog/libraries/mobile/react-native/index.md index c0a0ce9a87..545fb13ec0 100644 --- a/src/connections/sources/catalog/libraries/mobile/react-native/index.md +++ b/src/connections/sources/catalog/libraries/mobile/react-native/index.md @@ -88,7 +88,7 @@ These are the options you can apply to configure the client: | `storePersistor` | undefined | A custom persistor for the store that `analytics-react-native` uses. Must match [`Persistor`](https://github.com/segmentio/analytics-react-native/blob/master/packages/sovran/src/persistor/persistor.ts#L1-L18) interface exported from [sovran-react-native](https://github.com/segmentio/analytics-react-native/blob/master/packages/sovran). | | `proxy` | undefined | `proxy` is a batch url to post to instead of 'https://api.segment.io/v1/b'. | | `errorHandler` | undefined | Create custom actions when errors happen, see [Handling errors](#handling-errors) | - +| `useSegmentEndpoints` | false | Set to `true` to automatically append the Segment endpoints when using `proxy` or `cdnProxy` to send or fetch settings. Otherwise, `proxy` or `cdnProxy` will be used as is. | ## Adding Plugins to the Client diff --git a/src/connections/sources/catalog/libraries/mobile/xamarin/analytics-xamarin.md b/src/connections/sources/catalog/libraries/mobile/xamarin/analytics-xamarin.md new file mode 100644 index 0000000000..03d79299f9 --- /dev/null +++ b/src/connections/sources/catalog/libraries/mobile/xamarin/analytics-xamarin.md @@ -0,0 +1,422 @@ +--- +title: Analytics for Xamarin +sourceTitle: 'Xamarin' +sourceCategory: 'Mobile' +id: wcssVcPJrc +hidden: true +support_type: community +--- + +> warning "End-of-Support for Analytics.Xamarin in March 2026" +> End-of-support for the Analytics.Xamarin SDK is scheduled for March 2026. Segment's future development efforts concentrate on the new [Analytics-CSharp](/docs/connections/sources/catalog/libraries/server/csharp/) SDK. If you'd like to migrate to Analytics-CSharp, see the [migration guide](/docs/connections/sources/catalog/libraries/server/csharp/migration-guide/). + +Segment's [Xamarin](http://xamarin.com/) Portable Class Library ([PCL](http://developer.xamarin.com/guides/cross-platform/application_fundamentals/pcl/)) is the best way to integrate analytics into your Xamarin application. It lets you record analytics data from your C#, F#, and .NET code, and supports `PCL Profile 4.0 - Profile136`, which targets the following platforms: + +- .NET Framework 4 or later +- Windows Phone 8 or later +- Silverlight 5 +- Windows 8 +- Windows Phone Silverlight 8 +- Windows Store apps (Windows 8) +- Xamarin.Android +- Xamarin.iOS + +The library issues requests that hit our servers, and then we route your data to any analytics service you enable on our destinations page. This library is open-source, so you can [check it out on GitHub](https://github.com/segmentio/Analytics.Xamarin). + +**Note:** Since Xamarin requires Segment's library to be portable to different builds, Segment can only enable server-side destinations, as opposed to bundling select native SDKs like we do for iOS and Android. Look for the "Server" icon when selecting destinations. For tools for which we offer both bundled and server-side destinations, like Mixpanel, Amplitude, and Google Analytics, Segment's Xamarin library will only be able to use their server-side functionality. + +## Getting Started + +Clone `Analytics.Xamarin` from [GitHub](https://github.com/segmentio/Analytics.Xamarin)... + +```bash +git clone https://github.com/segmentio/Analytics.Xamarin.git +``` + +Import the `Analytics.Xamarin` project into Xamarin Studio, and add it as a reference to your code. + +Now you'll need to initialize the library. + +```csharp +using Segment; + +// initialize with your Segment source write key ... +Analytics.Initialize("YOUR_WRITE_KEY"); +``` + +You only need to initialize once at the start of your program. You can then keep using the `Analytics` singleton anywhere in your code. + +The default initialization settings are production-ready and queue messages on another thread before sending any requests. In development you might want to use [development settings](/docs/connections/sources/catalog/libraries/mobile/xamarin/#development-settings). + +## Identify + +`identify` lets you tie a user to their actions and record traits about them. It includes a unique User ID and any optional traits you know about them. + +We recommend calling `identify` a single time when the user's account is first created, and only identifying again later when their traits change. + +Example `identify` call: + +```csharp +Analytics.Client.Identify("019mr8mf4r", new Traits() { + { "name", "Tom Smykowski" }, + { "email", "tom@example.com" }, + { "friends", 29 } +}); +``` + +This example call identifies Tom by his unique User ID (the one you know him by in your database) and label him with `name`, `email` and `friends` traits. + +The `identify` call has the following fields: + +<table class="api-table"> + <tr> + <td>`userId` _String_</td> + <td>The ID for this user in your database.</td> + </tr> + <tr> + <td>`Traits` _Traits, optional_</td> + <td>A dictionary of traits you know about the user. Things like: `email`, `name` or `friends`.</td> + </tr> + <tr> + <td>`options` _Options, optional_</td> + <td>An `Options` object lets you set a [timestamp](#historical-import), [enable or disable destinations](#selecting-destinations), or [send additional context](#context).</td> + </tr> +</table> + +Find details on the **identify method payload** in our [Spec](/docs/connections/spec/identify/). + +## Track + +`track` lets you record the actions your users perform. Every action triggers what we call an "event", which can also have associated properties. + +You'll want to track events that are indicators of success for your site, like **Signed Up**, **Item Purchased** or **Article Bookmarked**. + +To get started, we recommend tracking just a few important events. You can always add more later! + +Example `track` call: + +```csharp +Analytics.Client.Track("019mr8mf4r", "Item Purchased", new Properties() { + { "revenue", 39.95 }, + { "shipping", "2-day" } +}); +``` +This example `track` call tells us that your user just triggered the **Item Purchased** event with a revenue of $39.95 and chose your hypothetical '2-day' shipping. + +`track` event properties can be anything you want to record. + +The `track` call has the following fields: + +<table class="api-table"> + <tr> + <td>`userId` _String_</td> + <td>The ID for this user in your database.</td> + </tr> + <tr> + <td>`event` _String_</td> + <td>The name of the event you're tracking. We recommend human-readable names like <strong>Played Song</strong> or <strong>Updated Status</strong>.</td> + </tr> + <tr> + <td>`properties` _Properties, optional_</td> + <td>A dictionary of properties for the event. If the event was <strong>Added to Cart</strong>, it might have properties like `price` or `product`.</td> + </tr> + <tr> + <td>`options` _Options, optional_</td> + <td>An `Options` object lets you set a [timestamp](#historical-import), [enable or disable destinations](#selecting-destinations), or [send additional context](#context).</td> + </tr> +</table> + +Find details on **best practices in event naming** as well as the **`track` method payload** in our [Spec](/docs/connections/spec/track/). + +## Screen + +The [`screen`](/docs/connections/spec/screen/) method lets you you record whenever a user sees a screen of your mobile app, along with optional extra information about the page being viewed. + +You'll want to record a screen event an event whenever the user opens a screen in your app. This could be a view, fragment, dialog or activity depending on your app. + +Not all services support screen, so when it's not supported explicitly, the screen method tracks as an event with the same parameters. + +Example `screen` call: + +```csharp +Analytics.Client.Screen("019mr8mf4r", "Register", new Properties() { + { "type", "facebook" } +}); +``` + +The `screen` call has the following fields: + +<table class="api-table"> + <tr> + <td>`userId` _String_</td> + <td>The ID for this user in your database.</td> + </tr> + <tr> + <td>`name` _String_</td> + <td>The screen name you're tracking. We recommend human-readable names like <strong>Login</strong> or <strong>Register</strong>.</td> + </tr> + <tr> + <td>`category` _String_</td> + <td>The screen category. If you're making a news app, the category could be <strong>Sports</strong>.</td> + </tr> + <tr> + <td>`properties` _Properties, optional_</td> + <td>A dictionary of properties for the screen view. If the screen is <strong>Restaurant Reviews</strong>, it might have properties like `reviewCount` or `restaurantName`.</td> + </tr> + <tr> + <td>`options` _Options, optional_</td> + <td>An `Options` object lets you set a [timestamp](#historical-import), [enable or disable destinations](#selecting-destinations), or [send additional context](#context).</td> + </tr> +</table> + +Find details on the **`screen` payload** in our [Spec](/docs/connections/spec/screen/). + +## Group + +`group` lets you associate an [identified user](/docs/connections/sources/catalog/libraries/server/java/#identify) user with a group. A group could be a company, organization, account, project or team! It also lets you record custom traits about the group, like industry or number of employees. + +This is useful for tools like [Intercom](/docs/connections/destinations/catalog/intercom/), [Preact](/docs/connections/destinations/catalog/preact/) and [Totango](/docs/connections/destinations/catalog/totango/), as it ties the user to a **group** of other users. + +Example `group` call: + +```csharp +Analytics.Client.Group("userId", "groupId", new Traits() { + { "name", "Initech, Inc." }, + { "website", "http://www.example.com" } +}); +``` +The `group` call has the following fields: + +<table class="api-table"> + <tr> + <td>`userId` _String_</td> + <td>The ID for this user in your database.</td> + </tr> + <tr> + <td>`groupId` _String_</td> + <td>The ID for this group in your database.</td> + </tr> + <tr> + <td>`traits` _Traits, optional_</td> + <td>A dictionary of traits you know about the group. Things like: `name` or `website`.</td> + </tr> + <tr> + <td>`options` _Options, optional_</td> + <td>An `Options` object lets you set a [timestamp](#historical-import), [enable or disable destinations](#selecting-destinations), or [send additional context](#context).</td> + </tr> +</table> + +Find more details about `group` including the **`group` payload** in our [Spec](/docs/connections/spec/group/). + +## Alias + +`alias` is how you associate one identity with another. This is an advanced method, but it is required to manage user identities successfully in *some* of our destinations. + +In [Mixpanel](/docs/connections/destinations/catalog/mixpanel/#alias) it's used to associate an anonymous user with an identified user once they sign up. For [Kissmetrics](/docs/connections/destinations/catalog/kissmetrics/#alias), if your user switches IDs, you can use 'alias' to rename the 'userId'. + +Example `alias` call: + +```csharp +Analytics.Client.Alias("previousId", "userId"); +``` + +Here's a full example of how we might use the `alias` call: + +```csharp +// the anonymous user does actions ... +Analytics.Client.Track("anonymous_user", "Anonymous Event"); +// the anonymous user signs up and is aliased +Analytics.Client.Alias("anonymous_user", "identified@example.com"); +// the identified user is identified +Analytics.Client.Identify("identified@example.com", new Traits() { plan: "Free" }); +// the identified user does actions ... +Analytics.Client.Track("identified@example.com", "Identified Action"); +``` + +For more details about `alias`, including the **`alias` call payload**, check out our [Spec](/docs/connections/spec/alias/). + +--- + +## Development Settings + +You can use this initialization during development while testing the library. `SetAsync(false)` will make sure the library makes a request to our servers every time it's called. + +```csharp +Analytics.Initialize("YOUR_WRITE_KEY", new Config().SetAsync(false)); +``` + +Don't forget to set async back to `true` for production, so that you can advantage of asynchronous flushing on a different thread. + +## Options + +An `Options` object lets you: + +1. Set a [timestamp](#historical-import), [enable or disable destinations](#selecting-destinations) +2. [Send additional context](#context) +3. [Send an anoymousId](#anonymous-id) + +## Selecting Destinations + +The `alias`, `group`, `identify`, `page` and `track` calls can all be passed an object of `options` that lets you turn certain destinations on or off. By default all destinations are enabled. + +Here's an example `identify` call with the `options` object shown. + +```csharp +Analytics.Client.Identify("hj2kf92ds212", new Traits() { + { "email", "tom@example.com" }, + { "name", "Tom Smykowski" }, +}, new Options() + .SetIntegration("all", false) + .SetIntegration("Kissmetrics", true) +); +``` + +In this case, we're specifying that we want this identify to only go to Kissmetrics. `"all", false` says that no destination should be enabled unless otherwise specified. `{ "Kissmetrics", true }` turns on Kissmetrics, etc. + +destination flags are **case sensitive** and match [the destination's name in the docs](/docs/connections/destinations/) (i.e. "AdLearn Open Platform", "awe.sm", "MailChimp", etc.). + +**Note:** Available at the business level, filtering track calls can be done right from the Segment UI on your source schema page. We recommend using the UI if possible since it's a much simpler way of managing your filters and can be updated with no code changes on your side. + +## Historical Import + +You can import historical data by adding the `timestamp` argument to your `identify` and `track` calls. _Note: If you're tracking things that are happening right now, leave out the timestamp and our servers will timestamp the requests for you._ + +```csharp +Analytics.Client.Track("sadi89e2jd", "Logged Workout", new Properties() { + { "distance", "10 miles" }, + { "city", "Boston" }, +}, new Options() + .SetTimestamp(new DateTime(2010, 1, 18)) +); +``` + +## Context + +If you're running a web server, you might want to send context variables such as `userAgent` or `ip` with your `page` or `screen` calls. You can do so by setting the `Context` in the `Options` object. + +```csharp +Analytics.Client.Page("019mr8mf4r", "Login", new Properties() { + { "path", "/login" }, + { "title", "Initech Login" } +}, new Options() + .SetContext(new Context() { + { "app", "Education App 2" } + })); +``` + +Learn more on the [Context page](/docs/connections/spec/common/#context). + +## Anonymous ID + +By default, the Xamarin library requires all messages to have a `userId`. If you would like to use an `anonymousId`, you can pass it in with options. + +```csharp +Analytics.Client.Page(null, "Login", new Properties(), new Options() + .SetAnonymousId("some-id")); +``` + +## Nested Properties + +You can provide nested properties, like so: + +```csharp +Analytics.Client.Identify("hj2kf92ds212", new Traits() { + { "email", "tom@example.com" }, + { "name", "Tom Smykowski" }, + { "address", new Dict() { + { "street", "123 Fake Street" }, + { "city", "Boston" } + }} +}); +``` + +## Batching + +Our libraries are built to support high performance environments. That means it is safe to use Analytics.Xamarin on a web server that's serving hundreds of requests per second. + +By default (in async mode), this library will start a single seperate thread on initialization, and flush all messages on that thread. That means every method you call **does not** result in an HTTP request, but is queued in memory instead. Messages are flushed in batch in the background, which allows for much faster operation. + +### How do I turn batching off? + +Sometimes you might not want batching (eg. when debugging, or in short-lived programs). You can turn off batching by setting the `async` argument to `false`, and your requests will always be sent in a blocking manner. + +```csharp +Analytics.Initialize("YOUR_WRITE_KEY", new Config().SetAsync(false)); +``` + +### What happens if there are just too many messages? + +If the module detects that it can't flush faster than it's receiving messages, it'll simply stop accepting messages. This means your program will never crash because of a backing up analytics queue. The maximum size of the queue defaults to `10000`, and here's how you can change it: + +```csharp +Analytics.Initialize("YOUR_WRITE_KEY", new Config().SetMaxQueueSize(10000)); +``` + +### How do I flush right now?! + +You can also flush on demand. For example, at the end of your program, you'll want to flush to make sure there's nothing left in the queue. Just call the `Flush` method: + +```csharp +Analytics.Client.Flush(); +``` + +This method will block until all messages are flushed. + +### How do I dispose of the flushing thread at the end of my program? + +The Analytics client implements the `IDisposable` interface, and will turn off its flushing thread when you call `Dispose`. + +```csharp +Analytics.Client.Dispose(); +``` + +## Configuration + +If you hate defaults, than you'll love how configurable the Analytics.Xamarin is. Check out these gizmos: + +```csharp +Analytics.Initialize("YOUR_WRITE_KEY", new Config() + .SetAsync(true) + .SetTimeout(TimeSpan.FromSeconds(10)) + .SetMaxQueueSize(10000)); +``` + +<table class="DefinitionTable"> + <tr> + <td>`SetAsync` _boolean_</td> + <td>`true` to flush on a different thread, `false` to flush immediately on the same thread.</td> + </tr> + <tr> + <td>`SetTimeout` _TimeSpan_</td> + <td>The amount of time to wait before calling the HTTP request a timeout.</td> + </tr> + <tr> + <td>`SetMaxQueueSize` _int_</td> + <td>The maximum number of messages to allow into the queue before no new message are accepted.</td> + </tr> +</table> + +## Logging + +`Analytics.Xamarin` has detailed logging, which you can enable by attaching your own handler, like so: + +```csharp +using Segment; + +Segment.Logger.Handlers += Logging_Handler; + +void Logging_Handler(Level level, string message, Dict args) { + if (args != null) { + foreach (string key in args.Keys) { + message += String.Format(" {0}: {1},", "" + key, "" + args[key]); + } + } + Console.WriteLine(String.Format("[Analytics] [{0}] {1}", level, message)); +} +``` + +## Anonymizing IP + +We collect IP address for client-side (iOS, Android, Analytics.js and Xamarin) events automatically. + +If you don't want us to record your tracked users' IP in destinations and S3, you can set your event's `context.ip` field to `0.0.0.0` . Our server won't record the IP address of the client for libraries if the `context.ip` field is already set. \ No newline at end of file diff --git a/src/connections/sources/catalog/libraries/mobile/xamarin/index.md b/src/connections/sources/catalog/libraries/mobile/xamarin/index.md index 92137a2088..28bea0b8f1 100644 --- a/src/connections/sources/catalog/libraries/mobile/xamarin/index.md +++ b/src/connections/sources/catalog/libraries/mobile/xamarin/index.md @@ -4,7 +4,14 @@ sourceTitle: 'Xamarin' sourceCategory: 'Mobile' id: wcssVcPJrc support_type: community +custom_ranking: + heading: 0 + position: 99999 --- + +> warning "End-of-Support for Analytics.Xamarin in March 2026" +> End-of-support for the Analytics.Xamarin SDK is scheduled for March 2026. Segment's future development efforts concentrate on the new [Analytics-CSharp](/docs/connections/sources/catalog/libraries/server/csharp/) SDK. If you'd like to migrate to Analytics-CSharp, see the [migration guide](/docs/connections/sources/catalog/libraries/server/csharp/migration-guide/). + Segment's [Xamarin](http://xamarin.com/) Portable Class Library ([PCL](http://developer.xamarin.com/guides/cross-platform/application_fundamentals/pcl/)) is the best way to integrate analytics into your Xamarin application. It lets you record analytics data from your C#, F#, and .NET code, and supports `PCL Profile 4.0 - Profile136`, which targets the following platforms: - .NET Framework 4 or later @@ -20,9 +27,6 @@ The library issues requests that hit our servers, and then we route your data to **Note:** Since Xamarin requires Segment's library to be portable to different builds, Segment can only enable server-side destinations, as opposed to bundling select native SDKs like we do for iOS and Android. Look for the "Server" icon when selecting destinations. For tools for which we offer both bundled and server-side destinations, like Mixpanel, Amplitude, and Google Analytics, Segment's Xamarin library will only be able to use their server-side functionality. -> info "Analytics-CSharp (C#)" -> With [Analytics-CSharp](/docs/connections/sources/catalog/libraries/server/csharp/), you can add Segment analytics to your C# based app which includes Xamarin. If you'd like to migrate to use Analytics-CSharp, see the [Analytics-CSharp migration guide](/docs/connections/sources/catalog/libraries/server/csharp/migration-guide/). - ## Getting Started Clone `Analytics.Xamarin` from [GitHub](https://github.com/segmentio/Analytics.Xamarin)... diff --git a/src/connections/sources/catalog/libraries/server/csharp/index.md b/src/connections/sources/catalog/libraries/server/csharp/index.md index 493245910a..e7428dde74 100644 --- a/src/connections/sources/catalog/libraries/server/csharp/index.md +++ b/src/connections/sources/catalog/libraries/server/csharp/index.md @@ -2,15 +2,24 @@ title: Analytics-CSharp (C#) strat: csharp support_type: flagship +tags: + - C# + - C-sharp + - .NET + - NET + - Xamarin + - Unity + - ASP.NET id: redirect_from: - - '/connections/sources/catalog/libraries/mobile/unity' - - '/connections/sources/catalog/libraries/mobile/csharp/' + - '/connections/sources/catalog/libraries/mobile/unity/' + - '/connections/sources/catalog/libraries/mobile/csharp/' + - '/connections/sources/catalog/libraries/mobile/xamarin/' + - '/connections/sources/catalog/libraries/server/net/' --- With Analytics-CSharp, you can add Segment analytics to your C# based app which includes Unity, Xamarin, .NET. Analytics-CSharp helps you measure your users, product, and business. It unlocks insights into your app's funnel, core business metrics, and whether you have product-market fit. The Analytics-CSharp library is open-source [on GitHub](https://github.com/segmentio/analytics-csharp){:target="_blank"}. - ### Supported platforms These platforms support Analytics-CSharp: * .NET/.NET core/.NET framework @@ -23,7 +32,7 @@ These platforms support Analytics-CSharp: * Unity * iOS * Android - * PC, Mac, Linux + * PC, Mac, Linux ## Getting started @@ -59,19 +68,22 @@ To get started with the Analytics-CSharp library: > info "" > Segment's SDK is designed to be disposable, meaning Segment disposes of objects when the analytics instance is disposed. Segment avoids using singletons for configurations or HTTP clients to prevent memory management issues. If you want to use singletons, create your own HTTP client provider with a singleton HTTP client for better control and management. -| Option Name | Description | -|-----------------------------|---------------| - | `writeKey` *required* | This is your Segment write key. | -| `flushAt` | The default is set to `20`. <br> The count of events at which Segment flushes events. | -| `flushInterval` | The default is set to `30` (seconds). <br> The interval in seconds at which Segment flushes events. | -| `defaultSettings` | The default is set to `{}`. <br> The settings object used as fallback in case of network failure. | -| `autoAddSegmentDestination` | The default is set to `true`. <br> This automatically adds the Segment Destination plugin. You can set this to `false` if you want to manually add the Segment Destination plugin. | - | `apiHost` | The default is set to `api.segment.io/v1`. <br> This sets a default API Host to which Segment sends events. | -| `cdnHost` | The default is set to `cdn-settings.segment.com/v1`. <br> This sets a default cdnHost to which Segment fetches settings. | -| `analyticsErrorHandler` | The default is set to `null`. <br>This sets an error handler to handle errors happened in analytics. | - | `storageProvider` | The default is set to `DefaultStorageProvider`. <br>This sets how you want your data to be stored. `DefaultStorageProvider` is used by default which stores data to local storage. `InMemoryStorageProvider` is also provided in the library. You can also write your own storage solution by implementing `IStorageProvider` and `IStorage`. | -| `httpClientProvider` | The default is set to `DefaultHTTPClientProvider`. <br>This sets a http client provider for analytics use to do network activities. The default provider uses System.Net.Http for network activities. | -| `flushPolicies` | The default is set to `null`. <br>This sets custom flush policies to tell analytics when and how to flush. By default, it converts `flushAt` and `flushInterval` to `CountFlushPolicy` and `FrequencyFlushPolicy`. If a value is given, it overwrites `flushAt` and `flushInterval`. | + + +Option Name | Description +----------------------------|--------------- +`writeKey` *required* | This is your Segment write key. +`flushAt` | The default is set to `20`. <br/> The count of events at which Segment flushes events. +`flushInterval` | The default is set to `30` (seconds). <br/> The interval in seconds at which Segment flushes events. +`defaultSettings` | The default is set to `{}`. <br/> The settings object used as fallback in case of network failure. +`autoAddSegmentDestination` | The default is set to `true`. <br/> This automatically adds the Segment Destination plugin. You can set this to `false` if you want to manually add the Segment Destination plugin. +`apiHost` | The default is set to `api.segment.io/v1`. <br/> This sets a default API Host to which Segment sends events. +`cdnHost` | The default is set to `cdn-settings.segment.com/v1`. <br/> This sets a default cdnHost to which Segment fetches settings. +`analyticsErrorHandler` | The default is set to `null`. <br/>This sets an error handler to handle errors happened in analytics. +`storageProvider` | The default is set to `DefaultStorageProvider`. <br/>This sets how you want your data to be stored. `DefaultStorageProvider` is used by default which stores data to local storage. `InMemoryStorageProvider` is also provided in the library. You can also write your own storage solution by implementing `IStorageProvider` and `IStorage`. +`httpClientProvider` | The default is set to `DefaultHTTPClientProvider`. <br/>This sets a http client provider for analytics use to do network activities. The default provider uses System.Net.Http for network activities. +`flushPolicies` | The default is set to `null`. <br/>This sets custom flush policies to tell analytics when and how to flush. By default, it converts `flushAt` and `flushInterval` to `CountFlushPolicy` and `FrequencyFlushPolicy`. If a value is given, it overwrites `flushAt` and `flushInterval`. +`eventPipelineProvider` | The default is `EventPipelineProvider`. <br/>This sets a custom event pipeline to define how Analytics handles events. The default `EventPipelineProvider` processes events asynchronously. Use `SyncEventPipelineProvider` to make manual flush operations synchronous. ## Tracking Methods @@ -329,6 +341,21 @@ The `reset` method clears the SDK’s internal stores for the current user and g analytics.Reset() ``` +## Enrichment Closure +To modify the properties of an event, you can either write an enrichment plugin that applies changes to all events, or pass an enrichment closure to the analytics call to apply changes to a specific event. + +```c# + analytics.Track("MyEvent", properties, @event => + { + if (@event is TrackEvent trackEvent) + { + // update properties of this event + trackEvent.UserId = "foo"; + } + + return @event; + }); +``` ## Flush policies To more granularly control when events are uploaded you can use `FlushPolicies`. @@ -378,7 +405,7 @@ For example, you might want to disable flushes if you detect the user has no net ### Create your own flush policies -You can create a custom FlushPolicy special for your application needs by implementing the `IFlushPolicy` interface. You can also extend the `FlushPolicyBase` class that already creates and handles the `shouldFlush` value reset. +You can create a custom FlushPolicy special for your application needs by implementing the `IFlushPolicy` interface. You can also extend the `IFlushPolicy` class that already creates and handles the `shouldFlush` value reset. A `FlushPolicy` only needs to implement two of these methods: - `Schedule`: Executed when the flush policy is enabled and added to the client. This is a good place to start background operations, make async calls, configure things before execution diff --git a/src/connections/sources/catalog/libraries/server/csharp/migration-guide.md b/src/connections/sources/catalog/libraries/server/csharp/migration-guide.md index c0ec9d2887..31e68bc75b 100644 --- a/src/connections/sources/catalog/libraries/server/csharp/migration-guide.md +++ b/src/connections/sources/catalog/libraries/server/csharp/migration-guide.md @@ -49,7 +49,16 @@ You can update to Analytics-CSharp in 3 steps: using Segment.Analytics.Compat; ``` -3. *(Optional)* Update calls that resets the anonymous ID. +3. *(Required for .NET users)* Add `UserIdPlugin` to Analytics. + + Analytics-CSharp, by default, attaches an internal state `userId` to each event. The `UserIdPlugin`, instead, attaches the `userId` provided in analytics calls directly to the event. + + <br> After: + ```c# + analytics.Add(new UserIdPlugin()); + ``` + +4. *(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 call `Identify` and want to go back to anonymous, the new SDK provides a `Reset` function to achieve that. @@ -76,6 +85,104 @@ Change your development settings if you would like to make analytics run synchro <br> After: ```c# var configuration = new Configuration("YOUR WRITE KEY", - useSynchronizeDispatcher: true); + useSynchronizeDispatcher: true, + // provide a defaultSettings in case the SDK failed to fetch settings in test environment + defaultSettings: new Settings + { + Integrations = new JsonObject + { + ["Segment.io"] = new JsonObject + { + ["apiKey"] = "YOUR WRITE KEY" + } + } + } + ); var analytics = new Analytics(configuration); ``` + +## FAQs + +### Should I make Analytics a singleton or scoped in .NET? + +The SDK supports both, but be aware of the implications of choosing one over the other: + +| Feature | Singleton | Scoped | +|--|--|--| +| **Fetch Settings** | Settings are fetched only once at application startup. | Settings are fetched on every request. | +| **Flush** | Supports both async and sync flush. | Requires sync flush. Should flush per event or on page redirect/close to avoid data loss. | +| **Internal State** | The internal state (`userId`, `anonId`, etc.) is shared across sessions and cannot be used. (*This is an overhead we are working to minimize*.) | The internal state is safe to use since a new instance is created per request. | +| **UserId for Events** | Requires adding `UserIdPlugin` and calling analytics APIs with `userId` to associate the correct `userId` with events. | No need for `UserIdPlugin` or passing `userId` in API calls. Instead, call `analytics.Identify()` to update the internal state with the `userId`. Successive events are auto-stamped with that `userId`. | +| **Storage** | Supports both local storage and in-memory storage. | Requires in-memory storage. (*Support for local storage is in progress*.) | + + +In a nutshell, to register Analytics as singleton: + +```c# +var configuration = new Configuration( + writeKey: "YOUR_WRITE_KEY", + // Use in-memory storage to keep the SDK stateless. + // The default storage also works if you want to persist events. + storageProvider: new InMemoryStorageProvider(), + // Use a synchronous pipeline to make manual flush operations synchronized. + eventPipelineProvider: new SyncEventPipelineProvider() +); + +var analytics = new Analytics(configuration); + +// Add UserIdPlugin to associate events with the provided userId. +analytics.Add(new UserIdPlugin()); + +// Call analytics APIs with a userId. The UserIdPlugin will update the event with the provided userId. +analytics.Track("user123", "foo", properties); + +// This is a blocking call due to SyncEventPipelineProvider. +// Use the default EventPipelineProvider for asynchronous flush. +analytics.Flush(); + +// Register Analytics as a singleton. +``` + +To register Analytics as scoped: + +```c# +var configuration = new Configuration( + writeKey: "YOUR_WRITE_KEY", + // Requires in-memory storage. + storageProvider: new InMemoryStorageProvider(), + // Flush per event to prevent data loss in case of a page close. + // Alternatively, manually flush on page close. + flushAt: 1, + // Requires a synchronous flush. + eventPipelineProvider: new SyncEventPipelineProvider() +); + +var analytics = new Analytics(configuration); + +// Update the internal state with a userId. +analytics.Identify("user123"); + +// Subsequent events are auto-stamped with the userId from the internal state. +analytics.Track("foo", properties); + +// This is a blocking call due to SyncEventPipelineProvider. +analytics.Flush(); + +// Register Analytics as scoped. +``` + +### Which JSON library does this SDK use? + +The SDK supports `.netstandard 1.3` and `.netstandard 2.0` and automatically selects the internal JSON library based on the target framework: + +* In `.netstandard 1.3`, the SDK uses `Newtonsoft Json.NET` +* In `.netstandard 2.0`, the SDK uses `System.Text.Json` + +Be ware that both Analytics.NET and Analytics.Xamarin use `Newtonsoft Json.NET`. If you encounter issues where JSON dictionary values are turned into empty arrays, it is likely that: + +1. You are targeting `.netstandard 2.0`. +2. Your properties use`Newtonsoft Json.NET` objects or arrays. + +To resolve this, you can: +* Option 1: Target `.netstandard 1.3` +* Option 2: Upgrade your JSON library to `System.Text.Json` \ No newline at end of file diff --git a/src/connections/sources/catalog/libraries/server/net/analytics-net.md b/src/connections/sources/catalog/libraries/server/net/analytics-net.md new file mode 100644 index 0000000000..92d90c88c3 --- /dev/null +++ b/src/connections/sources/catalog/libraries/server/net/analytics-net.md @@ -0,0 +1,539 @@ +--- +title: Analytics for .NET +repo: analytics.NET +id: 8HWbgPTt3k +hidden: true +support_type: community +--- + +> warning "End-of-Support for Analytics.NET in March 2026" +> End-of-support (EoS) for the Analytics.NET SDK is scheduled for March 2026. Segment's future development efforts concentrate on the new [Analytics-CSharp](/docs/connections/sources/catalog/libraries/server/csharp/) SDK. If you'd like to migrate to Analytics-CSharp, see the [migration guide](/docs/connections/sources/catalog/libraries/server/csharp/migration-guide/). + +Segment's .NET library is the best way to integrate analytics into your .NET application or website. It lets you record analytics data from your ASP.NET, C#, F#, and Visual Basic code. The library issues requests that hit Segment's servers, and then Segment routes your data to any analytics service you enable on our destinations page. This library is open-source, so you can [check it out on GitHub](https://github.com/segmentio/Analytics.NET). + +All of Segment's server-side libraries are built for high-performance, so you can use them in your web server controller code. This library uses an internal queue to make Identify and Track calls non-blocking and fast. It also batches messages and flushes asynchronously to Segment's servers. + +## Getting Started + +### Client-side vs Server-side + +The best analytics installation combines both client-side and server-side tracking. A client-side analytics.js installation allows you to install A/B testing, heat mapping, session recording, and ad optimization tools. A server-side .NET installation allows you to accurately track events that aren't available client-side, such as payments. For best practices, [check out Segment's guide to client-side vs. server-side](/docs/guides/how-to-guides/collect-on-client-or-server/). + + +### Step 1: Add Analytics.js to your ASP.NET Master Page + +1. In your Segment workspace, click Catalog, and search for "Net". +2. Click the .Net tile, then click **Add Source**. +3. Give the new source a label (which you'll use to identify it later), and apply any labels such as `prod` or `test`. + +You will then be presented with an [Analytics.js snippet](/docs/connections/sources/catalog/libraries/website/javascript/quickstart/#step-2-copy-the-segment-snippet). + +Copy the snippet directly into your ASP.NET [Site.master](https://github.com/segmentio/asp.net-example/blob/master/Site.master#L18-L21). + +That snippet will load `analytics.js` onto the page _asynchronously_, so it won't affect your page load speed. + +As soon as that snippet is running on your site, you can start turning on any destinations on your Segment destinations page. In fact, if you reload, you can start seeing Page calls in the [source debugger](/docs/connections/sources/debugger/). + +For more in depth `analytics.js` information, check out Segment's [analytics.js docs](/docs/connections/sources/catalog/libraries/website/javascript/). + +Lots of analytics and marketing tools want to know more information about your users, and what they're doing on your app. In the next section, Segment installs the .NET library and start sending an event every time a new user registers on your site. + +### Step 2: Install Segment's .NET Library + +Your website will use Segment's .NET library to Identify and Track users. You can use [NuGet](http://docs.nuget.org/docs/start-here/using-the-package-manager-console) to install the library. + +```bash +Install-Package Analytics -Version <version> +``` + +**Note:** the Analytics package has a dependency on [Newton.JSON](https://www.newtonsoft.com/json). + +You can also accomplish the same thing in the Visual Studio `Tools` menu, select `Library Package Manager` and then click `Package Manager Console`. + +Now the .NET library needs to know which Segment project you want to send data to. You can initialize the library with your Segment source's `writeKey` in the [Global.asax file](https://github.com/segmentio/asp.net-example/blob/master/Global.asax#L14). Then you can use the `Analytics` singleton in any controller you want: + +```csharp +<%@ Application Language="C#" %> +<%@ Import Namespace="ASP.NET_Example" %> +<%@ Import Namespace="System.Web.Optimization" %> +<%@ Import Namespace="System.Web.Routing" %> +<%@ Import Namespace="Segment" %> + +<script runat="server"> + + void Application_Start(object sender, EventArgs e) + { + RouteConfig.RegisterRoutes(RouteTable.Routes); + BundleConfig.RegisterBundles(BundleTable.Bundles); + // this is your project's write key + Segment.Analytics.Initialize("x24b2rmtvv"); + } + +</script> +``` + +```csharp +using Segment; + +// initialize the project #{source.owner.login}/#{source.slug}... +Analytics.Initialize("YOUR_WRITE_KEY"); +``` + +You only need to initialize once at the start of your program. You can then keep using the `Analytics` singleton anywhere in your code. + +The default initialization settings are production-ready and queue messages on another thread before sending any requests. In development you might want to use [development settings](/docs/connections/sources/catalog/libraries/server/net/#development-settings). + +### Regional configuration +{% include content/regional-config.md %} + +## Identify + +> success "" +> For any of the different methods described on this page, you can replace the properties and traits in the code samples with variables that represent the data collected. + +If you're not familiar with the Segment Specs, take a look to understand what the [Identify](/docs/connections/spec/identify/) method does. + +The Identify call has the following fields: + +<table class="api-table"> + <tr> + <td>`userId` _String_</td> + <td>The ID for this user in your database.</td> + </tr> + <tr> + <td>`Traits` _Traits, optional_</td> + <td>A dictionary of traits you know about the user. Things like: <code>email</code>, <code>name</code> or <code>friends</code>.</td> + </tr> + <tr> + <td>`options` _Options, optional_</td> + <td>A custom object which allows you to set a timestamp, an anonymous cookie id, or enable specific destinations.</td> + </tr> +</table> + +An example call would look like: + +```csharp +Analytics.Client.Identify("019mr8mf4r", new Traits() { + { "name", "#{ user.name }" }, + { "email", "#{ user.email }" }, + { "friends", 29 } +}); +``` + +## Track + +If you're not familiar with the Segment Spec, take a look to understand what the [Track](/docs/connections/spec/track/) method does. + +The Track call has the following fields: + +<table class="api-table"> + <tr> + <td>`userId` _String_</td> + <td>The ID for this user in your database.</td> + </tr> + <tr> + <td>`event` _String_</td> + <td>The name of the event you're tracking. Segment recommends human-readable names like <strong>Song Played</strong> or <strong>Status Updated</strong>.</td> + </tr> + <tr> + <td>`properties` _Properties, optional_</td> + <td>A dictionary of properties for the event. If the event was <strong>Product Added</strong> to cart, it might have properties like <code>price</code> or <code>product</code>.</td> + </tr> + <tr> + <td>`options` _Options, optional_</td> + <td>A custom object which allows you to set a timestamp, an anonymous cookie id, or enable specific destinations.</td> + </tr> +</table> + +An example call would look like: + +```csharp +Analytics.Client.Track("019mr8mf4r", "Item Purchased", new Properties() { + { "revenue", 39.95 }, + { "shipping", "2-day" } +}); +``` + +## Page + +If you're not familiar with the Segment Specs, take a look to understand what the [Page](/docs/connections/spec/page/) method does. + +The Page call has the following fields: + +<table class="api-table"> + <tr> + <td>`userId` _String_</td> + <td>The ID for this user in your database.</td> + </tr> + <tr> + <td>`name` _String_</td> + <td>The webpage name you're tracking. Segment recommends human-readable names like <strong>Login</strong> or <strong>Register</strong>.</td> + </tr> + <tr> + <td>`category` _String_</td> + <td>The webpage category. If you're making a news app, the category could be <strong>Sports</strong>.</td> + </tr> + <tr> + <td>`properties` _Properties, optional_</td> + <td>A dictionary of properties for the webpage visit. If the event was <strong>Login</strong>, it might have properties like <code>path</code> or <code>title</code>.</td> + </tr> + <tr> + <td>`options` _Options, optional_</td> + <td>A custom object which allows you to set a timestamp, an anonymous cookie id, or enable specific destinations.</td> + </tr> +</table> + +Example Page call: + +```csharp +Analytics.Client.Page("019mr8mf4r", "Login", new Properties() { + { "path", "/login" }, + { "title", "Initech Login" } +}); +``` + +## Screen + +If you're not familiar with the Segment Specs, take a look to understand what the [Screen](/docs/connections/spec/screen/) method does. + +The Screen call has the following fields: + +<table class="api-table"> + <tr> + <td>`userId` _String_</td> + <td>The ID for this user in your database.</td> + </tr> + <tr> + <td>`name` _String_</td> + <td>The screen name you're tracking. Segment recommends human-readable names like <strong>Login</strong> or <strong>Register</strong>.</td> + </tr> + <tr> + <td>`category` _String_</td> + <td>The screen category. If you're making a news app, the category could be <strong>Sports</strong>.</td> + </tr> + <tr> + <td>`properties` _Properties, optional_</td> + <td>A dictionary of properties for the screen view. If the screen is <strong>Restaurant Reviews</strong>, it might have properties like <code>reviewCount</code> or <code>restaurantName</code>.</td> + </tr> + <tr> + <td>`options` _Options, optional_</td> + <td>A custom object which allows you to set a timestamp, an anonymous cookie id, or enable specific destinations.</td> + </tr> +</table> + +Example Screen call: + +```csharp +Analytics.Client.Screen("019mr8mf4r", "Register", new Properties() { + { "type", "facebook" } +}); +``` + +## Group + +If you're not familiar with the Segment Specs, take a look to understand what the [Group](/docs/connections/spec/group/) method does. + +The Group call has the following fields: + +<table class="api-table"> + <tr> + <td>`userId` _String_</td> + <td>The ID for this user in your database.</td> + </tr> + <tr> + <td>`groupId` _String_</td> + <td>The ID for this group in your database.</td> + </tr> + <tr> + <td>`traits` _Traits, optional_</td> + <td>A dictionary of traits you know about the group. Things like: <code>ma,e</code> or <code>website</code>.</td> + </tr> + <tr> + <td>`options` _Options, optional_</td> + <td>A custom object which allows you to set a timestamp, an anonymous cookie id, or enable specific destinations.</td> + </tr> +</table> + +Example Group call: + +```csharp +Analytics.Client.Group("userId", "groupId", new Traits() { + { "name", "Initech, Inc." }, + { "website", "http://www.example.com" } +}); +``` + +## Alias + +If you're not familiar with the Segment Specs, take a look to understand what the [Alias](/docs/connections/spec/alias/) method does. + +The Alias call has the following fields: + +<table class="api-table"> + <tr> + <td>`previousId` _String_</td> + <td>The previousId for this user.</td> + </tr> + <tr> + <td>`userId` _String_</td> + <td>The ID for this user in your database.</td> + </tr> +</table> + +Example Alias call: + +```csharp +Analytics.Client.Alias("previousId", "userId") +``` + +Here's a full example of how you might use the Alias call: + +```csharp +// the anonymous user does actions ... +Analytics.Client.Track("anonymous_user", "Anonymous Event"); +// the anonymous user signs up and is aliased +Analytics.Client.Alias("anonymous_user", "identified@example.com"); +// the identified user is identified +Analytics.Client.Identify("identified@example.com", new Traits() { plan: "Free" }); +// the identified user does actions ... +Analytics.Client.Track("identified@example.com", "Identified Action"); +``` + +--- + +## Development Settings + +You can use this initialization during development while testing the library. `SetAsync(false)` will make sure the library makes a request to Segment's servers every time it's called. + +```csharp +Analytics.Initialize("YOUR_WRITE_KEY", new Config().SetAsync(false)); +``` + +Don't forget to set async back to `true` for production, so that you can advantage of asynchronous flushing on a different thread. + + +## Historical Import + +You can import historical data by adding the `timestamp` argument to any of your method calls. This can be helpful if you've just switched to Segment. + +Historical imports can only be done into destinations that can accept historical timestamped data. Most analytics tools like Mixpanel, Amplitude, Kissmetrics, etc. can handle that type of data just fine. One common destination that does not accept historical data is Google Analytics since their API cannot accept historical data. + +**Note:** If you're tracking things that are happening right now, leave out the `timestamp` and Segment's servers will timestamp the requests for you. + +```csharp +Analytics.Client.Track("sadi89e2jd", "Workout Logged", new Properties() { + { "distance", "10 miles" }, + { "city", "Boston" }, +}, new Options() + .SetTimestamp(new DateTime(2010, 1, 18)) +); +``` + +## Selecting Destinations + +The Alias, Group, Identify, Page, and Track calls can all be passed an object of `options` that lets you turn certain destinations on or off. By default all destinations are enabled. + +You can specify which analytics destinations you want each action to go to. + +```csharp +Analytics.Client.Identify("hj2kf92ds212", new Traits() { + { "email", "tom@example.com" }, + { "name", "Tom Smykowski" }, +}, new Options() + .SetIntegration("all", false) + .SetIntegration("Kissmetrics", true) +); +``` + +In this case, you're specifying that you want this identify to only go to Kissmetrics. `"all", false` says that no destination should be enabled unless otherwise specified, and `{ "Kissmetrics", true }` turns on Kissmetrics. + +Destination flags are **case sensitive** and match [the destination's name in the docs](/docs/connections/destinations/) (for example, "AdLearn Open Platform", "awe.sm", or "MailChimp"). + +**Note:** + +- Business Tier users can filter Track calls right from the Segment UI on your source schema page. Segment recommends using the UI if possible since it's a much simpler way of managing your filters and can be updated with no code changes on your side. + +- If you are on a grandfathered plan, events sent server-side that are filtered through the Segment dashboard still count towards your API usage. + +## Context + +If you're running a web server, you might want to send [context variables](https://segment.com/docs/connections/spec/common/#context) such as `userAgent` or `ip` with your `page` or `screen` calls. You can do so by setting the `Context` in the `Options` object. + +```csharp +Analytics.Client.Page("019mr8mf4r", "Login", new Properties() { + { "path", "/login" }, + { "title", "Initech Login" } +}, new Options() + .SetContext (new Context () { + { "userAgent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"}, + { "ip", "12.212.12.49" }, + { "language", "en-us" }, + { "Google Analytics", new Dict() { + { "clientId", User.ClientId } + } + } +})); +``` + +## Anonymous ID + +All libraries require all messages to have either a `userId` or `anonymousId`. If you would like to use an `anonymousId`, which you should for anonymous users, you can pass it in with options. + +```csharp +Analytics.Client.Page(null, "Login", new Properties(), new Options() + .SetAnonymousId("some-id")); +``` + +## Nested Properties + +You can provide nested properties, like so: + +```csharp +Analytics.Client.Identify("hj2kf92ds212", new Traits() { + { "email", "tom@example.com" }, + { "name", "Tom Smykowski" }, + { "address", new Dict() { + { "street", "123 Fake Street" }, + { "city", "Boston" } + }} +}); +``` + + +## Batching + +Segment's libraries are built to support high performance environments. That means it is safe to use Analytics.NET on a web server that's serving hundreds of requests per second. + +By default (in async mode), this library starts a single separate thread on initialization, and flushes all messages on that thread. That means every method you call **does not** result in an HTTP request, but is queued in memory instead. Messages are flushed in batch in the background, which allows for much faster operation. + +There is a maximum of `500KB` per batch request and `32KB` per call. + +{% include content/tracking-api-limit.md %} + + + +### How do I turn batching off? + +Sometimes you might not want batching (for example, when debugging, or in short-lived programs). You can turn off batching by setting the `async` argument to `false`, and your requests will always be sent in a blocking manner. + +```csharp +Analytics.Initialize("YOUR_WRITE_KEY", new Config().SetAsync(false)); +``` + + +### What happens if there are just too many messages? + +If the module detects that it can't flush faster than it's receiving messages, it'll simply stop accepting messages. This means your program will never crash because of a backing up analytics queue. The maximum size of the queue defaults to `10000`, and here's how you can change it: + +```csharp +Analytics.Initialize("YOUR_WRITE_KEY", new Config().SetMaxQueueSize(10000)); +``` + + +### How do I flush right now?! + +You can also flush on demand. For example, at the end of your program, you'll want to flush to make sure there's nothing left in the queue. Just call the `Flush` method: + +```csharp +Analytics.Client.Flush(); +``` + +This method will block until all messages are flushed. + + +### How do I dispose of the flushing thread at the end of my program? + +The Analytics client implements the `IDisposable` interface, and will turn off its flushing thread when you call `Dispose`. + +```csharp +Analytics.Client.Dispose(); +``` + + +## Configuration + +If you hate defaults, than you'll love how configurable the Analytics.NET is. Check out these gizmos: + +```csharp +Analytics.Initialize("YOUR_WRITE_KEY", new Config() + .SetAsync(true) + .SetTimeout(TimeSpan.FromSeconds(10)) + .SetHost("https://events.eu1.segmentapis.com") + .SetMaxQueueSize(10000));)); +``` + +<table class="DefinitionTable"> + <tr> + <td>`async` _boolean_</td> + <td><code>true</code> to flush on a different thread, <code>false</code> to flush immediately on the same thread.</td> + </tr> + <tr> + <td>`timeout` _TimeSpan_</td> + <td>The amount of time to wait before calling the HTTP request a timeout.</td> + </tr> + <tr> + <td>`host` _string_</td> + <td>The API host server address - can be set with the EU endpoint "https://events.eu1.segmentapis.com" instead of default server "https://api.segment.io"</td> + </tr> + <tr> + <td>`maxQueueSize` _int_</td> + <td>The maximum number of messages to allow into the queue before no new message are accepted.</td> + </tr> +</table> + + +## Multiple Clients + +Different parts of your app may require different Segment. In that case, you can initialize different `Analytics.Client` instances instead of using the singleton. + +```csharp +Client client = new Client("YOUR_WRITE_KEY", new Config() + .SetAsync(false) + .SetTimeout(TimeSpan.FromSeconds(10)) + .SetMaxQueueSize(10000)); + +client.Track(...); +``` + + +## Troubleshooting + +{% include content/troubleshooting-intro.md %} +{% include content/troubleshooting-server-debugger.md %} +{% include content/server-side-troubleshooting.md %} + +### Logging + +`Analytics.NET` has detailed logging, which you can enable by attaching your own handler, like so: + +```csharp +using Segment; + +Logger.Handlers += LoggingHandler; + +static void LoggingHandler(Logger.Level level, string message, IDictionary<string, object> args) +{ + if (args != null) + { + foreach (string key in args.Keys) + { + message += String.Format(" {0}: {1},", "" + key, "" + args[key]); + } + } + Console.WriteLine(String.Format("[Analytics] [{0}] {1}", level, message)); +} +``` + +Note: the logger requires a minimum version of .NET Core 2.1. + +### Json.NET + +`Analytics.NET` uses [Json.NET](http://json.codeplex.com/) to serialize JSON payloads. If you have an older version of `Json.NET` in your build path, `Analytics.NET` could create incomplete JSON payloads, which can cause strange API responses. If you're seeing issues, try updating `Json.NET`. + + +### Mono + +`Analytics.NET` has been tested and works in Mono. + +### .NET Core +`Analytics.NET` has been tested and works with .NET Core 3.1 and 3.4.2 beta. diff --git a/src/connections/sources/catalog/libraries/server/net/index.md b/src/connections/sources/catalog/libraries/server/net/index.md index bead3e9e5a..53a6d5eee3 100644 --- a/src/connections/sources/catalog/libraries/server/net/index.md +++ b/src/connections/sources/catalog/libraries/server/net/index.md @@ -3,17 +3,18 @@ title: Analytics for .NET repo: analytics.NET id: 8HWbgPTt3k support_type: community -tags: - - C# - - C-sharp +custom_ranking: + heading: 0 + position: 99999 --- + +> warning "End-of-Support for Analytics.NET in March 2026" +> End-of-support (EoS) for the Analytics.NET SDK is scheduled for March 2026. Segment's future development efforts concentrate on the new [Analytics-CSharp](/docs/connections/sources/catalog/libraries/server/csharp/) SDK. If you'd like to migrate to Analytics-CSharp, see the [migration guide](/docs/connections/sources/catalog/libraries/server/csharp/migration-guide/). + Segment's .NET library is the best way to integrate analytics into your .NET application or website. It lets you record analytics data from your ASP.NET, C#, F#, and Visual Basic code. The library issues requests that hit Segment's servers, and then Segment routes your data to any analytics service you enable on our destinations page. This library is open-source, so you can [check it out on GitHub](https://github.com/segmentio/Analytics.NET). All of Segment's server-side libraries are built for high-performance, so you can use them in your web server controller code. This library uses an internal queue to make Identify and Track calls non-blocking and fast. It also batches messages and flushes asynchronously to Segment's servers. -> info "Analytics-CSharp (C#)" -> With [Analytics-CSharp](/docs/connections/sources/catalog/libraries/server/csharp/), you can add Segment analytics to your C# based app which includes .NET. If you'd like to migrate to use Analytics-CSharp, see the [Analytics-CSharp migration guide](/docs/connections/sources/catalog/libraries/server/csharp/migration-guide/). - ## Getting Started ### Client-side vs Server-side diff --git a/src/connections/sources/catalog/libraries/server/net/quickstart.md b/src/connections/sources/catalog/libraries/server/net/quickstart.md index b90cc059c2..937f737bb9 100644 --- a/src/connections/sources/catalog/libraries/server/net/quickstart.md +++ b/src/connections/sources/catalog/libraries/server/net/quickstart.md @@ -1,7 +1,13 @@ --- title: 'Quickstart: ASP.NET' +custom_ranking: + heading: 0 + position: 99999 --- +> warning "End-of-Support for Analytics.NET in March 2026" +> End-of-support for the Analytics.NET SDK is scheduled for March 2026. Segment's future development efforts concentrate on the new [Analytics-CSharp](/docs/connections/sources/catalog/libraries/server/csharp/) SDK. If you'd like to migrate to Analytics-CSharp, see the [migration guide](/docs/connections/sources/catalog/libraries/server/csharp/migration-guide/). + This tutorial will help you start sending analytics data from your ASP.NET app to Segment and any of our destinations, using our .NET and Analytics.js library. As soon as you're set up you'll be able to turn on analytics tools, ad conversion pixels, email tools and lots of other destinations with the flip of a switch! If you want to dive deeper at any point, check out the [.NET library reference](/docs/connections/sources/catalog/libraries/server/net). diff --git a/src/connections/sources/index.md b/src/connections/sources/index.md index 9e461d4da3..e49f710b92 100644 --- a/src/connections/sources/index.md +++ b/src/connections/sources/index.md @@ -123,13 +123,11 @@ Each of these tabs displays an event count, which is the total number of events Segment's Mobile SDKs are the best way to simplify your iOS, Android, and Xamarin app tracking. Try them over server-side sources as the default installation for any mobile app. - [AMP](/docs/connections/sources/catalog/libraries/mobile/amp) -- [Android](/docs/connections/sources/catalog/libraries/mobile/android) -- [Android Wear](/docs/connections/sources/catalog/libraries/mobile/android/wear) -- [iOS](/docs/connections/sources/catalog/libraries/mobile/ios) -- [Kotlin](/docs/connections/sources/catalog/libraries/mobile/kotlin-android/) +- [Android (Kotlin)](/docs/connections/sources/catalog/libraries/mobile/kotlin-android/) - [React Native](/docs/connections/sources/catalog/libraries/mobile/react-native) -- [Swift](/docs/connections/sources/catalog/libraries/mobile/swift/) -- [Xamarin](/docs/connections/sources/catalog/libraries/mobile/xamarin) +- [iOS (Swift)](/docs/connections/sources/catalog/libraries/mobile/swift/) +- [Xamarin](/docs/connections/sources/catalog/libraries/server/csharp) +- [Unity](/docs/connections/sources/catalog/libraries/server/csharp/) > info "Analytics-Flutter library" > The Analytics-Flutter library is currently only available in pilot phase and is governed by Segment's [First Access and Beta Preview Terms](https://www.twilio.com/en-us/legal/tos){:target="_blank"}. If you'd like to try out this library, access the [Analytics-Flutter GitHub repository](https://github.com/segmentio/analytics_flutter){:target="_blank"}. @@ -146,7 +144,7 @@ Segment's server-side sources let you send analytics data directly from your ser - [PHP](/docs/connections/sources/catalog/libraries/server/php/) - [Python](/docs/connections/sources/catalog/libraries/server/python/) - [Ruby](/docs/connections/sources/catalog/libraries/server/ruby/) -- [.NET](/docs/connections/sources/catalog/libraries/server/net/) +- [.NET](/docs/connections/sources/catalog/libraries/server/csharp/) > info "Cloud-mode tracking" > Server-side data management is when tag sends data to the Segment servers, which then passes that data to the destination system.