SDK integration

The SDK for iOS is provided as modules with source code.

Step 1. Enable the library

To connect the analytics library, add the following dependency to your project's Podfile:

pod 'AppMetricaAnalytics', '~> 5.9.0'
I have a children's app

If your app is intended for children, connect modules without the use of AppMetricaAdSupport:

pod 'AppMetricaCore', '~> 5.9.0'
pod 'AppMetricaCrashes', '~> 5.9.0'
pod 'AppMetricaWebKit', '~> 5.9.0'
I don't need all the features

If you don't need all the features of the AppMetrica SDK, connect only the required modules:

pod 'AppMetricaCore', '~> 5.9.0' # The main module for working with the AppMetrica SDK, mandatory for connection
pod 'AppMetricaAdSupport', '~> 5.9.0' # Required for collecting IDs. IDFAs won't be collected without it
pod 'AppMetricaCrashes', '~> 5.9.0' # The module for detecting crashes and sending errors
pod 'AppMetricaWebKit', '~> 5.9.0' # The module for setting up event sending from the WebView's JS code

Integration via the Xcode interface

To connect the library, follow these steps:

  1. In the Xcode project navigator (Project Navigator) window, select your project (if Workspace is used). In the top menu, click File and select Add Package Dependencies....

  2. Specify the repository URL https://github.com/appmetrica/appmetrica-sdk-ios.

  3. Leave only the required modules (to disable a module, select None in Add to Target):

    • AppMetricaCore: The mandatory main SDK module. It must be connected for working with AppMetrica.
    • AppMetricaAdSupport: The module is used to collect IDs, including IDFA.
    • AppMetricaCrashes: The module is intended for detecting crashes and sending errors.
    • AppMetricaWebKit: The module enables you to send events from JavaScript code in WebView.

    Note

    If your app is intended for children, connect modules without the use of AppMetricaAdSupport.

Integration via the Package.swift manifest

First, add the following dependency to the dependencies: array of your package:

dependencies: [
   .package(
      url: "https://github.com/appmetrica/appmetrica-sdk-ios",
      from: "5.9.0"
   )
],

The AppMetrica SDK modules that you can connect depending on the needs of your project:

  • AppMetricaCore: The mandatory main SDK module. It must be connected for working with AppMetrica.
  • AppMetricaAdSupport: The module is used to collect IDs, including IDFA.
  • AppMetricaCrashes: The module is intended for detecting crashes and sending errors.
  • AppMetricaWebKit: The module enables you to send events from JavaScript code in WebView.

Note

If your app is intended for children, connect modules without the use of AppMetricaAdSupport.

Example of connecting modules in the dependencies: array of the target:

.target(
   name: "MyTargetName",
   dependencies: [
      .product(name: "AppMetricaCore", package: "AppMetrica"),
      .product(name: "AppMetricaCrashes", package: "AppMetrica"),
      .product(name: "AppMetricaWebKit", package: "AppMetrica"),
      // .product(name: "AppMetricaAdSupport", package: "AppMetrica"), // This module is disabled
   ]
),

Step 2. Initialize the library

Add the import:

import AppMetricaCore

Initialize the library in the application(_:didFinishLaunchingWithOptions:) method of your UIApplicationDelegate:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
    // Initializing the AppMetrica SDK.
    let configuration = AppMetricaConfiguration(apiKey: "API key")
    AppMetrica.activate(with: configuration!)
}

Add the import:

#import <AppMetricaCore/AppMetricaCore.h>

Initialize the library in the application:didFinishLaunchingWithOptions: method of your UIApplicationDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Initializing the AppMetrica SDK.
    AMAAppMetricaConfiguration *configuration = [[AMAAppMetricaConfiguration alloc] initWithAPIKey:@"API key"];
    [AMAAppMetrica activateWithConfiguration:configuration];
    return YES;
}
What is the API key?

The API key is a unique app ID issued in the AppMetrica web interface at app registration. You can find it under Settings.

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

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

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

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

  3. 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 EngagementSessions report has increased.
    • There are events and profile attributes in the Events and Profiles reports.

Learn more

Troubleshooting

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.

Contact support