Tracking user activity
This is an archived version of documentation. You can find the current documentation for all platforms here.
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
To change the length of the timeout, pass the value in seconds to the sessionTimeout property of the library configuration YMMYandexMetricaConfiguration.
By default, the session timeout is 10 seconds. The minimum acceptable value for the sessionTimeout
property is 10 seconds.
// 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];
Copied to clipboard
To change the length of the timeout, pass the value in seconds to the sessionTimeout property of the library configuration YMMYandexMetricaConfiguration.
By default, the session timeout is 10 seconds. The minimum acceptable value for the sessionTimeout
property is 10 seconds.
// Creating an extended library configuration. let configuration = YMMYandexMetricaConfiguration.init(apiKey: "API key") // Setting the session timeout. configuration?.sessionTimeout = 15 // Initializing the AppMetrica SDK. YMMYandexMetrica.activate(with: configuration!)
Copied to clipboard
Tracking sessions manually
- 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];
Copied to clipboard - Set up session control using the methods +resumeSession: and +pauseSession:.
[YMMYandexMetrica resumeSession]; ... [YMMYandexMetrica pauseSession];
Copied to clipboard
+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];
Copied to clipboard