react-native-adapty - v3.15.2
    Preparing search index...

    Class Adapty

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

    Index

    Constructors

    Methods

    • Initializes the Adapty SDK.

      Parameters

      Returns Promise<void>

      A promise that resolves when the SDK is initialized.

      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.

      Basic usage in your app's entry point

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

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

    • Adds an event listener for the latest profile load event.

      Parameters

      • event: "onLatestProfileLoad"
      • callback: (data: AdaptyProfile) => void | Promise<void>

      Returns EmitterSubscription

    • Adds an event listener for successful installation details retrieval.

      Parameters

      Returns EmitterSubscription

    • Adds an event listener for installation details retrieval failures.

      Parameters

      • event: "onInstallationDetailsFail"
      • callback: (data: AdaptyError) => void | Promise<void>

      Returns EmitterSubscription

    • Enables mock mode.

      Parameters

      Returns void

      This method should be called before activate() if you want to test SDK methods without full activation (e.g., isActivated()). If bridge is already initialized, this method does nothing.

      Important: Mock mode cannot be disabled at runtime. To switch back to production mode, you need to restart the app.

      adapty.enableMock({ profile: { ... } });
      const isActivated = await adapty.isActivated(); // false
      await adapty.activate('api_key');
    • Gets the current installation status.

      Returns Promise<AdaptyInstallationStatus>

      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.

      AdaptyError If an error occurs while retrieving the installation status.

      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) {
      // handle error
      }
    • Fetches the paywall by the specified placement.

      Parameters

      • placementId: string

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

      • Optionallocale: string

        The locale of the desired paywall.

      • Optionalparams: GetPlacementParamsInput = ...

        Additional parameters for retrieving paywall.

      Returns Promise<AdaptyPaywall>

      A promise that resolves with a requested paywall.

      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.

      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 the paywall of the specified placement for the All Users audience.

      Parameters

      • placementId: string

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

      • Optionallocale: string

        The locale of the desired paywall.

      • Optionalparams: GetPlacementForDefaultAudienceParamsInput = ...

        Additional parameters for retrieving paywall.

      Returns Promise<AdaptyPaywall>

      A promise that resolves with a requested paywall.

      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.

      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 docs for more details

      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>

      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 Model.AdaptyProfile cache on a regular basis, in order to keep this information as up-to-date as possible.

    • Type Parameters

      • T

      Parameters

      • method:
            | "activate"
            | "adapty_ui_activate"
            | "adapty_ui_create_paywall_view"
            | "adapty_ui_dismiss_paywall_view"
            | "adapty_ui_present_paywall_view"
            | "adapty_ui_show_dialog"
            | "adapty_ui_create_onboarding_view"
            | "adapty_ui_dismiss_onboarding_view"
            | "adapty_ui_present_onboarding_view"
            | "create_web_paywall_url"
            | "get_current_installation_status"
            | "is_activated"
            | "get_paywall"
            | "get_paywall_for_default_audience"
            | "get_paywall_products"
            | "get_onboarding"
            | "get_onboarding_for_default_audience"
            | "get_profile"
            | "identify"
            | "log_show_paywall"
            | "logout"
            | "make_purchase"
            | "open_web_paywall"
            | "present_code_redemption_sheet"
            | "report_transaction"
            | "restore_purchases"
            | "set_fallback"
            | "set_integration_identifiers"
            | "set_log_level"
            | "update_attribution_data"
            | "update_collecting_refund_data_consent"
            | "update_profile"
            | "update_refund_preference"
      • params: string
      • resultType:
            | "AdaptyError"
            | "AdaptyPaywall"
            | "AdaptyRemoteConfig"
            | "AdaptyProfile"
            | "AdaptyPurchaseResult"
            | "AdaptyOnboarding"
            | "AdaptyInstallationStatus"
            | "AdaptyInstallationDetails"
            | "AdaptyPaywallProduct"
            | "AdaptyPaywallBuilder"
            | "AdaptyUiView"
            | "AdaptyUiDialogActionType"
            | "AdaptyUiOnboardingMeta"
            | "AdaptyUiOnboardingStateParams"
            | "AdaptyUiOnboardingStateUpdatedAction"
            | "Array<AdaptyPaywallProduct>"
            | "BridgeError"
            | "String"
            | "Boolean"
            | "Void"
      • 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

      • Optionalparams: IdentifyParamsInput

        Additional parameters for identification

      Returns Promise<void>

    • 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

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

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

      All available promotions will be applied automatically.

      Parameters

      Returns Promise<AdaptyPurchaseResult>

      A Promise that resolves to the Model.AdaptyPurchaseResult object containing details about the purchase. If the result is 'success', it also includes the updated user's profile.

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

      If an error occurs during the purchase process or while decoding the response from the native SDK.

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

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

      Returns Promise<void>

      iOS 14+ only.

    • 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>

    • Sets the fallback paywalls.

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

      Parameters

      Returns Promise<void>

      resolves when fallback placements are saved

    • Parameters

      • key: string
      • value: string

      Returns Promise<void>

    • 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

      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.

      AdaptyError if the log level is invalid

    • Updates an attribution data for the current user.

      Parameters

      • attribution: Record<string, any>

        An object containing attribution data.

      • source: string

        The source of the attribution data.

      Returns Promise<void>

      A promise that resolves when the attribution data is updated.

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

      adapty.updateAttribution(attribution, 'adjust');

      AdaptyError Throws if parameters are invalid or not provided.

    • Parameters

      • consent: boolean

      Returns Promise<void>