# Track API in Mobile SDKs


This guide explains how to use the `track` API in the RudderStack [Android (Kotlin)]({{< ref "sources/event-streams/sdks/kotlin-sdk/" >}}) and [iOS (Swift)]({{< ref "sources/event-streams/sdks/swift-sdk/" >}}) SDKs.

## Overview

The RudderStack Android (Kotlin) and iOS (Swift) SDKs provide a [`track`]({{< ref "event-spec/standard-events/track.md" >}}) API that lets you record the user’s actions along with any properties associated with them.

## Android (Kotlin)

The `track` method definition in the Android (Kotlin) SDK is as follows:

{{< tabs tabTotal="2" >}}
{{% tab tabName="Default invocation" %}}
```kotlin
analytics.track(
    name = "Product Added",
    properties = buildJsonObject {
        put("key", "value")
    },
    options = RudderOption()
)
```

The corresponding Java snippet is shown below:

```java
HashMap<String, Object> properties = new HashMap<>();
properties.put("key", "value");

analytics.track("Product Added", properties, new RudderOption());
```
{{% /tab %}}
{{% tab tabName="Alternate invocations" %}}
```kotlin
// Track event with event name
analytics.track(name = "Product Added")

// Track event with event name and properties
analytics.track(
    name = "Product Added",
    properties = buildJsonObject {
        put("key-1", "value-1")
    },
)

// Track event with event name and options
analytics.track(
    name = "Product Added",
    options = RudderOption(
        customContext = buildJsonObject {
            put("key-1", "value-1")
        },
        integrations = buildJsonObject {
            put("Amplitude", true)
            put("INTERCOM", buildJsonObject {
                put("lookup", "phone")
            })
        },
        externalIds = listOf(
            ExternalId(type = "brazeExternalId", id = "value1234"),
        ),
    ),
)
```
{{% /tab %}}
{{< /tabs >}}

### Method signature {#method-signature-kotlin}

The below table describes the `track` method signature in detail:

| Field | Data type | Description |
| :----| :------| :-----|
| `name` | String | Name of the event. |
| `properties` | Properties | Additional properties describing the event that you want to send. <br /><br />**Note**: The `properties` type in Java is `Map<String, Object>`. |
| `options` | RudderOption | Additional event options. |

### Example {#example-kotlin}

A sample `track` event sent from the Android (Kotlin) SDK is shown below:

{{< tabs tabTotal="2" >}}
{{% tab tabName="Kotlin" %}}
```kotlin
analytics.track(
    name = "Product Added",
    options = RudderOption(
        customContext = buildJsonObject {
            put("currency", "USD")
        },
        integrations = buildJsonObject {
            put("Amplitude", true)
            put("INTERCOM", buildJsonObject {
                put("lookup", "phone")
            })
        },
        externalIds = listOf(
            ExternalId(type = "brazeExternalId", id = "1hKOmRA4GRlm"),
        ),
    ),
)
```
{{% /tab %}}
{{% tab tabName="Java" %}}
```java
Map<String, Object> customContext = new HashMap<>();
customContext.put("key", "value");

Map<String, Object> nestedIntegrations = new HashMap<>();
nestedIntegrations.put("lookup", "phone");
Map<String, Object> integrations = new HashMap<>();
integrations.put("Amplitude", true);
integrations.put("INTERCOM", nestedIntegrations);

List<ExternalId> externalIds = new ArrayList<>();
externalIds.add(new ExternalId("brazeExternalId", "1hKOmRA4GRlm"));

RudderOption option = new RudderOptionBuilder()
        .setIntegrations(integrations)
        .setExternalId(externalIds)
        .setCustomContext(customContext)
        .build();
        
analytics.track("Product Added", option);
```
{{% /tab %}}
{{< /tabs >}}

## iOS (Swift)

The `track` method definition in the iOS (Swift) SDK is as follows:

{{< tabs tabTotal="2" >}}
{{% tab tabName="Default invocation" %}}
```swift
analytics.track(
    name: "Product Added",
    properties: [
        "key-1": "value-1"
    ],
    options: RudderOption()
)
```

