Installation and initialization

The AppMetrica library consists of two frameworks: core and crash-handling. If you don't use AppMetrica crash handling, add only the core part of the library. It reduces the size of the application.

The AppMetrica library supports the following platforms:
  1. Step 1. Enable the library
  2. Step 2. Initialize the library
  3. Step 3. (Optional) Configure sending events, profile attributes, and Revenue
  4. Step 4. Test the library operation

Step 1. Enable the library

The library can work with the following dependency managers:

The library supports static and dynamic frameworks for CocoaPods.

Note. To connect the AppMetrica SDK starting from 3.17.0, you need CocoaPods version 1.10 or higher.

To connect the crash-handling framework, add the following dependency to your project's Podfile:

  • Static framework

    pod 'YandexMobileMetrica', '4.5.2'
    Copied to clipboard

    Example of enabling a static framework on GitHub.

  • Dynamic framework

    pod 'YandexMobileMetrica/Dynamic', '4.5.2'
    Copied to clipboard

To enable the library without crash handling, use the YandexMobileMetrica/Static/Core or YandexMobileMetrica/Dynamic/Core dependency.

Note. If the Podfile has the line use_frameworks!, we recommend using the dynamic framework.
If you don't use these dependency managers

To enable the library, follow these steps:

  1. Add YandexMobileMetrica.framework to the project.
  2. (Optional) To enable crash handling, add YandexMobileMetricaCrashes.framework.
  3. Add the following dependencies: 'SystemConfiguration', 'UIKit', 'Foundation', 'CoreTelephony', 'CoreLocation', 'CoreGraphics', 'AdSupport', 'z', 'sqlite3', 'Security', 'c++', 'WebKit', and 'SafariServices' (with the Optional setting).
  4. Add -ObjC to Other Linker Flags.

Step 2. Initialize the library

Add the import:
#import <YandexMobileMetrica/YandexMobileMetrica.h>

Initialize the library in the initialize method in Main Entry Point of the extension (there may be multiple activation points):

+ (void)initialize 
{
    if ([self class] == [MMSInterfaceController class]) { 
        // Initializing the AppMetrica SDK.
        YMMYandexMetricaConfiguration *configuration = [[YMMYandexMetricaConfiguration alloc] initWithApiKey:@"API_key"];
        [YMMYandexMetrica activateWithConfiguration:configuration];
    }
}
Copied to clipboard

or

+ (void)initialize 
{ 
    if ([self class] == [MMSNotificationController class]) { 
        // Initializing the AppMetrica SDK.
        YMMYandexMetricaConfiguration *configuration = [[YMMYandexMetricaConfiguration alloc] initWithApiKey:@"API_key"];
        [YMMYandexMetrica activateWithConfiguration:configuration];
    }
}
Copied to clipboard
What is the API key?

The API key is a unique application identifier that is issued in the AppMetrica web interface during app registration.

Make sure you have entered it correctly.

AppMetrica allows tracking pre-installed apps. For more information, see Tracking pre-installed apps.

Note. Requirements: deployment target 8.0 and higher.

Step 3. (Optional) Configure sending events, profile attributes, and Revenue

To collect information on user actions in the app, set up sending your own events. For more information, see Sending your own events.

To collect information about users, set up sending profile attributes. For more information, see Profiles.

Note. Unlike events, a profile attribute can take only one value. When you send a new attribute value, the old value is overwritten.

To track in-app purchases, set up Revenue sending. For more information, see In-App purchases.

Step 4. Test the library operation

To test how the library works:
  1. Start the app with the AppMetrica SDK and use it for a while.
  2. Make sure your device is connected to the internet.
  3. In the AppMetrica interface, make sure that:
    • There is a new user in the Audience report.
    • The number of sessions in the Engagement → Sessions report has increased.
    • There are events and profile attributes in the Events and Profiles reports.

Troubleshooting

The number of sessions does not increase

Check your session tracking settings. For more information, see Tracking user activity.

There are no events in the report
  1. Perform a minimum of 10 app actions that trigger the event sending.

    It's necessary because AppMetrica accumulates events in the buffer and sends to the server in several parts.

  2. Wait for 10 minutes and check the report. Reports don't display events immediately.
Problems with Swift Package Manager
My problem is not listed
If your problem is not listed, contact support service. Specify the following:
  1. The source code snippet that shows the SDK integration to your app.
  2. Application ID in the AppMetrica web interface.
  3. Device ID.
    How to get an Apple IDFA
    1. Install the AppMetrica app on the test device.
    2. Log in and select your app from the list.
    3. In the upper-left corner, click  → Device Management.
    4. The Apple IDFA is shown in the IDFA field. Enter it in the AppMetrica web interface.
    Note. You can enable attribution testing in the AppMetrica app. To do this, turn on Attribution testing.
  4. Device model and manufacturer, platform and OS version, AppMetrica SDK version.

If you didn't find the answer you were looking for, you can use the feedback form to submit your question. Please describe the problem in as much detail as possible. Attach a screenshot if possible.