Tracking user activity

A single AppMetrica session is a certain period of the user interacting with your app.

In a standard scenario, a new session begins if the user returns to your app when a significant amount of time has passed since the app switched to background mode (the user hid the app or opened system settings).

Setting the length of the session timeout

By default, the session timeout is 10 seconds. The minimum acceptable value for the sessionTimeout property is 10 seconds.

To change the length of the timeout, pass the value in seconds to the sessionTimeout property of the library configuration YMMYandexMetricaConfiguration.

// Creating an extended library configuration.
YMMYandexMetricaConfiguration *configuration = [[YMMYandexMetricaConfiguration alloc] initWithApiKey:API_key];
// Setting the session timeout.
configuration.sessionTimeout = 15;
// Initializing the AppMetrica SDK.
[YMMYandexMetrica activateWithConfiguration:configuration];

Tracking sessions manually

AppMetrica automatically tracks the lifecycle of applications by default. To track sessions manually:
  1. Initialize the library with automatic session tracking disabled sessionsAutoTracking.
    // Creating an extended library configuration.
    YMMYandexMetricaConfiguration *configuration = [[YMMYandexMetricaConfiguration alloc] initWithApiKey:API_key];
    // Disabling automatic tracking user activity.
    configuration.sessionsAutoTracking = NO;
    ...
    // Initializing the AppMetrica SDK.
    [YMMYandexMetrica activateWithConfiguration:configuration];
  2. Set up session control using the methods +resumeSession: and +pauseSession:.
    [YMMYandexMetrica resumeSession];
    ...
    [YMMYandexMetrica pauseSession];
When using manual tracking, make sure that the current active session always ends with the +pauseSession: method invoke. If you don't invoke the +pauseSession: method the session will be ended the next time the app is launched.

For correct tracking, the reporters should be manually configured to send events about the start and the pause of the session for each reporter:

id<YMMYandexMetricaReporting> reporter = [YMMYandexMetrica reporterForApiKey:API_key];
[reporter resumeSession];
...
[reporter reportEvent:@"Updates installed" onFailure:^(NSError *error) {
    NSLog(@"REPORT ERROR: %@", [error localizedDescription]);
}];
...
[reporter pauseSession];