Entry point for the Adapty SDK. All Adapty methods are available through this class.

Hierarchy

  • Adapty

Constructors

Properties

addEventListener: AddListenerFn = ...

Adds a event listener for native event

Methods

  • Initializes the Adapty SDK.

    Parameters

    Returns Promise<void>

    A promise that resolves when the SDK is initialized.

    Remarks

    This method must be called in order for the SDK to work. It is preffered to call it as early as possible in the app lifecycle, so background activities can be performed and cache can be updated.

    Example

    Basic usage in your app's entry point

     adapty.activate('YOUR_API_KEY'); // <-- pass your API key here (required)
    

    Usage with your user identifier from your system

    adapty.activate('YOUR_API_KEY', { // <-- pass your API key here (required)
    customerUserId: 'YOUR_USER_ID' // <-- pass your user identifier here (optional)
    });

    Throws

    AdaptyError Usually throws if the SDK is already activated or if the API key is invalid.

  • Fetches a paywall by its developer ID.

    Parameters

    • placementId: string

      The identifier of the desired placement. This is the value you specified when you created the placement in the Adapty Dashboard.

    • Optional locale: string

      The locale of the desired paywall.

    • Optional params: GetPaywallParamsInput = ...

      Additional parameters for retrieving paywall.

    Returns Promise<AdaptyPaywall>

    A promise that resolves with a requested paywall.

    Remarks

    Adapty allows you remotely configure the products that will be displayed in your app. This way you don’t have to hardcode the products and can dynamically change offers or run A/B tests without app releases.

    Throws

    AdaptyError Throws an error:

    1. if the paywall with the specified ID is not found
    2. if your bundle ID does not match with your Adapty Dashboard setup
  • Fetches a user profile.

    Allows you to define the level of access, as well as other parameters.

    Returns Promise<AdaptyProfile>

    Remarks

    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.

    Throws

    AdaptyError

  • Type Parameters

    • T

    Parameters

    • method: "activate" | "get_paywall" | "get_paywall_products" | "get_products_introductory_offer_eligibility" | "get_profile" | "identify" | "log_show_onboarding" | "log_show_paywall" | "logout" | "make_purchase" | "not_implemented" | "present_code_redemption_sheet" | "restore_purchases" | "set_fallback_paywalls" | "set_log_level" | "set_variation_id" | "update_attribution" | "update_profile" | "__test__"
    • params: ParamMap
    • ctx: LogContext
    • log: LogScope

    Returns Promise<T>

  • Logs in a user with a provided customerUserId.

    If you don't have a user id on SDK initialization, you can set it later at any time with this method. The most common cases are after registration/authorization when the user switches from being an anonymous user to an authenticated user.

    Parameters

    • customerUserId: string

      unique user id

    Returns Promise<void>

    Throws

    AdaptyError

  • Logs an onboarding screen view event.

    In order for you to be able to analyze user behavior at this critical stage without leaving Adapty, we have implemented the ability to send dedicated events every time a user visits yet another onboarding screen.

    Parameters

    • screenOrder: number

      The number of the screen that was shown to the user.

    • Optional onboardingName: string

      The name of the onboarding.

    • Optional screenName: string

      The name of the screen.

    Returns Promise<void>

    resolves when the event is logged

    Remarks

    Even though there is only one mandatory parameter in this function, we recommend that you think of names for all the screens, as this will make the work of analysts during the data examination phase much easier.

    Example

    adapty.logShowOnboarding(1, 'onboarding_name', 'screen_name');
    

    Throws

    AdaptyError

  • Logs a paywall view event.

    Adapty helps you to measure the performance of the paywalls. We automatically collect all the metrics related to purchases except for paywall views. This is because only you know when the paywall was shown to a customer.

    Parameters

    Returns Promise<void>

    resolves when the event is logged

    Remarks

    Whenever you show a paywall to your user, call this function to log the event, and it will be accumulated in the paywall metrics.

    Example

    const paywall = await adapty.getPaywall('paywall_id');
    // ...after opening the paywall
    adapty.logShowPaywall(paywall);
  • Performs a purchase of the specified product.

    All the available promotions will be applied automatically.

    Parameters

    Returns Promise<AdaptyProfile>

    A Promise that resolves to an AdaptyProfile object containing the user's profile information after the purchase is made.

    Remarks

    Successful purchase will also result in a call to 'onLatestProfileLoad' listener. You can use addEventListener to subscribe to this event and handle the purchase result outside of this thread.

    Throws

    If an error occurs during the purchase process or while decoding the response from the native SDK. Some of the possible errors are:

    • #1006 — User has cancelled

    Example

    try {
    const paywall = await adapty.getPaywall('onboarding');
    const products = await adapty.getPaywallProducts(paywall);
    const product = products[0];

    const profile = await adapty.makePurchase(product);
    // successfull purchase
    } catch (error) {
    // handle error
    }
  • Opens a native modal screen to redeem Apple Offer Codes.

    Returns Promise<void>

    Remarks

    iOS 14+ only.

  • Sets the fallback paywalls.

    Fallback paywalls will be used if the SDK fails to fetch the paywalls from the dashboard. It is not designed to be used for the offline flow, as products are not cached in Adapty.

    Parameters

    • paywalls: string

    Returns Promise<void>

    resolves when fallback paywalls are saved

  • Sets the preferred log level.

    By default, the log level is set to error.

    Parameters

    • logLevel: LogLevel

      new preferred log level

    Returns Promise<void>

    resolves when the log level is set

    Remarks

    There are four levels available: error: only errors will be logged warn: messages from the SDK that do not cause critical errors, but are worth paying attention to info: various information messages, such as those that log the lifecycle of various modules verbose: any additional information that may be useful during debugging, such as function calls, API queries, etc.

    Throws

    AdaptyError if the log level is invalid

  • Sets the variation ID of the purchase.

    In Observer mode, Adapty SDK doesn't know, where the purchase was made from. If you display products using our Paywalls or A/B Tests, you can manually assign variation to the purchase. After doing this, you'll be able to see metrics in Adapty Dashboard.

    Parameters

    Returns Promise<void>

    Throws

    AdaptyError

  • Updates an attribution data for the current user.

    Parameters

    • attribution: Record<string, any>

      An object containing attribution data.

    • source: AttributionSource

      The source of the attribution data.

    • Optional networkUserId: string

      The network user ID.

    Returns Promise<void>

    A promise that resolves when the attribution data is updated.

    Example

    const attribution = {
    'Adjust Adid': 'adjust_adid',
    'Adjust Network': 'adjust_network',
    'Adjust Campaign': 'adjust_campaign',
    'Adjust Adgroup': 'adjust_adgroup',
    };

    adapty.updateAttribution(attribution, 'adjust');

    Throws

    AdaptyError Throws if parameters are invalid or not provided.

  • Updates a profile for the current user.

    Parameters

    Returns Promise<void>

    Throws

    AdaptyError If parameters are invalid or there is a network error.

    Example

    const profile = {
    email: '[email protected]',
    phone: '+1234567890',
    };

    await adapty.updateProfile(profile);

Generated using TypeDoc