• /
  • EnglishEspañol日本語한국어Português
  • ログイン今すぐ開始

Monitor your Unity mobile app

Our New Relic Unity agent monitors your Unity mobile app and provides deep insights into your app's performance, errors, and user experience. Once you install and configure the Unity agent, you'll be able to:

  • Capture C# and Native C++ errors: Identify and fix problems quickly.
  • Track network requests: See how your app interacts with the backend.
  • Use distributed tracing: Drill down into handled exceptions and find the root cause.
  • Create custom events and metrics: Understand how your users interact with your app.
Summary view of a Unity app in New Relic

one.newrelic.com > All capabilities > Mobile > (select an app) > Summary: View Unity data, track HTTP requests and errors, and monitor how your app is performing over time.

(Recommended) Guided installation

To install the Unity agent, follow our guided install, located directly in the UI.

Screenshot of the guided install UI for Unity

Manual installation

If you need to install the agent manually, follow these steps:

Review the requirements

Before you install the Unity agent, make sure your Unity app meets these version requirements:

Add the Unity agent to your project

In the Unity package manager, add the following GitHub URL:

https://github.com/newrelic/newrelic-unity-agent.git
Unity Agent Install From Package Manager

Add application token(s)

To enable New Relic to authenticate your Unity app's data, follow these steps:

  1. Get your application token from New Relic:

    1. Go to one.newrelic.com, click Integrations & Agents, then click Mobile.
    2. Select your Unity app.
    3. Go to Settings > Application and copy the displayed Application token.
  2. Add the token to your Unity project:

    1. Open your Unity IDE.

    2. Go to Tools > New Relic > Getting Started to open the editor window.

    3. Paste the appropriate application token into the corresponding field for each platform your app supports:

      • Android: Paste the Android token into the "Android App Token" field.
      • iOS: Paste the iOS token into the "iOS App Token" field.

      If your app runs on both Android and iOS, provide separate tokens for each platform. Do not use the same token for both.

    Add App Token in Unity Apps

(Android-only) Configure your Android app

To configure your Android app you need to customize your Gradle templates. If you're using Unity 2019 or later, follow the steps below.

  1. In your Gradle build settings, you'll need to include the New Relic Maven repository URL. To do this, open your mainTemplate.gradle file, which is usually located in the Assets/Plugins/Android folder. Add the following snippet:

    allprojects {
    buildscript {
    repositories {
    ARTIFACTORY_REPOSITORY
    google()
    jcenter()
    mavenCentral()
    }
    }
    }
  2. In your baseProjectTemplate.gradle file (usually located in your Unit project's Android folder), add the New Relic classpath at the project level:

    dependencies {
    // If you are changing the Android Gradle Plugin version,
    // make sure it is compatible with the Gradle version preinstalled with Unity.
    // See which Gradle version is preinstalled with Unity here:
    // https://docs.unity3d.com/Manual/android-gradle-overview.html
    // See the official Gradle and Android Gradle Plugin compatibility table here:
    // https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
    // To specify a custom Gradle version in Unity, go to "Preferences > External Tools",
    // uncheck "Gradle Installed with Unity (recommended)",
    // and specify a path to a custom Gradle version.
    classpath 'com.newrelic.agent.android:agent-gradle-plugin:7.2.0'
    BUILD_SCRIPT_DEPS
    }

    If you're using an older Unity version that requires Gradle 7.0 or lower, you'll need to use a specific classpath dependency to ensure compatibility:

    dependencies {
    // If you are changing the Android Gradle Plugin version,
    // make sure it is compatible with the Gradle version preinstalled with Unity.
    // See which Gradle version is preinstalled with Unity here:
    // https://docs.unity3d.com/Manual/android-gradle-overview.html
    // See official Gradle and Android Gradle Plugin compatibility table here:
    // https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
    // To specify a custom Gradle version in Unity, go to "Preferences > External Tools",
    // uncheck "Gradle Installed with Unity (recommended)",
    // and specify a path to a custom Gradle version.
    classpath 'com.newrelic.agent.android:agent-gradle-plugin:6.11.0'
    BUILD_SCRIPT_DEPS
    }

    If your project is using plugin DSL, make the following changes (and skip step 3):

    In android/app/build.gradle:

    plugins {
    id "com.android.application"
    id "kotlin-android"
    id "com.newrelic.agent.android" version "7.5.1" //<-- include this
    }
  3. In your launcherTemplate.gradle file (usually located in your Unity project's Android folder), apply the newrelic plugin to the top of your launcherTemplate.gradle file:

    apply plugin: "com.android.application"
    apply plugin: 'newrelic' // <-- add this
  4. In your AndroidManifest.xml file, add the following permissions:

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

(iOS-only) Manage dependencies

For iOS, check your External Dependency Manager settings:

  1. In your Unity IDE, go to Assets and open the External Dependency Manager.

  2. Click iOS Resolver.

  3. In the Podfile Configurations section, verify these settings:

    • Add use_frameworks! to Podfile is disabled
    • Always add the main target to Podfile is enabled
    Add iOS Dependency in Unity App
  4. If you're not using the Podfile for iOS dependency management, follow these steps:

    1. Download and unzip the New Relic XCFramework SDK (iOS agent). You can get the latest iOS agent from our iOS agent release notes.
    2. Add the New Relic XCFramework to your Xcode project:
      1. Unzip the SDK download.
      2. From your Finder, drag the NewRelicAgent.xcframework folder into your Xcode project, placing it onto your Targets Frameworks pane.
      3. Under the Embed column, click Embed & Sign.

    And you're done! You should start seeing data in New Relic within 5 minutes.

Customize the agent instrumentation

Need to customize your agent instrumentation? Our public mobile SDK API methods let you collect custom data, configure default settings, and more.

The following customizations are available for the Unity agent.

If you want to...

Use this method

Record breadcrumbs to track app activity that may be helpful for troubleshooting crashes.

Record breadcrumbs

Track a method as an interaction.

Start interactions

Stop interactions

Record custom metrics.

Record custom metrics

Record an exception.

Record errors

Record custom attributes and events.

There are several ways to report custom attributes and events:

Track custom network requests and failures.

Track HTTP requests

Track failing HTTP requests

Shut down the agent.

Shut down the agent

Run a test crash report.

Test crash reporting

Monitor C# errors

In the New Relic UI, you can view your fatal and non-fatal C# errors and handled exceptions, including details like event trails, attributes, and stack traces for each recorded error.

Mobile Handled Exceptions

To view your errors:

  1. Go to one.newrelic.com > All capabilities > Mobile.
  2. Select your Unity app.
  3. Click Exceptions > Handled exceptions.

You can also build a dashboard for these errors using this query:

SELECT * FROM MobileHandledException SINCE 24 hours ago

Query log data

New Relic stores your Unity logs as custom events. You can query these logs and build dashboards for them using this NRQL query:

SELECT * FROM `Mobile Unity Logs` SINCE 30 MINUTES AGO

For more information on NRQL queries, see Introduction to NRQL.

Copyright © 2024 New Relic株式会社。

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.