Adds an event listener for SDK events.
You can listen to various events from the Adapty SDK such as profile updates. The listener will be called whenever the corresponding event occurs.
Listen to profile updates
import { adapty } from '@adapty/capacitor';
const listener = adapty.addListener('onLatestProfileLoad', (profile) => {
console.log('Profile updated:', profile);
const isSubscribed = profile.accessLevels['YOUR_ACCESS_LEVEL']?.isActive;
if (isSubscribed) {
console.log('User has premium access');
}
});
// Later, remove the listener
listener.remove();
Initializes the Adapty SDK.
The activation options
You can find it in your app settings in Adapty Dashboard App settings > General.
Optionalparams?: ActivateParamsInputOptional activation parameters of type ActivateParamsInput.
A promise that resolves when the SDK is activated.
This method must be called in order for the SDK to work. It is preferred to call it as early as possible in the app lifecycle, so background activities can be performed and cache can be updated.
Creates a URL for a web paywall.
The options object
The paywall or product to create a URL for.
A promise that resolves with the web paywall URL.
This method generates a URL that can be used to open a web version of the paywall. You can use this URL in a custom web view or a browser.
import { adapty } from '@adapty/capacitor';
try {
const paywall = await adapty.getPaywall({ placementId: 'YOUR_PLACEMENT_ID' });
const url = await adapty.createWebPaywallUrl({ paywallOrProduct: paywall });
console.log('Web paywall URL:', url);
} catch (error) {
console.error('Failed to create web paywall URL:', error);
}
Gets the current installation status.
A promise that resolves with the installation status.
Installation status provides information about when the app was installed, how many times it has been launched, and other installation-related details. The status can be "not_available", "not_determined", or "determined" with details.
import { adapty } from '@adapty/capacitor';
try {
const status = await adapty.getCurrentInstallationStatus();
if (status.status === 'determined') {
console.log('Install time:', status.details.installTime);
console.log('Launch count:', status.details.appLaunchCount);
}
} catch (error) {
console.error('Failed to get installation status:', error);
}
Fetches the onboarding by the specified placement.
The options for fetching the onboarding
The identifier of the desired placement.
Optional. The identifier of the onboarding localization. Default: 'en'.
Optional. Additional parameters for fetching the onboarding.
A promise that resolves with the requested AdaptyOnboarding.
When you create an onboarding with the no-code builder, it's stored as a container with configuration that your app needs to fetch and display. This container manages the entire experience - what content appears, how it's presented, and how user interactions are processed.
import { adapty } from '@adapty/capacitor';
try {
const onboarding = await adapty.getOnboarding({
placementId: 'YOUR_PLACEMENT_ID',
locale: 'en',
params: {
fetchPolicy: 'reload_revalidating_cache_data',
loadTimeoutMs: 5000
}
});
console.log('Onboarding fetched successfully');
} catch (error) {
console.error('Failed to fetch onboarding:', error);
}
Fetches the onboarding of the specified placement for the All Users audience.
The options for fetching the onboarding
The identifier of the desired placement.
Optional. The identifier of the onboarding localization. Default: 'en'.
Optional. Additional parameters for fetching the onboarding.
A promise that resolves with the requested AdaptyOnboarding.
It's crucial to understand that the recommended approach is to fetch the onboarding
by the getOnboarding method. The getOnboardingForDefaultAudience method
should be used only if faster fetching outweighs the drawbacks:
Fetches the paywall by the specified placement.
The options for fetching the paywall
The identifier of the desired placement. This is the value you specified when creating a placement in the Adapty Dashboard.
Optional. The identifier of the paywall localization. Default: 'en'. See Localizations and locale codes for more information.
Optional. Additional parameters for fetching the paywall, including fetch policy and load timeout.
A promise that resolves with the requested AdaptyPaywall.
With Adapty, you can remotely configure the products and offers in your app by simply adding them to paywalls – no need for hardcoding them. The only thing you hardcode is the placement ID. This flexibility allows you to easily update paywalls, products, and offers, or run A/B tests, all without the need for a new app release.
Fetches the paywall of the specified placement for the All Users audience.
The options for fetching the paywall
The identifier of the desired placement.
Optional. The identifier of the paywall localization. Default: 'en'.
Optional. Additional parameters for fetching the paywall.
A promise that resolves with the requested AdaptyPaywall.
With Adapty, you can remotely configure the products and offers in your app by simply adding them to paywalls – no need for hardcoding them. The only thing you hardcode is the placement ID.
However, it's crucial to understand that the recommended approach is to fetch the paywall
through the placement ID by the getPaywall method.
The getPaywallForDefaultAudience method should be a last resort due to its significant drawbacks:
See documentation for more details.
Fetches a list of products associated with a provided paywall.
The options object
A paywall to fetch products for. You can get it using getPaywall method.
A promise that resolves with a list of AdaptyPaywallProduct associated with a provided paywall.
import { adapty } from '@adapty/capacitor';
try {
const paywall = await adapty.getPaywall({ placementId: 'YOUR_PLACEMENT_ID' });
const products = await adapty.getPaywallProducts({ paywall });
console.log('Products:', products);
} catch (error) {
console.error('Failed to fetch products:', error);
}
Fetches a user profile.
A promise that resolves with the user's AdaptyProfile.
The getProfile method provides the most up-to-date result as it always tries to query the API. If for some reason (e.g. no internet connection), the Adapty SDK fails to retrieve information from the server, the data from cache will be returned. It is also important to note that the Adapty SDK updates AdaptyProfile cache on a regular basis, in order to keep this information as up-to-date as possible.
import { adapty } from '@adapty/capacitor';
try {
const profile = await adapty.getProfile();
const isSubscribed = profile.accessLevels['YOUR_ACCESS_LEVEL']?.isActive;
if (isSubscribed) {
console.log('User has access to premium features');
}
} catch (error) {
console.error('Failed to get profile:', error);
}
Logs in a user with a provided customerUserId.
The identification options
A unique user identifier.
Optionalparams?: IdentifyParamsInputOptional. Additional parameters for identification, including platform-specific settings.
A promise that resolves when identification is complete.
Logs out the current user.
A promise that resolves when the user is logged out.
You can then login the user using identify method.
Logs a paywall view event.
The options object
The paywall object that was shown to the user.
A promise that resolves when the event is logged.
Adapty helps you to measure the performance of the paywalls. We automatically collect all the metrics related to purchases except for custom paywall views. This is because only you know when the paywall was shown to a customer.
Whenever you show a paywall to your user, call this function to log the event, and it will be accumulated in the paywall metrics.
Performs a purchase of the specified product.
The purchase options
The product to be purchased. You can get it using getPaywallProducts method.
Optional. Additional parameters for the purchase, including Android subscription update params.
A promise that resolves with the AdaptyPurchaseResult object containing details about the purchase.
If the result is 'success', it also includes the updated user's profile.
In paywalls built with Paywall Builder, purchases are processed automatically with no additional code.
Basic purchase
import { adapty } from '@adapty/capacitor';
try {
const result = await adapty.makePurchase({ product });
if (result.type === 'success') {
const isSubscribed = result.profile?.accessLevels['YOUR_ACCESS_LEVEL']?.isActive;
if (isSubscribed) {
console.log('User is now subscribed!');
}
}
} catch (error) {
console.error('Purchase failed:', error);
}
Opens a web paywall in the default browser.
The options object
The paywall or product to open as a web paywall.
A promise that resolves when the web paywall is opened.
Opens a native modal screen to redeem Apple Offer Codes.
A promise that resolves when the redemption sheet is presented.
Removes all attached event listeners.
A promise that resolves when all listeners are removed.
This method removes all event listeners that were added via addListener. It's recommended to call this method when cleaning up resources, such as when unmounting a component.
Sets the variation ID of the purchase.
The options object
The transaction ID of the purchase.
OptionalvariationId?: stringOptional. The variation ID from the AdaptyPaywall.
A promise that resolves when the transaction is reported.
Restores user purchases and updates the profile.
A promise that resolves with the updated user's AdaptyProfile.
Restoring purchases allows users to regain access to previously purchased content, such as subscriptions or in-app purchases, without being charged again. This feature is especially useful for users who may have uninstalled and reinstalled the app or switched to a new device.
In paywalls built with Paywall Builder, purchases are restored automatically without additional code from you.
import { adapty } from '@adapty/capacitor';
try {
const profile = await adapty.restorePurchases();
const isSubscribed = profile.accessLevels['YOUR_ACCESS_LEVEL']?.isActive;
if (isSubscribed) {
console.log('Access restored successfully!');
} else {
console.log('No active subscriptions found');
}
} catch (error) {
console.error('Failed to restore purchases:', error);
}
Sets the fallback paywalls.
The options object
The location of the fallback file for each platform.
A promise that resolves when fallback placements are saved.
Sets an integration identifier for the current user.
The options object
The key of the integration identifier.
The value of the integration identifier.
A promise that resolves when the integration identifier is set.
Sets the preferred log level and/or custom logger configuration.
A promise that resolves when the log level is set.
By default, the log level is set to error.
There are four levels available:
error: only errors will be loggedwarn: messages from the SDK that do not cause critical errors, but are worth paying attention toinfo: various information messages, such as those that log the lifecycle of various modulesverbose: any additional information that may be useful during debugging, such as function calls, API queries, etc.Updates attribution data for the current user.
The options object
An object containing attribution data.
The source of the attribution data (e.g., 'adjust', 'appsflyer').
A promise that resolves when the attribution data is updated.
import { adapty } from '@adapty/capacitor';
try {
const attribution = {
'Adjust Adid': 'adjust_adid',
'Adjust Network': 'adjust_network',
'Adjust Campaign': 'adjust_campaign',
'Adjust Adgroup': 'adjust_adgroup',
};
await adapty.updateAttribution({ attribution, source: 'adjust' });
} catch (error) {
console.error('Failed to update attribution:', error);
}
Updates the user's consent for collecting refund data.
The options object
Whether to collect refund data.
A promise that resolves when the consent is updated (or immediately on Android).
Updates a profile for the current user.
An object of parameters to update. Partial AdaptyProfileParameters.
A promise that resolves when the profile is updated.
You can set optional attributes such as email, phone number, etc. to the user of your app. You can then use attributes to create user segments or just view them in CRM.
The attributes that you've previously set won't be reset.
Custom attributes can be removed by passing null as their values.
Basic profile update
import { adapty } from '@adapty/capacitor';
try {
await adapty.updateProfile({
email: '[email protected]',
phoneNumber: '+18888888888',
firstName: 'John',
lastName: 'Appleseed',
gender: 'other',
birthday: new Date().toISOString(),
});
console.log('Profile updated successfully');
} catch (error) {
console.error('Failed to update profile:', error);
}
Updates the user's refund preference.
The options object
The refund preference setting.
A promise that resolves when the preference is updated (or immediately on Android).
Entry point for the Adapty SDK.
Remarks
This is the main Adapty class, excluding UI rendering functionality.