YMMYandexMetrica class

Methods of the class are used for configuring the library.

Instance methods

activateWithConfiguration(_:)

Initializes the library in an application with the extended startup configuration.

activateReporterWithConfiguration(_:)

Initializes a reporter with extended configuration.

handleOpenURL(_:)

Processes the URL that opened the application.

libraryVersion()

Returns the current version of the AppMetrica library.

reporterForApiKey(_:)

Creates a reporter for sending events to an additional API key.

reportError(_:exception:onFailure:)

Sends a custom error message.

reportEvent(_:onFailure:)

Sends an event message.

reportEvent(_:params:onFailure:)

Sends an event message with additional parameters.

reportReferralUrl(_:)

Sets referral URL for app installs. This method can be used to track some traffic sources.

reportRevenue(_:onFailure:)

Sends information about the purchase to the AppMetrica server.

reportUserProfile(_:onFailure:)

Sends information about the user profile update to the AppMetrica server.

requestAppMetricaDeviceIDWithCompletionQueue(_:block:)

Requests the unique AppMetrica ID (deviceID).

sendEventsBuffer()

Sends stored events from the buffer.

setLocation(_:)

Sets custom location of the device.

setLocationTracking(_:)

Enables/disables sending location of the device .

setStatisticsSending(_:)

Enables/disables sending statistics to the AppMetrica server.

setUserProfileID(_:)

Sets the ID of the user profile.

Method descriptions

activateWithConfiguration(_:)

class func activateWithConfiguration(_ configuration: YMMYandexMetricaConfiguration)

Initializes the library in an application with the extended startup configuration.

Parameters:
configuration

The instance of the YMMYandexMetricaConfiguration class which contains the extended startup configuration for the library.

activateReporterWithConfiguration(_:)

class func activateReporterWithConfiguration(_ configuration: YMMReporterConfiguration)

Initializes a reporter with extended configuration.

The configuration of the reporter should be initialized before the first call to the reporter. Otherwise, the configuration of the reporter is ignored.

The reporter should be activated with the configuration using a different API key instead of the app's API key.

Parameters:
configuration

The instance of the YMMReporterConfiguration class which contains the extended configuration for the reporter.

handleOpenURL(_:)

class func handleOpenURL(_ url: NSURL) -> Bool

Processes the URL that opened the application.

Used for tracking app openings via deeplink.

Parameters:
url

The URL that opened the application.

Returns:

  • true, if the deeplink is intended for AppMetrica.
  • false, if the deeplink is not intended for AppMetrica.

There are no such deeplink at the moment. The method always returns NO.

libraryVersion()

open class func libraryVersion() -> String

Returns the current version of the AppMetrica library.

Returns:

Library version.

reporterForApiKey(_:)

class func reporterForApiKey(_ apiKey: String) -> YMMYandexMetricaReporting?

Creates a reporter for sending events to an additional API key.

To initialize a reporter with the extended configuration, use the activateReporter(with:) method. The configuration of the reporter should be initialized before the first call to the reporter. Otherwise, the configuration of the reporter is ignored.

Parameters:
apiKey

API key that differs from the main application API key.

Returns:

The instance that implements the YMMYandexMetricaReporting protocol for a specified API key.

reportError(_:exception:onFailure:)

class func reportError(_ message: String, exception: NSException?, onFailure: ((NSError) -> Void)?)

Sends a custom error message.

Parameters:
message

Short name or description of the error.

exception

The instance of the NSException class.

onFailure

The block that is executed when an error occurs. The error is passed as a block argument.

reportEvent(_:onFailure:)

class func reportEvent(_ message: String, onFailure: ((NSError) -> Void)?)

Sends an event message.

Parameters:
message

Short name or description of the event

onFailure

The block that is executed when an error occurs. The error is passed as a block argument.

reportEvent(_:params:onFailure:)

class func reportEvent(_ message: String, parameters params: [NSObject : AnyObject]?, onFailure: ((NSError) -> Void)?)

Sends an event message with additional parameters.

Parameters:
message

Short name or description of the event

params

Parameters as “key-value” pairs.

onFailure

The block that is executed when an error occurs. The error is passed as a block argument.

reportReferralUrl(_:)

class func reportReferralUrl(_ url: NSURL)

Sets referral URL for app installs. This method can be used to track some traffic sources.

Parameters:
url

Referral URL of the app install.

reportRevenue(_:onFailure:)

class func reportRevenue(_ revenueInfo: YMMRevenueInfo, onFailure: ((NSError) -> Void)?)

Sends information about the purchase to the AppMetrica server.

Parameters:
revenueInfo

The instance of the YMMRevenueInfo class which contains information about a purchase.

onFailure

The block that is executed when an error occurs. The error is passed as a block argument.

reportUserProfile(_:onFailure:)

class func reportUserProfile(_ userProfile: YMMUserProfile, onFailure: ((NSError) -> Void)?)

Sends information about the user profile update to the AppMetrica server.

Parameters:
userProfile

The instance of the YMMUserProfileclass which contains information about the user profile.

onFailure

The block that is executed when an error occurs. The error is passed as a block argument.

requestAppMetricaDeviceIDWithCompletionQueue(_:block:)

class func requestAppMetricaDeviceIDWithCompletionQueue(_ queue: dispatch_queue_t?, completionBlock block: YMMAppMetricaDeviceIDRetrievingBlock)

Requests the unique AppMetrica ID (deviceID).

Note. In the Logs API and Post API deviceID referred to as appmetrica_device_id.
Parameters:
queue

The queue where the callback block will be called.

block

Callback block for receiving appmetrica_device_id. Includes an ID appMetricaDeviceID and error error, if the ID could not be obtained.

sendEventsBuffer()

class func sendEventsBuffer()

Sends stored events from the buffer.

AppMetrica SDK does not send an event immediately after it occurred. The library stores event data in the buffer. The sendEventsBuffer() method sends data from the buffer and flushes it. Use the method to force sending stored events after passing important checkpoints of user scenarios.
Attention. Frequent use of the method can lead to increased outgoing internet traffic and energy consumption.

setLocation(_:)

class func setLocation(_ location: CLLocation?)

Sets custom location of the device.

Parameters:
location

Information about the location of the device.

setLocationTracking(_:)

class func setLocationTracking(_ enabled: Bool)

Enables/disables sending location of the device .

Parameters:
enabled

A flag indicating if sending information about the device location is enabled. The default value is true.

Possible values:
  • true — Sending information about the device location is enabled.
  • false — Sending information about the location of the device is disabled.

setStatisticsSending(_:)

class func setStatisticsSending(_ enabled: Bool)

Enables/disables sending statistics to the AppMetrica server.

For more information about using the method, see Disable and enable sending statistics.
Note. Disabling sending also turns off sending data from all reporters that initialized with the other API key.
Parameters:
enabledA flag indicating that sending statistics is enabled. The default value is true.

Possible values:

  • true — Sending statistics is enabled.
  • false — Sending statistics is disabled.

setUserProfileID(_:)

class func setUserProfileID(_ userProfileID: String?)

Sets the ID of the user profile.

Parameters:
userProfileID

User profile ID.