AMAAppMetrica class

Methods of the class are used for configuring the library.

Instance methods

+activateReporterWithConfiguration:

Initializes a reporter with the extended configuration.

+activateWithConfiguration:

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

+clearAppEnvironment

Deleting all key-value data associated with all future events.

+pauseSession

Pauses the session.

+reportAdRevenue:onFailure:

Sends information about advertising revenue to the AppMetrica server.

+reportECommerce:onFailure:

Sends a message about an E-commerce event.

+reportEvent:onFailure:

Sends an event message.

+reportEvent:parameters:onFailure:

Sends an event message with additional parameters.

+reportExternalAttribution:source:onFailure:

Sends external attribution data to AppMetrica.

+reportRevenue:onFailure:

Sends information about the purchase to the AppMetrica server.

+reportUserProfile:onFailure:

Sends information about a user profile update.

+reporterForAPIKey:

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

+requestStartupIdentifiersWithCompletionQueue:completionBlock:

Requests all predefined IDs.

+requestStartupIdentifiersWithKeys:completionQueue:completionBlock:

Requests IDs for specific keys.

+resumeSession

Resumes the session or creates a new one if the session timeout has expired.

+sendEventsBuffer

Sends stored events from the buffer.

+setAppEnvironmentValue:forKey:

Sets a key-value pair associated with all future events.

+setDataSendingEnabled:

Enables/disables sending statistics to the AppMetrica server.

+setupWebViewReporting:onFailure:

Adds a JavaScript interface with the AppMetrica name in a window to the specified WebView. This lets you send client events from JavaScript code.

+trackOpeningURL:

Processes the URL that opened the app.

Properties

UUID

The current UUID.

accurateLocationTrackingEnabled

Controls the accuracy of location tracking used by the internal location manager.

activated

Indicates whether AppMetrica was activated.

allowsBackgroundLocationUpdates

Enable/disable background tracking of location updates.

customLocation

Sets custom location of the device.

deviceIDHash

The current appmetrica_device_id_hash.

deviceID

The current appmetrica_device_id.

libraryVersion

The current version of the AppMetrica library.

locationTrackingEnabled

Enables/disables sending location of the device.

userProfileID

Sets the ID of the user profile.

Method descriptions

+activateReporterWithConfiguration:

+ (void)activateReporterWithConfiguration:(AMAReporterConfiguration *)configuration;

Initializes a reporter with the 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 AMAReporterConfiguration class which contains the extended configuration for the reporter.

+activateWithConfiguration:

+ (void)activateWithConfiguration:(AMAAppMetricaConfiguration *)configuration;

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

Parameters:

configuration

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

+clearAppEnvironment

+ (void)clearAppEnvironment;

Cleaning the app environment, such as deleting all key-value data associated with all future events.

+pauseSession

+ (void)pauseSession;

Pauses the session.

Note

The session duration depends on the specified timeout. If the time interval between pausing and resuming the session is less than the specified timeout, the current session will be resumed; otherwise, a new one will be created.

For more information about sessions, see Tracking user activity.

+reportAdRevenue:onFailure:

+ (void)reportAdRevenue:(AMAAdRevenueInfo *)adRevenue
              onFailure:(nullable void (^)(NSError *error))onFailure;

Sends information about advertising revenue to the AppMetrica server.

Parameters:

adRevenue

The instance of the AMAAdRevenueInfo class which contains information about advertising revenue.

onFailure

A callback method to be called in the event of an error.

+reportECommerce:onFailure:

+ (void)reportECommerce:(AMAECommerce *)eCommerce
              onFailure:(nullable void (^)(NSError *error))onFailure;

Sends a message about an E-commerce event.

Parameters:

eCommerce

The AMAECommerce class instance.

onFailure

A callback method to be called in the event of an error.

+reportEvent:onFailure:

+ (void)reportEvent:(NSString *)name
          onFailure:(nullable void (^)(NSError *error))onFailure;

Sends an event message.

Parameters:

name

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:parameters:onFailure:

+ (void)reportEvent:(NSString *)name
         parameters:(nullable NSDictionary *)params
          onFailure:(nullable void (^)(NSError *error))onFailure;

Sends an event message with additional parameters.

Parameters:

name

Short name or description of the event.

params

Parameters as key-value pairs.

onFailure

A callback method to be called in the event of an error.

+reportExternalAttribution:source:onFailure:

+ (void)reportExternalAttribution:(NSDictionary *)attribution
                           source:(AMAAttributionSource)source
                        onFailure:(nullable void (^)(NSError *error))onFailure;

Sends external attribution data to AppMetrica.

Parameters:

attribution

A dictionary with attribution data. It must be convertible to JSON, or else the method fails with the onFailure error block run.

source

The attribution data source. Source list.

onFailure

A callback method to be called in the event of an error. The error is passed as an argument.

+reportRevenue:onFailure:

+ (void)reportRevenue:(AMARevenueInfo *)revenueInfo
            onFailure:(nullable void (^)(NSError *error))onFailure;

Sends information about the purchase to the AppMetrica server.

Parameters:

revenueInfo

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

onFailure

A callback method to be called in the event of an error.

+reportUserProfile:onFailure:

+ (void)reportUserProfile:(AMAUserProfile *)userProfile
                onFailure:(nullable void (^)(NSError *error))onFailure;

Sends information about a user profile update.

Parameters:

userProfile

The instance of the AMAUserProfile class which contains information about the user profile.

onFailure

A callback method to be called in the event of an error.

+reporterForAPIKey:

+ (nullable id<AMAAppMetricaReporting>)reporterForAPIKey:(NSString *)APIKey;

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

