AppMetrica class
- Instance methods
- Properties
- Method descriptions
- activate(with:)
- activateReporter(with:)
- clearAppEnvironment()
- pauseSession()
- reportAdRevenue(_:onFailure:)
- reportECommerce(_:onFailure:)
- reportEvent(name:onFailure)
- reportEvent(name:parameters:onFailure)
- reportExternalAttribution(_:from:onFailure:)
- reportRevenue(_:onFailure:)
- reportUserProfile(_:onFailure:)
- reporter(for:)
- requestStartupIdentifiers(for:on:completion:)
- requestStartupIdentifiers(on:completion:)
- resumeSession()
- sendEventsBuffer()
- setAppEnvironment(_:forKey:)
- setDataSendingEnabled(_:)
- setupWebViewReporting(with:onFailure:)
- trackOpeningURL(_:)
- Property descriptions
Methods of the class are used for configuring the library.
Instance methods
Initializes the library in an application with the extended startup configuration. |
|
Initializes a reporter with the extended configuration. |
|
Deleting all key-value data associated with all future events. |
|
Pauses the user session. |
|
Sends information about advertising revenue to the AppMetrica server. |
|
Sends a message about an E-commerce event. |
|
Sends an event message. |
|
Sends an event message with additional parameters. |
|
Sends external attribution data to AppMetrica. |
|
Sends information about the purchase to the AppMetrica server. |
|
Sends information about a user profile update. |
|
Creates a reporter for sending events to an additional API key. |
|
Requests IDs for specific keys. |
|
Requests all predefined IDs. |
|
Resumes the session, or creates a new one if the session timeout has expired. |
|
Sends stored events from the buffer. |
|
Sets a key-value pair associated with all future events. |
|
Enables/disables sending statistics to the AppMetrica server. |
|
Adds a JavaScript interface with the AppMetrica name in a window to the specified WebView. This lets you send client events from JavaScript code. |
|
Processes the URL that opened the app. |
Properties
Enable/disable background tracking of location updates. |
|
The current appmetrica_device_id_hash. |
|
The current appmetrica_device_id. |
|
Controls the accuracy of location tracking used by the internal location manager. |
|
Indicates whether AppMetrica was activated. |
|
Enables/disables sending location of the device. |
|
The current version of the AppMetrica library. |
|
Sets the ID of the user profile. |
|
The current UUID. |
Method descriptions
activate(with:)
class func activate(with: AppMetricaConfiguration)
Initializes the library in an app with the extended startup configuration.
Parameters:
|
The instance of the AppMetricaConfiguration class which contains the extended startup configuration for the library. |
activateReporter(with:)
class func activateReporter(with: ReporterConfiguration)
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:
|
The instance of the ReporterConfiguration class which contains the extended configuration for the reporter. |
clearAppEnvironment()
class func clearAppEnvironment()
Cleaning the app environment, such as deleting all key-value data associated with all future events.
pauseSession()
class func pauseSession()
Pauses the user session.
Note
The session duration depends on 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:)
class func reportAdRevenue(_ adRevenue: AdRevenueInfo, onFailure: ((Error) -> Void)?)
Sends information about advertising revenue to the AppMetrica server.
Parameters:
|
The instance of the AdRevenueInfo class which contains information about advertising revenue. |
|
A callback method to be called in the event of an error. |
reportECommerce(_:onFailure:)
class func reportECommerce(_ eCommerce: ECommerce, onFailure: ((Error) -> Void)?)
Sends a message about an E-commerce event.
Parameters:
|
The ECommerce class instance. |
|
A callback method to be called in the event of an error. |
reportEvent(name:onFailure)
class func reportEvent(name: String, onFailure: ((Error) -> Void)?)
Sends an event message.
Parameters:
|
Short name or description of the event. |
|
The block that is executed when an error occurs. The error is passed as a block argument. |
reportEvent(name:parameters:onFailure)
class func reportEvent(name: String, parameters: [AnyHashable : Any]?, onFailure: ((Error) -> Void)?)
Sends an event message with additional parameters.
Parameters:
|
Short name or description of the event. |
|
Parameters as |
|
A callback method to be called in the event of an error. |
reportExternalAttribution(_:from:onFailure:)
class func reportExternalAttribution(_ attribution: [AnyHashable : Any], from source: AttributionSource, onFailure: ((any Error) -> Void)? = nil)
Sends external attribution data to AppMetrica.
|
A dictionary with attribution data. It must be convertible to JSON, or else the method fails with the |
|
The attribution data source. Source list. |
|
A callback method to be called in the event of an error. The error is passed as an argument. |
reportRevenue(_:onFailure:)
class func reportRevenue(_ revenueInfo: RevenueInfo, onFailure: ((Error) -> Void)?)
Sends information about the purchase to the AppMetrica server.
Parameters:
|
The instance of the RevenueInfo class which contains information about a purchase. |
|
A callback method to be called in the event of an error. |
reportUserProfile(_:onFailure:)
class func reportUserProfile(_ userProfile: UserProfile, onFailure: ((Error) -> Void)?)
Sends information about the user profile update.
Parameters:
|
The instance of the UserProfile class which contains information about the user profile. |
|
A callback method to be called in the event of an error. |
reporter(for:)
class func reporter(for: String) -> AppMetricaReporting
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:
|
An API key that differs from the app's API key. |
Returns:
The instance that implements the AppMetricaReporting protocol for the specified API key.
requestStartupIdentifiers(for:on:completion:)
class func requestStartupIdentifiers(for: [StartupKey], on: dispatch_queue_t?, completion: ([StartupKey : Any]?, Error?) -> Void)
Getting IDs for specific keys
Parameters:
|
An array of identification keys for the query. See |
|
Queue for sending a block. If the value is zero, the main queue is used. |
|
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 |
requestStartupIdentifiers(on:completion:)
class func requestStartupIdentifiers(on: dispatch_queue_t?, completion: ([StartupKey : Any]?, Error?) -> Void)
Getting all predefined IDs
Parameters:
|
Queue for sending a block. If the value is zero, the main queue is used. |
|
The block will be sent when available IDs appear or in case of an error. Predefined IDs are:
If they are available at the time of calling, the block is sent immediately. See the |
resumeSession()
class func resumeSession()
Resumes the session, or creates a new one if the session timeout has expired.
Note
The session duration depends on 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()
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.
Alert
Frequent use of the method can lead to increased outgoing internet traffic and energy consumption.
setAppEnvironment(_:forKey:)
class func setAppEnvironment(_ value: String?, forKey: String)
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. |
|
Key. |
setDataSendingEnabled(_:)
class func setDataSendingEnabled(_ enabled: Bool)
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:
|
A flag indicating that sending statistics is enabled. The default value is Possible values:
|
setupWebViewReporting(with:onFailure:)
class func setupWebViewReporting(with: JSControlling, onFailure: ((Error) -> Void)?)
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:
|
The |
|
A callback method to be called in the event of an error. |
trackOpeningURL(_:)
class func trackOpeningURL(_ URL: URL)
Processes the URL that opened the application.
Used for tracking app openings via deeplink
Parameters:
|
URL that opened the app. |
Property descriptions
allowsBackgroundLocationUpdates
var allowsBackgroundLocationUpdates: Bool { get; set; }
Enable/disable background tracking of location updates. Disabled by default.
customLocation
var customLocation: CLLocation? { get; set; }
Sets custom location of the device.
deviceIDHash
var deviceIDHash: String? { get; }
Retrieves the appmetrica_device_id_hash.
deviceID
var deviceID: String? { get; }
Retrieves the appmetrica_device_id.
isAccurateLocationTrackingEnabled
var isAccurateLocationTrackingEnabled: Bool { get; set; }
Controls the accuracy of location tracking used by the internal location manager.
If set to true
, the location manager attempts to use the most accurate location data available.
This property takes effect only if the isLocationTrackingEnabled
parameter is set to true
, and the location
wasn't set manually using the customLocation
property.
isActivated
var isActivated: Bool { get; }
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.
isLocationTrackingEnabled
var isLocationTrackingEnabled: Bool { get; set; }
Enables/disables sending location of the device .
libraryVersion
var libraryVersion: String { get; }
Returns the current version of the AppMetrica library.
userProfileID
var userProfileID: String? { get; set; }
Sets the ID of the user profile. AppMetrica doesn't display predefined attributes
in the web interface if ProfieId sending isn't configured.
uuid
var uuid: String { get; }
Retrieves the current UUID.