{{< warning >}}
Make sure to include the `import RudderStackAnalytics` statement before making the call.
{{< /warning >}}

The corresponding Objective-C snippet is shown below:

```objectivec
[analytics track:@"Product Added"
      properties:@{
          @"key-1": @"value-1"
      }
      options:[[RSSOptionBuilder new] build]];
```

{{< info >}}
`RSSOptionBuilder` is an Objective-C–only helper class. It uses the builder pattern to create an `RSSOption` instance and lets you set custom context, configure integrations, and attach external IDs in a structured way.
{{< /info >}}

{{% /tab %}}
{{% tab tabName="Alternate invocations" %}}
```swift
// Track event with event name
analytics.track(name: "Product Added")

// Track event with event name and properties
analytics.track(
    name: "Product Added",
    properties: [
        "key-1": "value-1"
    ]
)

// Track event with event name and options
analytics.track(
    name: "Product Added",
    properties: [
        "key-1": "value-1"
    ],
    options: RudderOption(
        integrations: [
            "Amplitude": true,
            "INTERCOM": [
                "lookup": "phone"
            ]
        ],
        customContext: [
            "key-1": "value-1"
        ],
        externalIds: [
            ExternalId(type: "brazeExternalId", id: "value1234")
        ]
    )
)
```

The corresponding Objective-C snippet is shown below:

```objectivec
// Track event with event name
[analytics track:@"Product Added"];

// Track event with event name and properties
[analytics track:@"Product Added"
    properties:@{
        @"key-1": @"value-1"
    }];

// Track event with event name and options
RSSOptionBuilder *optionBuilder = [[RSSOptionBuilder alloc] init];

[optionBuilder setCustomContext:@{
    @"key-1": @"value-1"
}];

[optionBuilder setIntegrations:@{
    @"Amplitude": @YES,
    @"INTERCOM": @{
        @"lookup": @"phone"
    }
}];

[optionBuilder setExternalIds:@[
    [[RSSExternalId alloc] initWithType:@"brazeExternalId" id:@"value1234"]
]];

[analytics track:@"Product Added"
      properties:@{
          @"key-1": @"value-1"
      }
      options:[optionBuilder build]];
```

{{% /tab %}}
{{< /tabs >}}

### Method signature {#method-signature-swift}

The below table describes the `track` method signature in detail:

| Field | Data type | Description |
| :----| :------| :-----|
| `name` | String | Name of the event. |
| `properties` | Properties | Additional properties describing the event that you want to send. |
| `options` | RudderOption | Additional event options. |

### Example {#example-swift}

A sample `track` event sent from the iOS (Swift) SDK is shown below:

{{< tabs tabTotal="2" >}}
{{% tab tabName="Swift" %}}
```swift
analytics.track(
    name: "Track at \(Date())",
    properties: [
        "key-1": "value-1"
    ],
    options: RudderOption(
        integrations: [
            "Amplitude": true,
            "INTERCOM": [
                "lookup": "phone"
            ]
        ],
        customContext: [
            "key-1": "value-1"
        ],
        externalIds: [
            ExternalId(type: "brazeExternalId", id: "value1234")
        ]
    )
)
```
{{% /tab %}}
{{% tab tabName="Objective-C" %}}
```objectivec
RSSOptionBuilder *optionBuilder = [[RSSOptionBuilder alloc] init];

[optionBuilder setCustomContext:@{
    @"key-1": @"value-1"
}];

[optionBuilder setIntegrations:@{
    @"Amplitude": @YES,
    @"INTERCOM": @{
        @"lookup": @"phone"
    }
}];

[optionBuilder setExternalIds:@[
    [[RSSExternalId alloc] initWithType:@"brazeExternalId" id:@"value1234"]
]];

[analytics track:[NSString stringWithFormat:@"Track at %@", [NSDate date]]
      properties:@{
          @"key-1": @"value-1"
      }
      options:[optionBuilder build]];
```
{{% /tab %}}
{{< /tabs >}}
