### Install Userpilot via JavaScript Snippet
Source: https://docs.userpilot.com/getting-started/quickstart
Embed the Userpilot JavaScript snippet into the `
` section of your HTML pages. This script initializes Userpilot with your provided App Token. Replace 'Your_App_Token' with your actual token obtained from the Userpilot dashboard.
```javascript
```
--------------------------------
### Reload Userpilot on Route Change (SPA)
Source: https://docs.userpilot.com/getting-started/quickstart
For Single Page Applications (SPAs), it's crucial to reload Userpilot when the route changes to ensure dynamic content and tracking work correctly. This example uses React's `useEffect` hook to call `userpilot.reload()` whenever the location changes.
```javascript
const location = useLocation();
React.useEffect(() => {
userpilot.reload();
}, [location]);
```
--------------------------------
### Track Key Events with Userpilot
Source: https://docs.userpilot.com/getting-started/quickstart
Track important user actions within your application by calling the `userpilot.track()` function. Pass a descriptive string as an argument to log the event. This allows you to monitor feature usage and user engagement within Userpilot.
```javascript
userpilot.track("Clicked purchase button");
```
--------------------------------
### Setup Push Notifications and Request Permission (Objective-C)
Source: https://docs.userpilot.com/developer/installation/mobile/mobile-cordova
This Objective-C method, `setupPushWithApplication:`, initializes push notification handling by requesting authorization and registering for remote notifications. It also sets the `UNUserNotificationCenterDelegate`.
```objectivec
- (void)setupPushWithApplication:(UIApplication *)application {
[self requestPushNotificationPermission];
// 1: Register to get a device token
[application registerForRemoteNotifications];
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
}
```
--------------------------------
### Identify Users with Userpilot
Source: https://docs.userpilot.com/getting-started/quickstart
Identify users by calling the `userpilot.identify()` function. This function accepts a user ID and an optional object containing user and company properties. For Multi-Page Applications (MPAs), call this on each page load. For Single Page Applications (SPAs), call it once after authentication.
```javascript
userpilot.identify("USER_ID", {
name: "John Doe",
email: "john@example.com",
created_at: "2025-03-17",
company: {
id: "COMPANY_ID",
name: "Acme Inc.",
},
});
```
--------------------------------
### Manual Push Notification Setup for iOS (Swift)
Source: https://docs.userpilot.com/developer/installation/mobile/mobile-flutter
This Swift code provides a comprehensive manual setup for push notifications using the Userpilot SDK in an iOS application. It includes requesting user permission, registering for remote notifications, setting the push token with Userpilot, and handling notification responses. This is an extension to the AppDelegate class.
```swift
// AppDelegate+PushNotification.swift
import Foundation
import UserNotifications
import userpilot_flutter
extension AppDelegate {
/// Call from `UIApplicationDelegate.application(_:didFinishLaunchingWithOptions:)`
func setupPush(application: UIApplication) {
requestPushNotificationPermission()
// 1: Register to get a device token
application.registerForRemoteNotifications()
UNUserNotificationCenter.current().delegate = self
}
// MARK: - Push Notification Permission Request, In case you didn't request it from your Flutter app.
private func requestPushNotificationPermission() {
let options: UNAuthorizationOptions = [.alert, .sound, .badge]
// Check if the app has already been authorized
UNUserNotificationCenter.current().getNotificationSettings { (settings) in
if settings.authorizationStatus == .authorized {
// App is already authorized for push notifications
// Register for remote notifications again to get the device token
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
} else {
// If not authorized, request permission
UNUserNotificationCenter.current().requestAuthorization(options: options) { (granted, error) in
if granted {
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
} else {
if let errorDescription = error?.localizedDescription {
print("Permission denied or failed to request: \(errorDescription)")
} else {
print("Permission denied or failed to request: Unknown error")
}
}
}
}
}
}
// 2: Pass device token to Userpilot
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
UserpilotFlutterPlugin.setPushToken(deviceToken)
}
// 3: Pass the user's response to a delivered notification to Userpilot
override func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
if UserpilotFlutterPlugin.didReceiveNotification(response: response, completionHandler: completionHandler) {
return
}
```
--------------------------------
### Install Userpilot JavaScript SDK
Source: https://docs.userpilot.com/developer/installation/web
This snippet shows how to install the Userpilot JavaScript SDK directly into your website's HTML. It requires pasting a script tag at the beginning of the `` section. The `AppToken` is essential for initialization and can be found in the environment tab.
```javascript
```
```typescript
import { Userpilot } from 'userpilot'
// Initialize Userpilot
Userpilot.initialize('AppToken');
```
--------------------------------
### Configure Userpilot SDK Initialization
Source: https://docs.userpilot.com/developer/installation/mobile/mobile-ios
This section shows how to initialize the Userpilot SDK with custom configurations, including enabling logging, disabling push notification permission requests, and setting up navigation, analytics, and experience delegates. Examples are provided for Swift and Objective-C.
```swift
let userpilot = Userpilot(
config: Userpilot.Config(token: "APP_TOKEN")
.logging(true)
.disableRequestPushNotificationsPermission()
)
userpilot.navigationDelegate = self
userpilot.analyticsDelegate = self
userpilot.experienceDelegate = self
```
```objective-c
Config *config = [[Config alloc] initWithToken:@"APP_TOKEN"];
// Enable or disable logging
[config loggingWithEnabled:YES];
[config disableRequestPushNotificationsPermission];
Userpilot *userpilot = [[Userpilot alloc] initWithConfig:config];
userpilot.navigationDelegate = self;
userpilot.analyticsDelegate = self;
userpilot.experienceDelegate = self;
// Example - setup navigationDelegate
// in AppDelegate.h
#import
@import Userpilot;
@interface AppDelegate : UIResponder
@end
// in AppDelegate.m
#pragma mark - UserpilotNavigationDelegate
- (void)navigateTo:(NSURL *)url {
NSLog(@"Userpilot requested navigation to URL: %@", url.absoluteString);
// Example: open the URL externally in Safari
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
}
// Or if you want to handle specific URLs in-app, use conditionals here
// e.g., check url.host or pathComponents
}
#pragma mark - UserpilotExperienceDelegate
- (void)onExperienceStateChangedWithExperienceType:(UserpilotExperienceType)experienceType
experienceId:(NSNumber *)experienceId
experienceState:(UserpilotExperienceState)experienceState {
NSLog(@"Experience [%@] type: %ld changed state to: %ld",
experienceId, (long)experienceType, (long)experienceState);
}
- (void)onExperienceStepStateChangedWithExperienceType:(UserpilotExperienceType)experienceType
experienceId:(NSNumber *)experienceId
stepId:(NSNumber *)stepId
stepState:(UserpilotExperienceState)stepState
step:(NSNumber *)step
totalSteps:(NSNumber *)totalSteps {
NSLog(@"Step [%@] of experience [%@] (type: %ld) changed state to: %ld - step %ld/%ld",
stepId, experienceId, (long)experienceType, (long)stepState,
step.intValue, totalSteps.intValue);
}
#pragma mark - UserpilotAnalyticsDelegate
- (void)didTrackWithAnalytic:(UserpilotAnalytic)analytic
value:(NSString *)value
properties:(NSDictionary *)properties {
NSLog(@"Tracked event - type: %ld, value: %@, properties: %@", (long)analytic, value, properties);
}
```
--------------------------------
### Manual Push Notification Setup (Swift)
Source: https://docs.userpilot.com/developer/installation/mobile/mobile-cordova
This Swift code provides the initial steps for manually configuring push notifications with the Userpilot SDK. It includes requesting authorization, registering for remote notifications, and setting the UNUserNotificationCenter delegate. This is part of a larger setup process.
```swift
// AppDelegate+PushNotification.swift
import Foundation
import UserNotifications
import UserpilotReactNative
typealias UserpilotImplementation = Implementation
extension AppDelegate: UNUserNotificationCenterDelegate {
/// Call from `UIApplicationDelegate.application(_:didFinishLaunchingWithOptions:)`
func setupPush(application: UIApplication) {
requestPushNotificationPermission()
// 1: Register to get a device token
application.registerForRemoteNotifications()
UNUserNotificationCenter.current().delegate = self
}
// MARK: - Push Notification Permission Request, In case you didn't request it from your Cordova app.
private func requestPushNotificationPermission() {
let options: UNAuthorizationOptions = [.alert, .sound, .badge]
// Check if the app has already been authorized
UNUserNotificationCenter.current().getNotificationSettings { (settings) in
if settings.authorizationStatus == .authorized {
// App is already authorized for push notifications
// Register for remote notifications again to get the device token
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
} else {
// If not authorized, request permission
UNUserNotificationCenter.current().requestAuthorization(options: options) { (granted, error) in
if granted {
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
} else {
if let errorDescription = error?.localizedDescription {
print("Permission denied or failed to request: (errorDescription)")
} else {
print("Permission denied or failed to request: Unknown error")
}
}
}
}
}
}
// 2: Pass device token to Userpilot
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
```
--------------------------------
### Initialize Userpilot SDK in Ionic-Capacitor
Source: https://docs.userpilot.com/developer/installation/mobile/mobile-capacitor
Initializes the Userpilot SDK within your Ionic-Capacitor application. This one-time setup requires your application token and allows for optional configuration, such as enabling logging.
```javascript
import { Userpilot } from '@userpilot/capacitor';
Userpilot.initialize({ token: 'APP_TOKEN', config: { logging: true } })
```
--------------------------------
### Prepare Cordova Platforms
Source: https://docs.userpilot.com/developer/installation/mobile/mobile-cordova
Prepares the platforms for your Cordova application after installing or updating plugins.
```bash
cordova prepare
```
--------------------------------
### Initialize Userpilot SDK in Swift
Source: https://docs.userpilot.com/developer/installation/mobile/mobile-ios
Initialize the Userpilot SDK in your AppDelegate using Swift. This is a one-time setup required during app launch. Ensure you replace '' with your actual application token and configure logging as needed.
```swift
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var userpilot: Userpilot?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
userpilot = Userpilot(config: Userpilot.Config(token: "APP_TOKEN")
.logging(true) // Enable or disable logging
)
return true
}
}
```
--------------------------------
### Manual Push Notification Setup for iOS with Userpilot
Source: https://docs.userpilot.com/developer/installation/mobile/mobile-react-native
Manually sets up push notifications by registering for permissions, obtaining the device token, and handling notification responses. This involves implementing several delegate methods within your AppDelegate.swift file. Ensure Userpilot SDK is imported.
```swift
// AppDelegate+PushNotification.swift
import Foundation
import UserNotifications
import UserpilotReactNative
typealias UserpilotImplementation = Implementation
extension AppDelegate: UNUserNotificationCenterDelegate {
/// Call from `UIApplicationDelegate.application(_:didFinishLaunchingWithOptions:)`
func setupPush(application: UIApplication) {
requestPushNotificationPermission()
// 1: Register to get a device token
application.registerForRemoteNotifications()
UNUserNotificationCenter.current().delegate = self
}
// MARK: - Push Notification Permission Request, In case you didn't request it from your React Native app.
private func requestPushNotificationPermission() {
let options: UNAuthorizationOptions = [.alert, .sound, .badge]
// Check if the app has already been authorized
UNUserNotificationCenter.current().getNotificationSettings { (settings) in
if settings.authorizationStatus == .authorized {
// App is already authorized for push notifications
// Register for remote notifications again to get the device token
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
} else {
// If not authorized, request permission
UNUserNotificationCenter.current().requestAuthorization(options: options) { (granted, error) in
if granted {
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
} else {
if let errorDescription = error?.localizedDescription {
print("Permission denied or failed to request: \(errorDescription)")
} else {
print("Permission denied or failed to request: Unknown error")
}
}
}
}
}
}
// 2: Pass device token to Userpilot
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
UserpilotImplementation.setPushToken(deviceToken)
}
// 3: Pass the user's response to a delivered notification to Userpilot
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
if UserpilotImplementation.didReceiveNotification(response: response, completionHandler: completionHandler) {
return
}
completionHandler()
}
}
```
--------------------------------
### Install Userpilot JavaScript SDK via npm
Source: https://docs.userpilot.com/developer/installation/SDK-APIs
Installs the Userpilot SDK using npm. This is the recommended method for Node.js environments. It allows for direct import and initialization within your JavaScript application.
```bash
npm i userpilot
```
--------------------------------
### Install Userpilot React Native Module
Source: https://docs.userpilot.com/developer/installation/mobile/mobile-react-native
This command installs the Userpilot React Native Module using npm. Ensure you are in your app's root directory before running this command.
```bash
npm install @userpilot/react-native
```
--------------------------------
### Install iOS Pods
Source: https://docs.userpilot.com/developer/installation/mobile/mobile-react-native
After installing the Userpilot React Native Module, run this command within your application's 'ios' folder to install the necessary CocoaPods dependencies.
```bash
pod install
```
--------------------------------
### Install Userpilot via Cocoapods
Source: https://docs.userpilot.com/developer/installation/mobile/mobile-ios
Add the Userpilot dependency to your project's Podfile. This method requires Cocoapods to be installed and used for dependency management. Replace '' with the actual version number.
```bash
target 'YourTargetName' do
pod 'Userpilot', '~>'
end
```
--------------------------------
### Initialize Userpilot Flutter SDK
Source: https://docs.userpilot.com/developer/installation/mobile/mobile-flutter
Demonstrates the Dart code required to initialize the Userpilot Flutter SDK. It includes importing the necessary library, setting optional configurations like logging, and calling the `initialize` method with your application token.
```dart
import 'package:userpilot_flutter/userpilot_flutter.dart';
UserpilotOptions options = UserpilotOptions();
options.logging = true;
Userpilot.initialize("", options);
```
--------------------------------
### SDK Callbacks
Source: https://docs.userpilot.com/developer/installation/mobile/mobile-flutter
Userpilot SDK provides callbacks for Navigation, Analytics, and Experience events.
```APIDOC
## SDK Callbacks
### Description
Callbacks provided by the Userpilot SDK to listen for specific events.
### Navigation Listener
Triggered when a deep link is invoked from an experience or push notification.
#### Parameters
- **url** (string) - The custom deep link URL that should be handled by the host (client) app.
### Analytics Listener
Triggered when the client app reports an analytics event to the SDK.
#### Parameters
- **analytic** (string) - The name or type of the analytic event (e.g., "Identify", "Screen", "Event").
- **value** (string) - The value associated with the event.
- **properties** (object) - Additional key-value pairs providing context for the event.
### Experience Listener
Provides callbacks related to the lifecycle of experiences and their steps within the SDK.
#### Parameters
(Specific parameters depend on the lifecycle event being listened to.)
```
--------------------------------
### Trigger and End Userpilot Experiences
Source: https://docs.userpilot.com/developer/installation/mobile/mobile-ios
This snippet demonstrates how to programmatically trigger a specific user experience using its ID and how to end the current active experience. It includes examples for both Kotlin/Swift and Objective-C.
```kotlin
userpilot.triggerExperience("")
```
```swift
userpilot.triggerExperience("")
```
```objective-c
[userpilot triggerExperienceWithId:@""];
```
```kotlin
userpilot.endExperience()
```
```swift
userpilot.endExperience()
```
```objective-c
[userpilot endExperience];
```
--------------------------------
### Userpilot Initialization with Configurations
Source: https://docs.userpilot.com/developer/installation/mobile/mobile-ios
Initializes the Userpilot SDK with optional configurations such as logging, push notification permission handling, and delegate assignments for navigation, analytics, and experience events.
```APIDOC
## POST /initialize
### Description
Initializes the Userpilot SDK with optional configurations.
### Method
POST
### Endpoint
`/initialize`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **token** (string) - Required - Your application's Userpilot token.
- **logging** (boolean) - Optional - Enable or disable logs for SDK. Default: false.
- **disableRequestPushNotificationsPermission** (boolean) - Optional - Disable request push notifications permission by SDK. Default: false.
- **navigationHandler** (UserpilotNavigationDelegate) - Optional - Handle deep link navigation from experiences and push notifications.
- **analyticsDelegate** (UserpilotAnalyticsDelegate) - Optional - Broadcasts analytics events to external listeners for tracking and reporting.
- **experienceDelegate** (UserpilotExperienceDelegate) - Optional - Notify about the display of Experience content.
### Request Example
```json
{
"token": "APP_TOKEN",
"logging": true,
"disableRequestPushNotificationsPermission": true,
"navigationHandler": "",
"analyticsDelegate": "",
"experienceDelegate": ""
}
```
### Response
#### Success Response (200)
Indicates successful initialization of the Userpilot SDK.
#### Response Example
(No specific response body)
```
--------------------------------
### Initialize Userpilot SDK in Objective-C
Source: https://docs.userpilot.com/developer/installation/mobile/mobile-ios
Initialize the Userpilot SDK in your AppDelegate using Objective-C. This setup is performed once during application launch. Remember to substitute '' with your valid application token and manage logging preferences.
```objective-c
#import "Userpilot-Swift.h"
@interface AppDelegate : UIResponder
@property (strong, nonatomic) Userpilot *userpilot;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
Config *config = [[Config alloc] initWithToken:@"APP_TOKEN"];
[config loggingWithEnabled:YES]; // Enable or disable logging
self.userpilot = [[Userpilot alloc] initWithConfig:config];
return YES;
}
@end
```
--------------------------------
### Identify Users with Userpilot
Source: https://docs.userpilot.com/developer/installation/web
This section details how to identify users with Userpilot using the `userpilot.identify()` function. It covers both multi-page and single-page applications, including examples of passing user and company properties. The user ID is mandatory, while other properties are optional.
```javascript
```
```typescript
React.useEffect(() => {
if(isAuthenticated){
Userpilot.identify('456987',{
name: 'John Doe',
email: 'john@site-domain.com',
created_at: '2018-07-11',
});
}
}, [isAuthenticated]);
```
```typescript
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
constructor(
private userService: AuthService
) {
const token = localStorage.getItem('token');
if(token){
this.userService.getUser().subscribe((user) => {
if(user.id){
Userpilot.identify(user.id,{
name: user.name,
email: user.email,
created_at: user.created_at,
});
}
});
}
}
}
```
```typescript
export const authenticationGuard = (to, from, next) => {
const authService = getAuthService();
const guardAction = () => {
if (authService.isAuthenticated) {
const user = authService.getUser();
const company = getUserCompany(user.id);
window.userpilot.identify(
user.id,
{
name: user.name,
email: user.email,
created_at: user.created_at, // Signup date as a Unix timestamp,
company: { // optional
id: company.id, // Company Unique ID
created_at: company.created_at // Signup date as a Unix timestamp
},
// Additional user properties
// plan: user.plan,
// trialEnds: user.trial_ends
}
);
}
}
};
```
--------------------------------
### Userpilot Experience Listener
Source: https://docs.userpilot.com/developer/installation/mobile/mobile-ios
Implement the UserpilotExperienceDelegate protocol to receive callbacks regarding the lifecycle and state changes of Userpilot experiences (flows, surveys, NPS). This enables you to react to experience starts, completions, dismissals, and step progressions.
```APIDOC
## Userpilot Experience Listener
### Description
Implement the `UserpilotExperienceDelegate` protocol to monitor and respond to state changes within Userpilot experiences, such as flows, surveys, and NPS campaigns. This delegate provides insights into when experiences start, complete, are dismissed, or progress through their steps.
### Protocol
`UserpilotExperienceDelegate`
### Enums
- `UserpilotExperienceType`:
- `flow`: Represents a user flow experience.
- `survey`: Represents a survey experience.
- `nps`: Represents an NPS (Net Promoter Score) survey experience.
- `UserpilotExperienceState`:
- `started`: The experience or step has begun.
- `completed`: The experience or step has finished successfully.
- `dismissed`: The experience or step was closed by the user before completion.
- `skipped`: The experience or step was skipped.
- `submitted`: The experience or step's data was submitted.
### Methods
- `onExperienceStateChanged(experienceType: UserpilotExperienceType, experienceId: NSNumber?, experienceState: UserpilotExperienceState)`:
- **experienceType** (`UserpilotExperienceType`): The type of the experience.
- **experienceId** (`NSNumber?`): The unique identifier for the experience.
- **experienceState** (`UserpilotExperienceState`): The current state of the entire experience.
- `onExperienceStepStateChanged(experienceType: UserpilotExperienceType, experienceId: NSNumber, stepId: NSNumber, stepState: UserpilotExperienceState, step: NSNumber?, totalSteps: NSNumber?)`:
- **experienceType** (`UserpilotExperienceType`): The type of the experience.
- **experienceId** (`NSNumber`): The unique identifier for the experience.
- **stepId** (`NSNumber`): The unique identifier for the specific step.
- **stepState** (`UserpilotExperienceState`): The current state of the step.
- **step** (`NSNumber?`): The current step number within the experience.
- **totalSteps** (`NSNumber?`): The total number of steps in the experience.
### Usage
Assign an object conforming to this protocol to the relevant Userpilot SDK property to receive updates on experience and step states.
```
--------------------------------
### Install Userpilot Staging Token
Source: https://docs.userpilot.com/developer/installation/production-staging
This JavaScript snippet demonstrates how to install the Userpilot SDK with a staging token. It sets the `userpilotSettings` with the 'STG-' prefixed token and includes the Userpilot SDK script. This is used for testing content in a staging environment.
```javascript
```
--------------------------------
### Install Userpilot with Custom Domain (JavaScript)
Source: https://docs.userpilot.com/developer/custom-domain
This snippet shows how to modify the Userpilot installation script to use your custom domain. It requires setting the `userpilotSettings` object with your token and custom domain, followed by loading the SDK from your specified domain.
```javascript
window.userpilotSettings = {token: "Your token", domain: "mydomain.example.com"};
```
--------------------------------
### GET /websites/userpilot
Source: https://docs.userpilot.com/api-references/endpoints/bulk/companies
Retrieves a list of website configurations. This endpoint is useful for fetching all available website settings.
```APIDOC
## GET /websites/userpilot
### Description
Retrieves a list of website configurations. This endpoint is useful for fetching all available website settings.
### Method
GET
### Endpoint
/websites/userpilot
### Parameters
#### Query Parameters
- **start_time** (string) - Optional - The start time for filtering results.
- **status** (string) - Optional - Filters results by status. Allowed values: `queued`, `validating`, `processing`, `pending_refresh`, `completed`, `failed`.
- **type** (string) - Optional - Filters results by type.
### Request Example
```json
{
"example": ""
}
```
### Response
#### Success Response (200)
- **status** (string) - The status of the website configuration.
- **total_rows** (integer) - The total number of rows returned.
#### Response Example
```json
{
"example": "{\n \"start_time\": \"2023-10-27T10:00:00Z\",\n \"status\": \"completed\",\n \"total_rows\": 10,\n \"type\": \"website_config\"\n}"
}
```
```
--------------------------------
### Monitor Userpilot Experience States
Source: https://docs.userpilot.com/developer/installation/mobile/mobile-ios
Receives callbacks when Userpilot experiences start, complete, or are dismissed, and tracks step progression. Implement this to pipe data to destinations or react to user actions. It defines experience types, states, and delegate methods for state changes.
```swift
/// The Userpilot experience type.
@objc
public enum UserpilotExperienceType: Int {
case flow
case survey
case nps
}
/// The various states of a Userpilot experience.
@objc
public enum UserpilotExperienceState: Int {
/// Indicates that the experience/step has started.
case started
/// Indicates that the experience/step has been completed successfully.
case completed
/// Indicates that the experience/step was dismissed before completion.
case dismissed
/// Indicates that the experience/step was skipped.
case skipped
/// Indicates that the experience/step was Submitted.
case submitted
}
/// A protocol to observe and respond to state changes in Userpilot experiences.
@objc
public protocol UserpilotExperienceDelegate: AnyObject {
/// Called when the state of a Userpilot experience changes.
///
/// - Parameters:
/// - experienceType: The current experience type.
/// - experienceId: A unique identifier for the experience.
/// - experienceState: The current state of the experience.
func onExperienceStateChanged(
experienceType: UserpilotExperienceType,
experienceId: NSNumber?,
experienceState: UserpilotExperienceState
)
/// Called when the state of a specific step within a Userpilot experience changes.
///
/// - Parameters:
/// - experienceType: The current experience type.
/// - experienceId: A unique identifier for the experience.
/// - stepId: A unique identifier for the step.
/// - stepState: The current state of the step.
/// - step: The current step number in the experience.
/// - totalSteps: The total number of steps in the experience.
func onExperienceStepStateChanged(
experienceType: UserpilotExperienceType,
experienceId: NSNumber,
stepId: NSNumber,
stepState: UserpilotExperienceState,
step: NSNumber?,
totalSteps: NSNumber?
)
}
```
--------------------------------
### Configure Android Gradle Properties
Source: https://docs.userpilot.com/developer/installation/mobile/mobile-react-native
This snippet shows how to configure Android Gradle properties, specifically setting the compileSdk and minSdk versions, and the Android Gradle Plugin version. It's crucial for ensuring compatibility with the Userpilot SDK.
```kotlin
android {
compileSdk 35
defaultConfig {
minSdk 21
}
}
```
--------------------------------
### End Experience API
Source: https://docs.userpilot.com/developer/installation/mobile/mobile-flutter
Ends the currently active Userpilot experience.
```APIDOC
## POST /endExperience
### Description
Ends the current active Userpilot experience.
### Method
POST
### Endpoint
/endExperience
### Parameters
None
### Request Example
```json
{
"action": "endExperience"
}
```
### Response
#### Success Response (200)
- **status** (string) - Indicates the success of the operation.
#### Response Example
```json
{
"status": "success"
}
```
```