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

Hierarchy

Constructors

Properties

addEventListener: Fn = ...

Methods

  • Initializes the Adapty SDK.

    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

    useEffect(() => {
    adapty.activate('YOUR_API_KEY'); // <-- pass your API key here (required)
    }, []);

    Usage with your user identifier from your system

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

    Returns

    A promise that resolves when the SDK is initialized.

    Throws

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

    Parameters

    Returns Promise<void>

  • Fetches a paywall by its developer ID.

    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.

    Returns

    A promise that resolves with a requested paywall.

    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

    Parameters

    • id: string

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

    • Optional locale: string

      The locale of the desired paywall.

    Returns Promise<AdaptyPaywall>

  • Fetches a user profile. Allows you to define the level of access, as well as other parameters.

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

    Returns

    Throws

    AdaptyError

    Returns Promise<AdaptyProfile>

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

    Throws

    AdaptyError

    Parameters

    • customerUserId: string

      unique user id

    Returns Promise<void>

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

    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');
    

    Returns

    resolves when the event is logged

    Throws

    AdaptyError

    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>

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

    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);

    Returns

    resolves when the event is logged

    Parameters

    Returns Promise<void>

  • Performs a purchase of the specified product.

    All the available promotions will be applied automatically.

    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.

    Returns

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

    Throws

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

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

    Parameters

    Returns Promise<AdaptyProfile>

  • Opens a native modal screen to redeem Apple Offer Codes. iOS 14+ only.

    Returns Promise<void>

  • Returns

    resolves when fallback paywalls are saved

    Parameters

    • paywalls: string

    Returns Promise<void>

  • Logs errors and other important information to help you understand what is going on.

    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.

    Returns

    resolves when the log level is set

    Throws

    AdaptyError if the log level is invalid

    Parameters

    • logLevel: LogLevel

      new preferred log level

    Returns Promise<void>

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

    Throws

    AdaptyError

    Parameters

    • variationId: string

      variationId property of Model.AdaptyPaywall

    • transactionId: string

      transactionId property of Model.AdaptyPurchase

    Returns Promise<void>

  • Updates an attribution data for the current user.

    Example

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

    adapty.updateAttribution(attribution, 'adjust');

    Returns

    A promise that resolves when the attribution data is updated.

    Throws

    AdaptyError Throws if parameters are invalid or not provided.

    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>

  • Blocks the current thread until the SDK is initialized.

    Remarks

    Applied automatically to all methods if lockMethodsUntilReady is set to true in activate.

    Returns

    A promise that resolves when the SDK is initialized.

    Throws

    AdaptyError same error as activation or error if SDK is not activated

    Returns Promise<void>

Generated using TypeDoc