### Get Workspaces Source: https://github.com/segmentio/segment-docs/blob/develop/src/partners/enable-with-segment.md This example shows how to retrieve a list of workspaces accessible with the provided install token. ```APIDOC ## GET /v1beta/workspaces ### Description Retrieves a list of all workspaces that the authenticated app has access to. ### Method GET ### Endpoint https://platform.segmentapis.com/v1beta/workspaces ### Headers - **Authorization** (string) - Required - Bearer token obtained via OAuth. ### Response #### Success Response (200) - **name** (string) - The resource name of the workspace. - **display_name** (string) - The user-friendly name of the workspace. - **id** (string) - The unique identifier for the workspace. - **create_time** (string) - The timestamp when the workspace was created. ### Response Example ```json { "name": "workspaces/userworkspace", "display_name": "Business", "id": "bb296fce9c", "create_time": "2012-08-12T15:40:04.406Z" } ``` ``` -------------------------------- ### Get Destination Source: https://github.com/segmentio/segment-docs/blob/develop/src/partners/enable-with-segment.md This example shows how to retrieve a specific destination configuration for a user's workspace and source using an install token. ```APIDOC ## GET /v1beta/workspaces/{workspaceId}/sources/{sourceId}/destinations/{destinationName} ### Description Retrieves the configuration for a specific destination associated with a workspace and source. ### Method GET ### Endpoint https://platform.segmentapis.com/v1beta/workspaces/{workspaceId}/sources/{sourceId}/destinations/{destinationName} ### Parameters #### Path Parameters - **workspaceId** (string) - Required - The ID of the workspace. - **sourceId** (string) - Required - The ID of the source. - **destinationName** (string) - Required - The name of the destination (e.g., 'clearbrain'). #### Headers - **Authorization** (string) - Required - Bearer token obtained via OAuth. ### Response #### Success Response (200) - **name** (string) - The resource name of the destination. - **parent** (string) - The parent resource path (e.g., workspace/source). - **display_name** (string) - The user-friendly name of the destination. - **enabled** (boolean) - Indicates if the destination is enabled. - **connection_mode** (string) - The connection mode for the destination. - **config** (array) - An array of configuration objects for the destination. ### Response Example ```json { "name": "workspaces/business/sources/js/destinations/clearbrain", "parent": "workspaces/business/sources/js", "display_name": "ClearBrain", "enabled": true, "connection_mode": "UNSPECIFIED", "config": [ { "name": "workspaces/business/sources/js/destinations/clearbrain/config/apiKey", "display_name": "API Key", "value": "abcd1234", "type": "string" } ], ... } ``` ``` -------------------------------- ### Install the Go Analytics Library Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/sources/catalog/libraries/server/go/quickstart.md Install the Segment Go library using go get. This command fetches and installs the specified package. ```bash go get github.com/segmentio/analytics-go/v3 ``` -------------------------------- ### Refresh Install Token Source: https://github.com/segmentio/segment-docs/blob/develop/src/partners/enable-with-segment.md This example demonstrates how to refresh an install token using your client ID and client secret. ```APIDOC ## POST /v1beta/{installName}/token ### Description Refreshes an install token to obtain a new access token. ### Method POST ### Endpoint https://platform.segmentapis.com/v1beta/{installName}/token ### Parameters #### Path Parameters - **installName** (string) - Required - The name of the installation. #### Headers - **Authorization** (string) - Required - Basic authentication using your Client ID and Client Secret (e.g., Basic base64Encode(CLIENT_ID:CLIENT_SECRET)). ### Response #### Success Response (200) - **access_token** (string) - The new access token. - **token_type** (string) - The type of token (e.g., 'bearer'). - **expires_in** (integer) - The time in seconds until the token expires. - **scope** (string) - The scope associated with the token. - **app_name** (string) - The name of the application. - **install_name** (string) - The name of the installation. - **workspace_names** (array) - A list of workspace names associated with the token. ### Response Example ```json { "access_token": "4d9ee1b5-b752-4f7f-86d9-5680df6f8ce8", "token_type": "bearer", "expires_in": 3600, "scope": "workspace", "app_name": "apps/myapp", "install_name": "install/10", "workspace_names": ["workspaces/userworkspace"] } ``` ``` -------------------------------- ### Run the partnerapp Example Source: https://github.com/segmentio/segment-docs/blob/develop/src/partners/enable-with-segment.md Execute the `index.js` script to start the partnerapp server. Navigate to `http://localhost:8888/auth/segment` in your browser to initiate the OAuth flow. ```sh node index.js ``` -------------------------------- ### Initialize Typewriter Wizard Source: https://github.com/segmentio/segment-docs/blob/develop/src/protocols/apis-and-extensions/typewriter.md Run this command to start the Typewriter quickstart wizard and regenerate configuration files. ```bash npx typewriter init ``` -------------------------------- ### Run Local Development Server Source: https://github.com/segmentio/segment-docs/blob/develop/devguide.md Use this command to start the local development server. Ensure Ruby and Node are installed. ```bash make dev ``` -------------------------------- ### Clone and Configure Destination Repository Source: https://github.com/segmentio/segment-docs/blob/develop/src/partners/destinations/build.md Clone the repository, log in to NPM and Yarn, install dependencies, and build the project. Run unit tests to verify your environment setup. ```sh # Clone the repo locally git clone cd action-destinations npm login yarn login # Requires node 18.17.1, optionally: nvm use 18.17.1 yarn --ignore-optional yarn install yarn build # Run unit tests to ensure things are working! For partners who don't have access to internal packages, you can run: yarn test-partners # For segment employees, you can run: yarn test # to reset all caches and rebuild again yarn clean-build ``` -------------------------------- ### Track an Application Installed Event with URL Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/destinations/catalog/button/index.md Track mobile app installs using Segment's 'Application Installed' event. Capture the referring URL to understand install sources. This example includes detailed context information. ```javascript analytics.track('Application Installed' { someProperty: true }, { userId: '1234567890', properties: { url: 'https://brand-homepage.com?btn_ref=srctok-XXX' }, context { app: { version: '4.15.0' }, device: { adTrackingEnabled: false, advertisingId: 'XXXXXXXX-YYYY-ZZZZ-1111-222222222222' }, ip: '127.0.0.1', locale: 'en-US', os: { name: 'iOS', version: '14.2' } } ... }) ``` -------------------------------- ### Install Dependencies with npm Source: https://github.com/segmentio/segment-docs/blob/develop/README.md Use this command to install project dependencies. Ensure Node.js and npm are installed. ```bash npm i ``` -------------------------------- ### Install JavaNetTrackingPlugin Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/auto-instrumentation/kotlin-setup.md Install the JavaNetTrackingPlugin where you initialize analytics. ```kotlin JavaNetTrackingPlugin.install() ``` -------------------------------- ### CSS Styling Example Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/sources/index.md CSS to style an HTML element with the ID 'example'. ```css #example { color: red; } ``` -------------------------------- ### Initialize Typewriter Client Source: https://github.com/segmentio/segment-docs/blob/develop/src/protocols/apis-and-extensions/typewriter-v7.md Use this command to initiate the Typewriter quickstart wizard, which generates a `typewriter.yml` configuration file and your first Typewriter client. ```sh npx typewriter@7 init ``` -------------------------------- ### Setup Analytics Instance Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/sources/catalog/libraries/mobile/react-native/classic.md Configure the `Analytics` instance using the `setup` method with your Segment source's Write Key. ```javascript analytics.setup('YOUR_WRITE_KEY', { // ... }) ``` -------------------------------- ### Install Branch Plugin Dependencies Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/sources/catalog/libraries/mobile/react-native/destination-plugins/branch-react-native.md Install the necessary npm packages for the Branch plugin and the react-native-branch SDK. Run `pod install` afterwards to complete the setup. ```bash npm install --save @segment/analytics-react-native-plugin-branch react-native-branch ``` ```bash yarn add @segment/analytics-react-native-plugin-branch react-native-branch ``` -------------------------------- ### Get Profile Traits by User ID Example Source: https://github.com/segmentio/segment-docs/blob/develop/src/unify/profile-api.md Example of retrieving a profile's traits using a `user_id`. ```http GET /v1/spaces/lg8283283/collections/users/profiles/user_id:u1234/traits ``` -------------------------------- ### Get Profile Traits by External ID Example Source: https://github.com/segmentio/segment-docs/blob/develop/src/unify/profile-api.md Example of retrieving a profile's traits using an `anonymous_id`. ```http GET /v1/spaces/lg8283283/collections/users/profiles/anonymous_id:a1234/traits ``` -------------------------------- ### Screen Call Example Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/sources/catalog/libraries/server/python/index.md This example demonstrates how to use the `screen` method to track a user viewing the settings page, including properties like the previous screen. ```APIDOC ## Screen The `screen` method allows you to record screen views on your mobile app, along with optional extra information about the screen being viewed. ### Method Signature ```python analytics.screen(user_id, name, category=None, properties=None, context=None, timestamp=None, anonymous_id=None, integrations=None) ``` ### Parameters * **user_id** (string or number) - Required - The ID for the user that is a part of the group. * **name** (string, optional) - The name of the page, for example **Signup** or **Home**. * **category** (string, optional) - The category of the page. Useful for things like ecommerce where many pages often live under a larger category. * **properties** (dict, optional) - A dictionary of properties of the screen. * **context** (dict, optional) - A dict containing any context about the request. To see the full reference of supported keys, check them out in the [context reference](/docs/connections/spec/common/#context). * **timestamp** (datetime, optional) - A `datetime` object representing when the Screen took place. This is most useful if you're importing historical data. If the Screen just happened, leave it blank to use the server's time. * **anonymous_id** (string or int, optional) - An anonymous session ID for this user. * **integrations** (dict, optional) - A dictionary of destinations to enable or disable. ### Request Example ```python analytics.screen('user_id', 'Settings', 'Brightness', { 'from': 'Home Screen' }) ``` ### Further Information Find details on the **Screen method payload** in the [Segment Spec](/docs/connections/spec/screen/). ``` -------------------------------- ### Start Session Response Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/sources/catalog/libraries/server/object-bulk-api/index.md Example response from the 'Start' endpoint, containing the 'sync_id' which is a unique identifier for the current upload session. ```json { "sync_id":"hjWdsur28j49LCQ" } ``` -------------------------------- ### Typewriter Initialization Wizard Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/sources/catalog/libraries/mobile/apple/swift-typewriter.md Run the quickstart wizard to initialize your Typewriter configuration. It prompts for an API token and stores it in ~/.typewriter. ```bash $ npx typewriter init ``` -------------------------------- ### Add Plugin Example Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/sources/catalog/libraries/mobile/kotlin-android/implementation.md Demonstrates how to create a simple plugin and add it to the analytics timeline using the `add` method. ```kotlin val plugin = object: Plugin { override val type = Plugin.Type.Enrichment override val name = "SomePlugin" override var lateinit analytics: Analytics } analytics.add(plugin) ``` -------------------------------- ### Install @segment/analytics-next for TypeScript Users Source: https://github.com/segmentio/segment-docs/blob/develop/src/protocols/apis-and-extensions/typewriter.md If you are using the snippet method with TypeScript, install the @segment/analytics-next npm library as a dev dependency to get the TypeScript types. ```sh npm install --save-dev @segment/analytics-next ``` -------------------------------- ### Get Profile Traits Request with Authentication Source: https://github.com/segmentio/segment-docs/blob/develop/src/unify/profile-api.md Example of a curl request to get profile traits, including basic authentication using a Segment Access Secret. ```bash curl https://profiles.segment.com/v1/spaces//collections/users/profiles//traits -X GET -u $SEGMENT_ACCESS_SECRET: ``` -------------------------------- ### Set Up SDK in Application Delegate Source: https://github.com/segmentio/segment-docs/blob/develop/src/getting-started/02-simple-install.md Configure and set up the Segment SDK in your application delegate's didFinishLaunchingWithOptions method. Enable automatic tracking of application lifecycle events and screen views. ```objective-c SEGAnalyticsConfiguration *configuration = [SEGAnalyticsConfiguration configurationWithWriteKey:@"YOUR_WRITE_KEY"]; configuration.trackApplicationLifecycleEvents = YES; // Enable this to record certain application events automatically! configuration.recordScreenViews = YES; // Enable this to record screen views automatically! [SEGAnalytics setupWithConfiguration:configuration]; ``` -------------------------------- ### Get Profile Metadata Request Example Source: https://github.com/segmentio/segment-docs/blob/develop/src/unify/profile-api.md Example of a curl request to retrieve profile metadata. The `Request-Id` in the response headers is crucial for contacting Segment support. ```bash curl -i https://profiles.segment.com/v1/spaces//collections/users/profiles//metadata HTTP/1.1 200 OK Date: Mon, 01 Jul 2013 17:27:06 GMT Status: 200 OK Request-Id: 1111-2222-3333-4444 ``` -------------------------------- ### Screen Method Example Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/destinations/catalog/webhooks/index.md This example demonstrates the payload for a 'screen' event. It includes user ID, screen name, and context details like device, OS, and app information. ```http POST https://your-webhook-url.com/x ``` ```http User-Agent: Segment.io/1.0 Content-Type: application/json ``` ```json { "version" : 1, "type" : "screen", "userId" : "019mr8mf4r", "name" : "Main Screen", "timestamp" : "2012-12-02T00:30:08.276Z", "context" : { "device" : { "model" : "x86_64", "type" : "ios" }, "os" : { "name" : "iPhone OS", "version": "7.1" }, "app" : { "build" : "88", "name" : "YourApp", "version": "2.0.0" } } } ``` -------------------------------- ### Track Install Attributed Event with Campaign Data Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/destinations/catalog/appsflyer/index.md Example of tracking an 'Install Attributed' event with detailed campaign information, including source, name, and ad creative details, for accurate attribution. ```objc [[SEGAnalytics sharedAnalytics] track:@"Install Attributed", properties: @{ @"provider" : @"Appsflyer/Tune/Kochava/Branch", @"campaign" : @{ @"source" : @"Network/FB/AdWords/MoPub/Source", @"name" : @"Campaign Name", @"content" : @"Organic Content Title", @"ad_creative" : @"Red Hello World Ad", @"ad_group" : @"Red Ones", @"conversion_date": @"2018-03-07T04:05:50Z", @"id": @"123", @"ad_group_id": @"456", @"click_date": @"2018-03-06T04:05:50Z", @"lineitem_id":@"789", @"attribution":@"true", @"lineitem_name":@"US-iOS-campaign-Name" } }]; ``` -------------------------------- ### OAuth Token Response Example Source: https://github.com/segmentio/segment-docs/blob/develop/src/partners/enable-with-segment.md This JSON object represents the successful response after exchanging an authorization code for an install token. It contains details like access token, expiration, scope, and installation identifiers. ```json { "access_token": "YL8a0w-Boz1EgZgmD2ELZvsxakjqSMwO8xe7tV-ToSk.nKaLX2QHocqalHR3O4BdoYdcopk3hjW4izYHMG14cxQ", "token_type": "bearer", "expires_in": 3599, "scope": "workspace", "app_name": "apps/2", "install_name": "installs/7", "workspace_names": [ "workspaces/userworkspace" ] "source_names": ["workspaces/userworkspace/sources/javascript"] } ``` -------------------------------- ### Initialize Analytics-Swift SDK Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/sources/catalog/libraries/mobile/apple/migration.md Configure and set up the Analytics-Swift SDK. Use this for initializing the SDK with your write key and custom configurations. ```swift let configuration = Configuration(writeKey: "YOUR_WRITE_KEY") configuration.trackApplicationLifecycleEvents = true configuration.flushAt = 3 configuration.flushInterval = 10 Analytics.setup(with: configuration) ``` ```objc SEGConfiguration *config = [[SEGConfiguration alloc] initWithWriteKey:@""]; config.trackApplicationLifecycleEvents = YES; config.flushAt = 1; _analytics = [[SEGAnalytics alloc] initWithConfiguration: config]; ``` -------------------------------- ### Retrieve Anonymous ID Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/sources/catalog/libraries/mobile/ios/index.md Use this method to get the current anonymous ID set by the library. No setup is required. ```swift Analytics.shared().getAnonymousId ``` ```objc [[SEGAnalytics sharedAnalytics] getAnonymousId]; ``` -------------------------------- ### Full Alias and Track Example in Go Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/sources/catalog/libraries/server/go/index.md Demonstrates a complete workflow using Alias to link an anonymous user to an identified user, followed by Identify and Track calls for the identified user. Useful for managing user identity transitions. ```go // the anonymous user does actions ... client.Enqueue(analytics.Track{ Event: "Anonymous Event", UserId: anonymousUser, }) // the anonymous user signs up and is aliased client.Enqueue(analytics.Alias{ PreviousId: anonymousUser, UserId: "019mr8mf4r", }) // the identified user is identified client.Enqueue(analytics.Identify{ UserId: "019mr8mf4r", Traits: map[string]interface{}{ "name": "Michael Bolton", "email": "mbolton@example.com", "plan": "Enterprise", "friends": 42, }, }) // the identified user does actions ... client.Enqueue(analytics.Track{ Event: "Item Viewed", UserId: "019mr8mf4r", Properties: map[string]interface{}{ "item": "lamp", }, }) ``` -------------------------------- ### Example Floodlight GET Request Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/destinations/catalog/doubleclick-floodlight/index.md This is the resulting HTTP GET request sent to DoubleClick Floodlight based on the provided track call and Floodlight tag mapping. It includes parameters like src, cat, type, dc_rdid, and custom u parameters. ```http https://ad.doubleclick.net/ddm/activity/src=1234567;cat=fghij456;type=abcde123;dc_rdid=38400000-8cf0-11bd-b23e-10b96e4ddddd;u1=Stranger%20Things;u2=Netflix;u3=true;ord=1312312312;dc_lat=0 ``` -------------------------------- ### Initialize Client Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/sources/catalog/libraries/server/go/index.md Install the analytics-go library and initialize a client with your Segment Write Key. You can also configure regional endpoints. ```APIDOC ## Initialize Client Install `analytics-go` using `go get`: ```bash go get github.com/segmentio/analytics-go/v3 ``` Then import it and initialize an instance with your source's **Write Key**. ```go package main import "github.com/segmentio/analytics-go/v3" func main() { client := analytics.New("YOUR_WRITE_KEY") defer client.Close() // Use the client. } ``` For Business plans with access to Regional Segment, you can use the endpoint configuration parameter to send data to the desired region: Example configuration for EU region: ```go client, err := analytics.NewWithConfig(writeKey, analytics.Config{ Endpoint: "https://events.eu1.segmentapis.com", }) ``` ``` -------------------------------- ### Go Map Initialization Source: https://github.com/segmentio/segment-docs/blob/develop/src/test.md Demonstrates the initialization of a complex nested map structure in Go. ```go incoming := map[string]interface{}{ "asdf": 1, "qwer": []interface{}{}, "zxcv": []interface{}{ map[string]interface{}{}, true, int(1e9), "tyui", }, } ``` -------------------------------- ### Configure Segment React Native 1.5.1 Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/sources/catalog/libraries/mobile/react-native/migration.md Example client configuration for analytics-react-native version 1.5.1. Ensure you have the correct version installed in your package.json. ```javascript import analytics from '@segment/analytics-react-native' ... analytics.setup('WRITE_KEY', { debug: true, using: [amplitude, appsflyer], trackAdvertising: true, }); ``` ```json "dependencies": { ... "@segment/analytics-react-native": "1.5.1" } ``` ```plaintext PODS: ... - Analytics (4.1.6) } ``` -------------------------------- ### Set App Status to Install Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/destinations/catalog/moengage/index.md Use this for a fresh installation of your app. This helps the SDK determine if the user is existing or new. ```kotlin MoEAnalyticsHelper.setAppStatus(context, AppStatus.INSTALL) ``` -------------------------------- ### Live Chat Conversation Started Event Example Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/spec/live-chat.md Send this event when a customer sends their first message in a conversation. It includes details about the agent and the conversation context. ```json { "userId": "019mr8mf4r", "action": "track", "event": "Live Chat Conversation Started", "properties": { "agent_id": "bce89acdd11901", "agent_name": "Peter Gibbons", "agent_username": "pgibbons", "conversation_duration": 0, "conversation_id": "abd627dbecffc", "message_body": "But my stapler...", "message_id": "beaffc193618cbe" } } ``` -------------------------------- ### Flush Method Example Use Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/sources/catalog/libraries/mobile/apple/implementation.md Example of how to call the flush method to immediately send all queued events in Swift. ```swift analytics.flush() ``` -------------------------------- ### Initialize Typewriter Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/sources/catalog/libraries/mobile/kotlin-android/kotlin-android-typewriter.md Command to run the Typewriter quickstart wizard to generate or re-initialize the configuration file. ```bash $ npx typewriter init ``` -------------------------------- ### Configure Segment React Native 2.0 Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/sources/catalog/libraries/mobile/react-native/migration.md Example client configuration for analytics-react-native version 2.0. This version uses `createClient` and `AnalyticsProvider`. Ensure all necessary dependencies are installed. ```javascript import { createClient, AnalyticsProvider, } from '@segment/analytics-react-native'; import { FirebasePlugin } from '@segment/analytics-react-native-plugin-firebase'; ... const segmentClient = createClient({ writeKey: 'WRITE_KEY', trackAppLifecycleEvents: true, }); segmentClient.add({ plugin: new FirebasePlugin() }); const App = () => { ... return ( ... ); }; ``` ```json "dependencies": { ... "nanoid": "^3.1.30", "@react-native-async-storage/async-storage": "^1.15.11", "@segment/analytics-react-native": "2.2.0", "@segment/analytics-react-native-plugin-firebase": "2.0", "@segment/sovran-react-native": "0.2.6", } ``` ```plaintext PODS: ... - segment-analytics-react-native (2.0.0): - React-Core - sovran-react-native (0.2.6): - React-Core } ``` -------------------------------- ### CI Integration Example for Typewriter Builds Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/sources/catalog/libraries/mobile/apple/swift-typewriter.md Example CircleCI configuration showing how to integrate Typewriter client builds into CI/CD pipelines for testing and deployment. ```yaml # An example (simplified) CircleCI configuration: jobs: test: steps: - npx typewriter development - yarn run test deploy: steps: - npx typewriter production - yarn run deploy ``` -------------------------------- ### Get Destination Configuration Source: https://github.com/segmentio/segment-docs/blob/develop/src/partners/enable-with-segment.md Use this cURL command to retrieve the configuration of a specific destination within a user's workspace and source. Ensure you have the correct install token and API endpoint. ```sh $ INSTALL_TOKEN=YL8a0w-Boz1EgZgmD2ELZvsxakjqSMwO8xe7tV-ToSk.nKaLX2QHocqalHR3O4BdoYdcopk3hjW4izYHMG14cxQ $ curl \ -H "Authorization: Bearer $INSTALL_TOKEN" \ https://platform.segmentapis.com/v1beta/workspaces/business/sources/js/destinations/clearbrain \ ``` -------------------------------- ### Full Alias Workflow Example in Java Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/sources/catalog/libraries/server/java/index.md Demonstrates a common workflow for using the Alias method, including tracking anonymous events, aliasing to an identified user, and then identifying the user. ```java // the anonymous user does actions ... track("anonymous_user", "Anonymous Event"); // the anonymous user signs up and is aliased alias("anonymous_user", "identified@example.com"); // the signed up user is identified identify("identified@example.com", new Traits("plan", "Free")); // the identified user does actions ... track("identified@example.com", "Identified Action"); ``` -------------------------------- ### Example for Object Collection Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/sources/catalog/cloud-apps/amazon-s3/index.md This JavaScript snippet shows how to use the Segment API to set an object collection named 'rooms' with a specific ID and properties. The corresponding CSV filename should start with `object_rooms_`. ```javascript segment.set('rooms', '2561341', { name: 'Charming Beach Room Facing Ocean', location: 'Lihue, HI', review_count: 47 }); ``` -------------------------------- ### Get User Workspace Source: https://github.com/segmentio/segment-docs/blob/develop/src/partners/enable-with-segment.md This cURL command shows how to retrieve information about a user's workspace using an install token. This is applicable if your app has broader scopes like 'workspace' or 'workspace:read'. ```sh $ INSTALL_TOKEN=YL8a0w-Boz1EgZgmD2ELZvsxakjqSMwO8xe7tV-ToSk.nKaLX2QHocqalHR3O4BdoYdcopk3hjW4izYHMG14cxQ $ curl \ -H "Authorization: Bearer $INSTAL_TOKEN" \ https://platform.segmentapis.com/v1beta/workspaces ``` -------------------------------- ### Add Plugin Example Use Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/sources/catalog/libraries/mobile/apple/implementation.md Example of how to add a plugin, such as UIKitScreenTracking, to the analytics timeline in Swift. ```swift analytics.add(plugin: UIKitScreenTracking(name: "ScreenTracking")) ``` -------------------------------- ### Configure Nielsen DCR Options on Android Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/destinations/catalog/nielsen-dcr/index.md Set up destination-specific option values for Nielsen DCR on Android using a Map. This example demonstrates tracking a 'Video Playback Started' event with Nielsen options. ```java Map nielsenOptions = new LinkedHashMap<>(); nielsenOptions.put("pipmode", "c3 value"); nielsenOptions.put("adLoadType", "c4 value"); nielsenOptions.put("channelName", "c6 value"); nielsenOptions.put("mediaUrl", "c6 value"); nielsenOptions.put("hasAds", "true"); nielsenOptions.put("crossId1", "cross id1 value"); nielsenOptions.put("crossId2", "cross id2 value"); Analytics.with(context).track("Video Playback Started", new Properties(), new Options().setIntegrationOptions("nielsen-dcr", nielsenOptions)); ``` -------------------------------- ### Setup Configuration Source: https://github.com/segmentio/segment-docs/blob/develop/src/connections/sources/catalog/libraries/mobile/react-native/classic.md Configures the Analytics instance with your Segment source's Write Key. ```APIDOC ## setup ### Description Configures the Analytics instance with your Segment source's Write Key and other optional settings. ### Method Signature ``` analytics.setup(writeKey: string, options?: Configuration) ``` ### Parameters #### Path Parameters - `writeKey` (string) - Required - Your Segment source's **Write Key**. - `options` (Configuration, optional) - An object containing configuration options. ### Request Example ```js analytics.setup('YOUR_WRITE_KEY', { // ... other configuration options }) ``` ```