Skip to content

docs:added docs for custom interaction #20379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---
title: Android Agent Custom Interactions
tags:
- Mobile monitoring
- New Relic Mobile Android
- Install configure
metaDescription: 'How to use Custom Interactions with Android Mobile Monitoring'
freshnessValidatedDate: 2025-04-02
---

<Callout variant="important">
This feature is only working correctly if you disable Default Interactions at runtime [configure Default Interactions runtime](/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/configure-settings) and buildtimee [configure Default Interactions at buildtime](/docs/mobile-monitoring/new-relic-mobile-android/install-configure/configure-new-relic-gradle-plugin).
</Callout>

# Creating Custom Interactions

You can create Custom Interactions and Enhance them with additional information. If Custom Interactions are not closed explicitly, New Relic agent will automatically close them and send the data to New Relic Platform.

To Create a Custom Interaction, use `startInteraction` to begin and `endInteraction` to close the interaction. The system automatically measures the timing.

### Java

```java
// Start a custom interaction
String id = NewRelic.startInteraction("Tap on Search");

// ...do some work here...

// End the custom interaction
NewRelic.endInteraction(id);
```

### Kotlin

```kotlin
// Start a custom interaction
val id = NewRelic.startInteraction("Tap on Search")

// ...do some work here...

// End the custom interaction
NewRelic.endInteraction(id)
```

These methods allow you to capture the duration and details of specific interactions within your application, providing deeper insights into user behavior and application performance.

# Creating Child Traces with Custom Interactions

Child traces are similar to custom interactions. When the parent interaction is closed, New Relic automatically closes all child method traces associated with the parent interaction.

To generate child traces, use the `NewRelic.startMethodTrace()` method. Here's how you can implement parent custom interactions and child traces:

### Java

```java
// Start a parent custom interaction
String parentId = NewRelic.startInteraction("Main Activity");

// Start a child trace
NewRelic.startMethodTrace("Load Resource From Database");

// ...do some work here...

// End the child trace
NewRelic.endMethodTrace();

// Start another child trace
NewRelic.startMethodTrace("Load Resource From Server");

// ...do some work here...

// End the child trace
NewRelic.endMethodTrace();

// End the parent interaction
NewRelic.endInteraction(parentId);
```

### Kotlin

```kotlin
// Start a parent custom interaction
val parentId = NewRelic.startInteraction("Main Activity")

// Start a child trace
NewRelic.startMethodTrace("Loop 1 Run")

// ...do some work here...

// End the child trace
NewRelic.endMethodTrace()

// Start another child trace
NewRelic.startMethodTrace("Loop 2 Run")

// ...do some work here...

// End the child trace
NewRelic.endMethodTrace()

// End the parent interaction
NewRelic.endInteraction(parentId)
```


## Considerations

- If customers want to create custom interactions with method traces, they need to start and end the interaction without any user intervention.
- If customers wish to calculate the time between two interactions with user intervention, they should not create child traces for these interactions.

This Approach allows for detailed tracking and measurement of interactions within your mobile application, providing valuable insights into application performance and user behavior.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ The New Relic Gradle plugin extension allows you to configure the behavior of pl
</td>
</tr>

<tr>
<td>
`defaultInteractionsEnabled`
</td>

<td>
Disabled the to create DefaultInteractions for Activities and Fragments.
* Default: `true`

Supported when used with Gradle 7.4 and higher.
</td>
</tr>

</tbody>
</table>

Expand Down Expand Up @@ -111,6 +124,9 @@ Here are some simple examples showing how to apply plugin configuration options

// Enable log instrumentation
logInstrumentationEnabled true

// Enable the Default Interaction
defaultInteractionsEnabled true
}
```
</Collapser>
Expand Down Expand Up @@ -184,4 +200,18 @@ Here are some simple examples showing how to apply plugin configuration options
}
```
</Collapser>

<Collapser
id="app-level"
title="Disable Default Interactions"
>
To disable default Interactions for Activities and Fragments:

```gradle
newrelic {
// disable log instrumentation
defaultInteractionsEnabled false
}
```
</Collapser>
</CollapserGroup>
2 changes: 2 additions & 0 deletions src/nav/mobile-monitoring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pages:
path: /docs/mobile-monitoring/new-relic-mobile-android/install-configure/android-agent-native-crash-reporting
- title: App launch time metrics
path: /docs/mobile-monitoring/new-relic-mobile-android/install-configure/configure-app-launch-time-android-apps
- title: Custom Interactions
path: /docs/mobile-monitoring/new-relic-mobile-android/install-configure/android-agent-custom-Interaction
- title: Distributed tracing
path: /docs/mobile-monitoring/new-relic-mobile-android/get-started/new-relic-android-and-dt
- title: Troubleshooting
Expand Down
Loading