Monitor your Cordova application

The New Relic Cordova agent monitors native applications (iOS, Android) built on the Apache Cordova framework. Written in JavaScript, the Cordova agent also includes all New Relic mobile monitoring features for native apps.

Features

Once installed, the Cordova agent can:

  • Detect the platforms added to your Cordova application and apply the most recent release of the relevant New Relic Android or iOS agent
  • Add post-build scripts for uploading iOS symbolication files
  • Upload Android Proguard mapping files
  • Automatically instrument mobile applications built via Cordova
  • Capture JavaScript errors
  • Generate distributed traces
  • Track promise rejection (unhandled exceptiona in JavaScript)
  • Track warnings and errors with console logs
  • Capture interactions and their sequences
  • Track user sessions

Get started with Cordova monitoring

Step 1: Check the requirements

Before installing, make sure you've met these prerequisites for adding the Android or iOS platform to your Cordova project:

Step 2: Get your application token

If you’re new to New Relic, create an account - it's free!

First, you need to get your application token to use later in Step 3:

  1. Go to one.newrelic.com > Browser & Mobile > (choose Android or iOS), then complete the instrumentation steps in the UI.
  2. From Step 4 in the UI, copy the application token. You’ll need this when installing the Cordova agent.

Step 3: Install the Cordova agent

  1. In your Cordova project directory, add the Cordova agent to your project with the Cordova command line tool, and paste the application token(s) from Step 2 using the --variable argument:

    # Install from github repository
    cordova plugin add https://github.com/newrelic/newrelic-cordova-plugin.git --variable IOS_APP_TOKEN="{ios-app-token}" --variable ANDROID_APP_TOKEN="{android-app-token}"

    Important

    If your app is built on both iOS and Android, you’ll need to get application tokens for iOS and Android separately.

  2. (Optional) If you're using an ionic framework, add this to your Cordova project directory:

    bash
    $
    ionic cordova plugin add https://github.com/newrelic/newrelic-cordova-plugin.git --variable IOS_APP_TOKEN="{ios-app-token}" --variable ANDROID_APP_TOKEN="{android-app-token}"
    $
    $
    npm install @awesome-cordova-plugins/newrelic
  3. Then, deploy your app.

And you’re done! Now it’s time to view data in New Relic (it may take a few minutes after deploying your app).

Step 4: View data in New Relic

View your app’s performance data in the New Relic mobile monitoring UI by going to one.newrelic.com > Mobile > (select a Cordova app).

one.newrelic.com > Mobile > (select a Cordova app): The Cordova agent will collect this data and send it to New Relic, where you can view and analyze it in the UI.

(Optional) Step 5: Track JavaScript errors

You can configure the Cordova agent to report JavaScript errors to New Relic by adding NewRelic.recordError(error); to your project:

NewRelic.recordError(error);

Cordova agent v6.2.0 and above:

JavaScript errors can be seen in the Handled Exceptions tab in New Relic One. You will be able to see the event trail, attributes, and stack trace for every JavaScript error recorded.

You can also find these errors by running this query:

SELECT * FROM MobileHandledException SINCE 24 hours ago

Cordova agent v6.0.0 - v6.1.0:

Then in the UI, you can track these JavaScript error events with a custom dashboard. To create a custom dashboard:

  1. Go to one.newrelic.com.
  2. Click Query builder.
  3. Run this query:
    SELECT * FROM `JS Errors`
  4. Click Add to dashboard.
    one.newrelic.com > Query builder: Use the Query builder to create a custom dashboard for tracking JavaScript errors from your Cordova app.
    If you need help getting started with dashboards, see Introduction to dashboards.

Next steps

  • Use API calls to track custom data: Our Cordova agent utilizes the same API calls as our iOS and Android SDK agents. See iOS SDK or Android SDK.

  • Update your Cordova agent version: If you need to update your Cordova agent to the latest version, using the run this simple command:

    cordova plugin update