---
title: Start an interaction
source: https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/start-interaction
---

## Android

### Syntax [#syntax]

#### Java [#java]

```java
NewRelic.startInteraction(string $interactionName)
```

#### Kotlin [#kotlin]

```kotlin
NewRelic.startInteraction(actionName: String)
```

### Description [#description]

Create an interaction to instrument a method in your Android app code.

To name an interaction that already exists and is already being tracked, see [`setInteractionName()`](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/name-interaction/#android).

### Parameters [#parameters]

| Parameter          | Type     | Description                                             |
| ------------------ | -------- | ------------------------------------------------------- |
| `$interactionName` | `string` | Required. The name you want to give to the interaction. |

### Return values [#return-values]

Returns an interaction ID number which can be used for [ending the interaction](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api/end-interaction) at a certain point.

### Example [#example]

Here's an example of starting to track an interaction named `RefreshContacts`:

#### Java [#java]

```java
public class MainActivity extends Activity {
  ...
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.action_refresh:
        NewRelic.startInteraction("RefreshContacts");
      ...
        return true;
      default:
        return super.onOptionsItemSelected(item);
    }
  }
  ...
}
```

#### Kotlin [#kotlin]

```kotlin
class MainActivity : AppCompatActivity() {

  ...
  var client: OkHttpClient = OkHttpClient();

      binding.fab.setOnClickListener { view ->

          val interActionId = NewRelic.startInteraction("Getting Data From Server")

              lifecycleScope.launch(Dispatchers.IO) {
                  val result = getRequest()
                  NewRelic.endInteraction(interActionId)
              }
          }
      }
    ...
```

## iOS

### Syntax [#syntax]

#### Objective-c [#objc]

```objectivec
+ (NSString*) startInteractionWithName:(NSString*)interactionName;
```

#### Swift [#swift]

```swift
NewRelic.startInteraction(string: "myInteractionName")
```

### Description [#description]

This method will start an interaction trace using `interactionName` as the name. The interaction will record all instrumented methods until a timeout occurs or `stopCurrentInteraction` is called.

To name an interaction that already exists and is already being tracked, see [`setInteractionName()`](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/name-interaction/#ios).

> #### 💡 TIP
>
> If you use these methods, the instrumented interactions will not show up on the [Interactions](https://docs.newrelic.com/docs/mobile-monitoring/mobile-monitoring-ui/mobile-app-pages/interactions-page) page, but they can be still found with a NRQL query, such as:
>
> ```sql
> SELECT name FROM Mobile SINCE 7 DAYS AGO
> ```

### Parameters [#parameters]

| Parameter         | Type     | Description                                             |
| ----------------- | -------- | ------------------------------------------------------- |
| `interactionName` | `string` | Required. The name you want to give to the interaction. |

### Return values [#return-values]

If `startInteractionWithName` is called, the return value is an `interactionIdentifier` that must be passed to `stopCurrentInteraction` . But it's not required to call `stopCurrentInteraction` after calling start because `startInteractionWithName` will eventually complete intelligently.

### Examples [#examples][#examples]

#### Objective-C [#obj-c]

```objectivec
NSString *identifier = [NewRelic startInteractionWithName: @"myInteractionName"];
[NewRelic stopCurrentInteraction: identifier];
```

#### Swift [#swift]

```swift
let identifier = NewRelic.startInteraction(withName: "myInteractionName")
NewRelic.stopCurrentInteraction(identifier)
```

## Capacitor

### Syntax [#syntax]

```typescript
startInteraction(options: { value: string; }) => Promise<{ value: string; }>
```

### Description [#description]

Track a method as an interaction.

### Parameters [#parameters]

| Parameter | Type                 | Description                                             |
| --------- | -------------------- | ------------------------------------------------------- |
| `options` | `{ value: string; }` | Required. The name you want to give to the interaction. |

### Example [#example]

```typescript
const badApiLoad = async () => {
  const id = await NewRelicCapacitorPlugin.startInteraction({ value: 'StartLoadBadApiCall' });
  console.log(id);
  const url = 'https://fakewebsite.com/moviessssssssss.json';
  fetch(url)
    .then((response) => response.json())
    .then((responseJson) => {
      console.log(responseJson);
      NewRelicCapacitorPlugin.endInteraction({ interactionId: id.value });
    }) 
    .catch((error) => {
      NewRelicCapacitorPlugin.endInteraction({ interactionId: id.value });
      console.error(error);
    });
};
```

## Cordova

### Syntax [#syntax]

```typescript
startInteraction(interactionName: string, cb?: function): Promise<InteractionId>;
```

### Description [#description]

Track a method as an interaction.

### Parameters [#parameters]

| Parameter        | Type     | Description                                             |
| ---------------- | -------- | ------------------------------------------------------- |
| `Interactioname` | `string` | Required. The name you want to give to the interaction. |

### Example [#example]

```js
const badApiLoad = async () => {
  const interactionId = await NewRelic.startInteraction('StartLoadBadApiCall');
  console.log(interactionId);
  const url = 'https://cordova.apache.org/moviessssssssss.json';
  fetch(url)
    .then((response) => response.json())
    .then((responseJson) => {
      console.log(responseJson);
      NewRelic.endInteraction(interactionId);
    }) 
    .catch((error) => {
      NewRelic.endInteraction(interactionId);
      console.error(error);
    });
}
```

## .NET MAUI

### Syntax [#syntax]

```csharp
StartInteraction(string interactionName): string;
```

### Description [#description]

Track a method as an interaction.

### Parameters [#parameters]

| Parameter | Type                 | Description                                             |
| --------- | -------------------- | ------------------------------------------------------- |
| `options` | `{ value: string; }` | Required. The name you want to give to the interaction. |

### Example [#example]

```csharp
HttpClient myClient = new HttpClient(CrossNewRelic.Current.GetHttpMessageHandler());

string interactionId = CrossNewRelic.Current.StartInteraction("Getting data from service");

var response = await myClient.GetAsync(new Uri("https://jsonplaceholder.typicode.com/todos/1"));
if (response.IsSuccessStatusCode)
{
    var content = await response.Content.ReadAsStringAsync();
} 
else
{
    Console.WriteLine("Unsuccessful response code");
}

CrossNewRelic.Current.EndInteraction(interactionId);
```

## Flutter

### Syntax [#syntax]

```dart
startInteraction(String actionName);
```

### Description [#description]

Track a method as an interaction.

### Parameters [#parameters]

| Parameter           | Type     | Description                                             |
| ------------------- | -------- | ------------------------------------------------------- |
| `string actionName` | `string` | Required. The name you want to give to the interaction. |

### Example [#example]

```dart
var id = await NewrelicMobile.instance.startInteraction("Getting Data from Service");

try {
  var dio = Dio();
  var response = await dio.get(
    'https://reqres.in/api/users?delay=15');
    print(response);
    NewrelicMobile.instance.endInteraction(id);
    Timeline.finishSync();
} catch (e) {
  print(e);
}
```

## React Native

### Syntax [#syntax]

```ts
startInteraction(interactionName: string): Promise<InteractionId>;
```

### Description [#description]

Track a method as an interaction.

### Parameters [#parameters]

| Parameter         | Type     | Description                                             |
| ----------------- | -------- | ------------------------------------------------------- |
| `interactionName` | `string` | Required. The name you want to give to the interaction. |

### Example [#example]

```js
const badApiLoad = async () => {
  const interactionId = await NewRelic.startInteraction('StartLoadBadApiCall');
  console.log(interactionId);
  const url = 'https://facebook.github.io/react-native/moviessssssssss.json';
  fetch(url)
    .then((response) => response.json())
    .then((responseJson) => {
      console.log(responseJson);
      NewRelic.endInteraction(interactionId);
    })
    .catch((error) => {
      NewRelic.endInteraction(interactionId);
      console.error(error);
    });;
};
```

## Unity

### Syntax [#syntax]

```csharp
StartInteractionWithName(string interactionName): string;
```

### Description [#description]

Track a method as an interaction.

### Parameters [#parameters]

| Parameter         | Type     | Description                                             |
| ----------------- | -------- | ------------------------------------------------------- |
| `interactionName` | `string` | Required. The name you want to give to the interaction. |

### Example [#example]

```csharp
string interActionId = NewRelicAgent.StartInteractionWithName("Unity InterAction Example");

for(int i = 0; i < 4; i++)
{
    Thread.Sleep(1000);
}

NewRelicAgent.StopCurrentInteraction(interActionId);
```

## Unreal Engine

### Syntax [#syntax]

```cpp
startInterAction(FString interActionName):FString;
```

### Description [#description]

Track a method as an interaction.

### Parameters [#parameters]

| Parameter         | Type      | Description                                             |
| ----------------- | --------- | ------------------------------------------------------- |
| `interActionName` | `FString` | Required. The name you want to give to the interaction. |

### Example [#example]

```cpp
#include "NewRelicBPLibrary.h"

FString id =  UNewRelicBPLibrary::startInterAction("test Unreal InterAction");

FPlatformProcess::Sleep(6.0);

UNewRelicBPLibrary::endInterAction(id);
```

![Screenshot of the Unreal Engine Plugin Start InterAction](https://docs.newrelic.com/images/newrelic_unreal_sdk_interaction_example.webp "Unreal Engine Plugin Start InterAction")
