> ## Documentation Index
> Fetch the complete documentation index at: https://docs.userpilot.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Ionic Capacitor plugin

> Install Userpilot on Ionic-Capacitor Application

Userpilot Capacitor 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

#### Android

Your application's `build.gradle` must have a `compileSdk` of 35+ and `minSdk` of 23+. Your project should use the Android Gradle Plugin (AGP) version 8.6+.

```kotlin theme={null}
android {
    compileSdk 35

    defaultConfig {
        minSdk 23
    }
}
```

#### iOS

Your application must target iOS 13+ to install the SDK, Update the iOS project xcodeproj to set the deployment target, if needed. In the application's Podfile, include at least this minimum version.

```bash theme={null}
# Podfile
platform :ios, '14.0'
```

***

## Installation

Add the Userpilot Capacitor Plugin dependency to your application.

1. In your app's root directory, install the Userpilot Capacitor Plugin. You can fetch the latest version from [here](https://www.npmjs.com/package/@userpilot/capacitor).

```bash theme={null}
npm install @userpilot/capacitor

npx cap sync
```

Note: You do not need to manually update your Podfile to add Userpilot.

***

## 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](https://run.userpilot.io/environment).

```javascript theme={null}
import { Userpilot } from '@userpilot/capacitor';

Userpilot.initialize({ token: 'APP_TOKEN', config: { logging: true } })
```

***

## 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.

<Warning>
  **Important**

  It’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.
</Warning>

**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.

```javascript theme={null}
// API
identify(options: IdentifyOptions)

// Parameters
export interface IdentifyOptions {
   userId: string;
   properties?: object;
   company?: object;
}

// Example
userpilot.identify(
   userId: '<USER_ID>', 
   properties: {
      'name' : 'John Doe',
      'email' : 'user@example.com', 
      'created_at' : '2019-10-17', 
      'role' : 'Admin'
   },   
   company: {
      'id' : '<COMPANY_ID>',
      'name': 'Acme Labs', 
      'created_at': '2019-10-17', 
      'plan' : 'Free'
   }
);
```

**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.

<Tip>
  Notes

  * Ensure the User ID source is consistent across Web, Android, and iOS.
  * While properties are optional, setting them enhances Userpilot’s segmentation capabilities.
</Tip>

### 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.

```javascript theme={null}
// API
screen(options: ScreenOptions)

// Parameters
export interface ScreenOptions {
   title: string;
}

// Example
Userpilot.screen({ title: 'Profile' })
```

### 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.

```javascript theme={null}
// API
track(options: TrackOptions)

// Parameters
export interface TrackOptions {
   name: string;
   properties?: object;
}

// Example
Userpilot.track({ name: 'Added to Cart', properties: {'itemId' : 'sku_456', 'price' : 29.99}})
```

### 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.

```javascript theme={null}
userpilot.logout()
```

### 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.

```javascript theme={null}
userpilot.anonymous()
```

<Warning>
  Anonymous users count towards your Monthly Active Users usage. Consider your MAU limits before using this API.
</Warning>

***

## Experience

Triggers a specific experience programmatically using it's ID. This API allows you to manually initiate an experience within your application.

```javascript theme={null}
// API
triggerExperience(options: ShowOptions)

// Parameters
export interface ShowOptions {
  experienceId: string;
}

// Example
userpilot.triggerExperience({ experienceId: '<EXPERIENCE_ID>' })
```

To end current active experience

```javascript theme={null}
userpilot.endExperience()
```

## Configuration (Optional)

| **Parameter**                             | **Type** | **Description**                                                                                                                         |
| ----------------------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| logging                                   | Boolean  | Enable or disable logs for the SDK.<br /><br />**Default: false**                                                                       |
| disableRequestPushNotificationsPermission | Boolean  | Disable push notifications permission request by the SDK.<br /><br />**Default: false**                                                 |
| useInAppBrowser                           | Boolean  | Determines whether to open URLs inside CustomTabsIntent/SFSafariViewController or use the system browser.<br /><br />**Default: false** |

<Frame>
  [**For any questions or concerns please reach out to support@userpilot.com**](mailto:support@userpilot.com)
</Frame>
