Skip to main content
UUserpilot Cordova Plugin enables you to capture user insights and deliver personalized in-app experiences in real time. With just a one-time setup, you can immediately begin leveraging Userpilot’s analytics and engagement features to understand user behaviors and guide their journeys in-app. This document provides a step-by-step walkthrough of the installation and initialization process, as well as instructions on using the SDK’s public APIs.

Prerequisites

Cordova

Your application should use Cordova version 10+ with cordova-cli installed globally.

Android

Your application’s build.gradle must have a compileSdk of 35+ and minSdk of 21+, and use Android Gradle Plugin (AGP) 8.6+.
<platform name="android">
    <preference name="android-minSdkVersion" value="21" />
    <preference name="android-compileSdkVersion" value="35" />
    <preference name="android-targetSdkVersion" value="35" />
    <preference name="GradlePluginKotlinEnabled" value="true" />
</platform>

iOS

Your application must target iOS 13+ to install the SDK, Update the iOS project xcodeproj to set the deployment target. Update your config.xml to set the deployment target.
<platform name="ios">
    <preference name="deployment-target" value="13.0" />
    <preference name="SwiftVersion" value="5.0" />
</platform>

Installation

Add the Userpilot Cordova Plugin dependency to your application.
  1. In your app’s root directory, install the Userpilot Cordova Plugin. You can fetch the latest version from here.
cordova plugin add @userpilot/cordova
or 
cordova plugin add @userpilot/cordova --variable DEPLOYMENT-TARGET=13.0
  1. Prepare your platforms:
cordova prepare

Initialization

To use Userpilot, initialize it once in your Application class. This ensures the SDK is ready as soon as your app starts. Update your Application class. Replace <APP_TOKEN> with your Application Token, which can be fetched from your Environments Page.
// API
setup(token, options, onSuccess, onError)

// Example
document.addEventListener('deviceready', function() {
	const options = {
        logging: true,         // Enable/disable SDK logging
        useInAppBrowser: true  // Enable/disable in-app browser for links - Works for Android
    };

    window.userpilot.setup('<APP_TOKEN>', options,
        function(success) {
            console.log('Userpilot initialized successfully');
        },
        function(error) {
            console.error('Failed to initialize Userpilot:', error);
        }
    );
}, false);

Configurations (Optional)

ParameterTypeDescription
loggingBooleanEnable or Disable logs for SDK

Default: false
disableRequestPushNotificationsPermissionBooleanDisable request push notifications permission by SDK.

Default: false
useInAppBrowserBooleanconfiguration to indicate when to open the URL inside CustomTabsIntent or not.

Default: false

Using the SDK

Once initialized, the SDK provides straightforward APIs for identifying users, tracking events, and screen views.

Identifying Users

This API is used to identify unique users and companies (groups of users) and set their properties. Once identified, all subsequent tracked events and screens will be attributed to that user.
ImportantIt’s crucial to call the Userpilot identify function; without it, Userpilot won’t be able to recognize your users, and mobile content won’t be displayed to them.
Recommended Usage:
  • On user authentication (login): Immediately call identify when a user signs in to establish their identity for all future events.
  • On app launch for authenticated users: If the user has a valid authenticated session, call identify at app launch.
  • Upon property updates: Whenever user or company properties change.
// API
identify(userID, properties, company, onSuccess, onError)

// Example
window.userpilot.identify(
    '<USER_ID>',
    {
        'name': 'John Doe', 
        'email': 'user@example.com', 
        'created_at': '2019-10-17', 
        'role': 'Admin'
    },
    {
        'id': 'company123', 
        'name': 'Acme Labs', 
        'created_at': '2019-10-17', 
        'plan': 'Free'
    },
    function(success) {
        console.log('User identified successfully');
    },
    function(error) {
        console.error('Failed to identify user:', error);
    }
);
Properties Guidelines
  • Key id is required in company properties, to identify a unique company.
  • Userpilot supports String, Numeric, and Date types.
  • Make sure you’re sending date values in ISO8601 format.
  • If you are planning to use Userpilot’s localization features, make sure you are passing user property locale_code with a value that adheres to ISO 639-1 format.
  • Userpilot’s reserved properties’ have pre-determined types and improve profiles interface in the dashboard:
    • Use key email to pass the user’s email.
    • Use key name to pass the user’s or company’s name.
    • Use key created_at to pass the user’s or company’s signed up date.
Notes
  • Ensure the User ID source is consistent across Web, Android, and iOS.
  • While properties are optional, setting them enhances Userpilot’s segmentation capabilities.

Tracking Screens (Required)

Calling screen is crucial for unlocking Userpilot’s core engagement and analytics capabilities. When a user navigates to a particular screen, invoking screen records that view and triggers any eligible in-app experiences. Subsequent events are also attributed to the most recently tracked screen, providing context for richer analytical insights. For these reasons, we strongly recommend tracking all of your app’s screen views.
// API
screen(screenName, onSuccess, onError)

// Example
window.userpilot.screen('Profile',
    function(success) {
        console.log('Screen tracked successfully');
    },
    function(error) {
        console.error('Failed to track screen:', error);
    }
);

Tracking Events

Log any meaningful action the user performs. Events can be button clicks, form submissions, or any custom activity you want to analyze. Optionally, you can pass metadata with the event to provide specific context.
// API
track(name, properties, onSuccess, onError)

// Example
window.userpilot.track('Added to Cart', 
    { 
        itemId: 'sku_456', 
        price: 29.99 
    },
    function(success) {
        console.log('Event tracked successfully');
    },
    function(error) {
        console.error('Failed to track event:', error);
    }
);

Logging Out

When a user logs out, call logout() to clear the current user context. This ensures subsequent events are no longer associated with the previous user.
// API
logout(onSuccess, onError)

// Example
window.userpilot.logout(
    function(success) {
        console.log('User logged out successfully');
    },
    function(error) {
        console.error('Failed to logout user:', error);
    }
);

Anonymous Users

If a user is not authenticated, call anonymous() to track events without a user ID. This is useful for pre-signup flows or guest user sessions.
// API
anonymous(onSuccess, onError)

// Example
window.userpilot.anonymous(
    function(success) {
        console.log('Anonymous user set successfully');
    },
    function(error) {
        console.error('Failed to set anonymous user:', error);
    }
);
Anonymous users count towards your Monthly Active Users usage. Consider your MAU limits before using this API.

Experience

Triggers a specific experience programmatically using it’s ID. This API allows you to manually initiate an experience within your application.
// API
triggerExperience(experienceId, onSuccess, onError)

// Example
window.userpilot.triggerExperience('<EXPERIENCE_ID>',
    function(success) {
        console.log('Experience triggered successfully');
    },
    function(error) {
        console.error('Failed to trigger experience:', error);
    }
);
To end current active experience
// API
endExperience(onSuccess, onError)

// Example
window.userpilot.endExperience(
    function(success) {
        console.log('Experience ended successfully');  
    },
    function(error) {
        console.error('Failed to end experience:', error);
    }
);

Configuration (Optional)

ParameterTypeDescription
loggingBooleanEnable or disable logs for the SDK.

Default: false
disableRequestPushNotificationsPermissionBooleanDisable push notifications permission request by the SDK.

Default: false
useInAppBrowserBooleanDetermines whether to open URLs inside CustomTabsIntent/SFSafariViewController or use the system browser.

Default: false