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.
Step 1. Enable the library
The library can work with the following dependency managers:
The library supports static and dynamic frameworks for CocoaPods.
To connect the crash-handling framework, add the following dependency to your project's Podfile:
Static framework
pod 'YandexMobileMetrica', '4.5.2'
Copied to clipboardExample 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.
To connect the library, add the following dependency to Cartfile
and save the file:
binary "https://raw.githubusercontent.com/yandexmobile/metrica-sdk-ios/master/YandexMobileMetrica.json" ~> 4.5.2
Copied to clipboard
To connect the library, follow these steps:
In Xcode, go to the Swift Packages tab for your project.
Specify the repository URL
https://github.com/yandexmobile/metrica-sdk-ios
, which contains a Swift package.Configure a rule for selecting the package version.
Restriction.Connection using Swift Package Manager is supported starting from version 3.14.0 of the AppMetrica SDK.
- Select the required libraries.
- Add
YandexMobileMetrica.framework
to the project. - (Optional) To enable crash handling, add
YandexMobileMetricaCrashes.framework
. - Add the following dependencies: 'SystemConfiguration', 'UIKit', 'Foundation', 'CoreTelephony', 'CoreLocation', 'CoreGraphics', 'AdSupport', 'z', 'sqlite3', 'Security', 'c++', 'WebKit', and 'SafariServices' (with the Optional setting).
- Add
-ObjC
toOther Linker Flags
.
To enable the library, follow these steps:
Step 2. Initialize the library
#import <YandexMobileMetrica/YandexMobileMetrica.h>
Initialize the library in the initialize
method of the NSExtensionPrincipalClass
extension:
+ (void)initialize { if ([self class] == [MMSTodayViewController class]) { // Initializing the AppMetrica SDK. YMMYandexMetricaConfiguration *configuration = [[YMMYandexMetricaConfiguration alloc] initWithApiKey:@"API_key"]; [YMMYandexMetrica activateWithConfiguration:configuration]; } }
Copied to clipboard
import YandexMobileMetrica
Initialize the library in the initialize
method of the NSExtensionPrincipalClass
extension:
override class func initialize() { if self === MMSTodayViewController.self { // Initializing the AppMetrica SDK. let configuration = YMMYandexMetricaConfiguration.init(apiKey: "API_key") YMMYandexMetrica.activate(with: configuration!) } }
Copied to clipboard
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.
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.
To track in-app purchases, set up Revenue sending. For more information, see In-App purchases.
Step 4. Test the library operation
- Start the app with the AppMetrica SDK and use it for a while.
- Make sure your device is connected to the internet.
Troubleshooting
- 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.
- The source code snippet that shows the SDK integration to your app.
- Application ID in the AppMetrica web interface.
- Device ID.
- Install the AppMetrica app on the test device.
- Log in and select your app from the list.
- In the upper-left corner, click.
- The Apple IDFA is shown in the IDFA field. Enter it in the AppMetrica web interface.
How to get an Apple IDFANote. You can enable attribution testing in the AppMetrica app. To do this, turn on Attribution testing. - Device model and manufacturer, platform and OS version, AppMetrica SDK version.
Check your session tracking settings. For more information, see Tracking user activity.