To initialize a reporter with the extended configuration, use the activateReporterWithConfiguration: 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

An API key that differs from the app's API key.

Returns:

The instance that implements the AMAAppMetricaReporting protocol for the specified API key.

+requestStartupIdentifiersWithCompletionQueue:completionBlock:

+ (void)requestStartupIdentifiersWithCompletionQueue:(nullable dispatch_queue_t)queue
                                     completionBlock:(AMAIdentifiersCompletionBlock)block;

Getting all predefined IDs

Parameters:

queue

Queue for sending a block. If the value is zero, the main queue is used.

block

The block will be sent when available IDs appear or in case of an error.

Predefined IDs are:

  • kAMAUUIDKey
  • kAMADeviceIDKey
  • kAMADeviceIDHashKey

If they are available at the time of calling, the block is sent immediately. See the AMAIdentifiersCompletionBlock definition for more information about the returned types.

+requestStartupIdentifiersWithKeys:completionQueue:completionBlock:

+ (void)requestStartupIdentifiersWithKeys:(NSArray<AMAStartupKey> *)keys
                          completionQueue:(nullable dispatch_queue_t)queue
                          completionBlock:(AMAIdentifiersCompletionBlock)block;

Getting IDs for specific keys

Parameters:

keys

An array of identification keys for the query. See AMAStartupKey.

queue

Queue for sending a block. If the value is zero, the main queue is used.

block

The block will be sent when available IDs appear or in case of an error.

If they are available at the time of calling, the block is sent immediately. See the AMAIdentifiersCompletionBlock definition for more information about the returned types.

+resumeSession

+ (void)resumeSession;

Resumes the session, or creates a new one if the session timeout has expired.

Note

The session duration depends on the specified timeout. If the time interval between pausing and resuming the session is less than the specified timeout, the current session will be resumed; otherwise, a new one will be created.

For more information about sessions, see Tracking user activity.

+sendEventsBuffer

+ (void)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.

Alert

Frequent use of the method can lead to increased outgoing internet traffic and energy consumption.

+setAppEnvironmentValue:forKey:

+ (void)setAppEnvironmentValue:(nullable NSString *)value
                        forKey:(NSString *)key;

Setting key-value data to be used as additional information associated with all future events.

If the value is zero, the previously set key value is deleted. Nothing is done if the key wasn't added.

Parameters:

value

Value.

key

Key.

+setDataSendingEnabled:

+ (void)setDataSendingEnabled:(BOOL)enabled;

Enables/disables sending statistics to the AppMetrica server.

For more information about using the method, see Disabling and enabling sending statistics.

Note

Disabling sending also turns off sending data from all reporters that initialized with the other API key.

Parameters:

enabled

A flag indicating that sending statistics is enabled. The default value is YES.

Possible values:

  • YES: Sending statistics is enabled.
  • NO: Sending statistics is disabled.

+setupWebViewReporting:onFailure:

+ (void)setupWebViewReporting:(id<AMAJSControlling>)controller
                    onFailure:(nullable void (^)(NSError *error))onFailure;

Adds a JavaScript interface with the AppMetrica name in a window to the specified webview. This lets you send client events from JavaScript code.

Notes:

  • The method must be called from the main queue.
  • The method is not available on tvOS.
  • Call this method before loading any content. We recommend calling this method before creating a webview and before adding your scripts to WKUserContentController. For more information, see Usage examples.

Parameters:

controller

The AMAJSControlling instance.

onFailure

A callback method to be called in the event of an error.

+trackOpeningURL:

+ (void)trackOpeningURL:(NSURL *)URL;

Processes the URL that opened the app.

Used for tracking app openings via deeplink.

Parameters:

URL

URL that opened the app.

Property descriptions

uuid

@property (class, nonatomic, readonly) NSString *UUID;

Retrieves the current UUID.

accurateLocationTrackingEnabled

@property (class, nonatomic, getter=isAccurateLocationTrackingEnabled) BOOL accurateLocationTrackingEnabled;

Controls the accuracy of location tracking used by the internal location manager.

If set to YES, the location manager attempts to use the most accurate location data available. This property takes effect only if the isLocationTrackingEnabled parameter is set to YES, and the location wasn't set manually using the customLocation property.

activated

@property (class, assign, readonly, getter=isActivated) BOOL activated;

Indicates whether AppMetrica was activated.

Note

Use this property to check whether AppMetrica has already been activated, typically to avoid redundant activation calls or to make sure that statistics collection is running.

allowsBackgroundLocationUpdates

@property (class, nonatomic) BOOL allowsBackgroundLocationUpdates;

Enable/disable background tracking of location updates. Disabled by default.

customLocation

@property (class, nonatomic, nullable) CLLocation *customLocation;

Sets custom location of the device.

deviceIDHash

@property (class, nonatomic, nullable, readonly) NSString *deviceIDHash;

Retrieves the appmetrica_device_id_hash.

deviceID

@property (class, nonatomic, nullable, readonly) NSString *deviceID;

Retrieves the appmetrica_device_id.

libraryVersion

@property (class, nonatomic, readonly) NSString *libraryVersion;

Returns the current version of the AppMetrica library.

locationTrackingEnabled

@property (class, nonatomic, getter=isLocationTrackingEnabled) BOOL locationTrackingEnabled;

Enables/disables sending location of the device .

userProfileID

@property (class, nonatomic, nullable) NSString *userProfileID;

Sets the ID of the user profile. AppMetrica doesn't display predefined attributes in the web interface if ProfieId sending isn't configured.