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.8.1'
I have a children's app
If your app is intended for children, connect modules without the use of AppMetricaAdSupport
:
pod 'AppMetricaCore', '~> 5.8.1'
pod 'AppMetricaCrashes', '~> 5.8.1'
pod 'AppMetricaWebKit', '~> 5.8.1'
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.8.1' # The main module for working with the AppMetrica SDK, mandatory for connection
pod 'AppMetricaAdSupport', '~> 5.8.1' # Required for collecting IDs. IDFAs won't be collected without it
pod 'AppMetricaCrashes', '~> 5.8.1' # The module for detecting crashes and sending errors
pod 'AppMetricaWebKit', '~> 5.8.1' # 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:
-
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....
-
Specify the repository URL
https://github.com/appmetrica/appmetrica-sdk-ios
. -
Leave only the required modules (to disable a module, select
None
inAdd 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.8.1"
)
],
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
-
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:
- Start the app with the AppMetrica SDK and use it for a while.
- Make sure your device is connected to the internet.
- In the AppMetrica interface, make sure that:
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
-
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.
-
Wait for 10 minutes and check the report. Reports don't display events immediately.
Problems with Swift Package Manager
Read the articles 'Library Not Found' error when you launch the app on your device and Error installing library on the device.
My problem is not listed
If your problem is not listed, contact support service. Specify the following:
-
The source code snippet that shows the SDK integration to your app.
-
Application ID in the AppMetrica web interface.
-
Device ID.
How to get Apple IDFA
-
Install the AppMetrica app on the test device.
-
Log in and select your app from the list.
-
In the upper-left corner, click → Device.
-
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. Enable Attribution testing for that.
-
-
Device model and manufacturer, platform and OS version, AppMetrica SDK version.
Learn more
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.