Class AppMetrica
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidactivate(android.content.Context context, AppMetricaConfig config) static voidactivateReporter(android.content.Context context, ReporterConfig config) Activates the reporter withReporterConfig.static voidClears app environment and removes it from storage.static voidenableActivityAutoTracking(android.app.Application application) Sessions should be tracked automatically without invoking this method.static StringgetDeviceId(android.content.Context context) ReturnsdeviceId.static intstatic Stringstatic AppMetricaPluginsCreates aAppMetricaPluginsinstance that can send plugin events to main API key.static IReportergetReporter(android.content.Context context, String apiKey) Creates anIReporterthat can send events to an alternative api key.static StringgetUuid(android.content.Context context) Returnsuuid.static voidinitWebViewReporting(android.webkit.WebView webView) Adds Javascript interface named "AppMetrica" to WebView's javascript.static voidpauseSession(android.app.Activity activity) Helper method for tracking the life cycle of the application.static voidputAppEnvironmentValue(String key, String value) Sets key - value pair to be used as additional information, associated with your application runtime's environment.static voidputErrorEnvironmentValue(String key, String value) Sets key - value data to be used as additional information, associated with your unhandled exception and error reports.static voidregisterAnrListener(AnrListener listener) Add listener for detect ANR.static voidreportAdRevenue(AdRevenue adRevenue) Sends information about ad revenue.static voidreportAnr(Map<Thread, StackTraceElement[]> allThreads) Sends an ANR event (the application is not responding) manually.static voidreportAppOpen(android.app.Activity activity) Sends report about open app via deeplinkstatic voidreportAppOpen(android.content.Intent intent) Sends report about open app via deeplinkstatic voidreportAppOpen(String deeplink) Sends report about open app via deeplink.static voidreportECommerce(ECommerceEvent event) Sends e-commerce event.static voidreportError(String identifier, String message) Sends an error.static voidreportError(String identifier, String message, Throwable error) Sends an error.static voidreportError(String message, Throwable error) Sends an error.static voidreportEvent(String eventName) Sends report by event name.static voidreportEvent(String eventName, String jsonValue) Sends report by event name and event value.static voidreportEvent(String eventName, Map<String, Object> attributes) Sends report by dictionary.static voidreportExternalAdRevenue(Object... values) Sends information about ad revenue from third-party libraries.static voidReports attribution from different sources to AppMetrica.static voidreportReferralUrl(String referralUrl) Deprecated.static voidreportRevenue(Revenue revenue) Sends information about the purchase.static voidreportUnhandledException(Throwable exception) Sends unhandled exception byThrowableobject.static voidreportUserProfile(UserProfile profile) Sends information about the user profile.static voidRequests deferred deeplink.static voidRequests deferred deeplink parameters.static voidrequestStartupParams(android.content.Context context, StartupParamsCallback callback, List<String> params) Gets specific startup parameters based on the options inStartupParamsCallback.static voidresumeSession(android.app.Activity activity) Helper method for tracking the life cycle of the application.static voidInitiates forced sending of all stored events from the buffer.static voidsetAdvIdentifiersTracking(boolean enabled) Enables/disables including advertising identifiers like GAID, Huawei OAID within its reports.static voidsetDataSendingEnabled(boolean enabled) Enables/disables data sending to the AppMetrica server.static voidsetLocation(android.location.Location location) SetsLocationto be used as location for reports of AppMetrica.static voidsetLocationTracking(boolean enabled) Sets whether AppMetrica should include location information within its reports.static voidsetUserProfileID(String userProfileID) Sets the ID of the user profile.
-
Method Details
-
activate
public static void activate(@NonNull android.content.Context context, @NonNull AppMetricaConfig config) - Parameters:
context-Contextobject. Any application context.config- AppMetrica configuration object.- See Also:
-
sendEventsBuffer
public static void sendEventsBuffer()Initiates forced sending of all stored events from the buffer.AppMetrica SDK doesn't send events immediately after they occurred. It stores events data in the buffer. This method forcibly initiates sending all the data from the buffer and flushes it.
Use the method after important checkpoints of user scenarios.
WARNING: Frequent use of the method can lead to increasing outgoing internet traffic and energy consumption.
-
resumeSession
public static void resumeSession(@Nullable android.app.Activity activity) Helper method for tracking the life cycle of the application.
It should be called intoActivity.onResume()()}.- Parameters:
activity-Activityobject.- Throws:
IllegalArgumentException- Ifactivityis null.- See Also:
-
ActivityActivity.onResume()pauseSession(android.app.Activity)
-
pauseSession
public static void pauseSession(@Nullable android.app.Activity activity) Helper method for tracking the life cycle of the application.
It should be called intoActivity.onPause().- Parameters:
activity-Activityobject.- Throws:
IllegalArgumentException- Ifactivityis null.- See Also:
-
ActivityActivity.onPause()resumeSession(android.app.Activity)
-
enableActivityAutoTracking
public static void enableActivityAutoTracking(@NonNull android.app.Application application) Sessions should be tracked automatically without invoking this method. SeeAppMetricaConfig.Builder.withSessionsAutoTrackingEnabled(boolean)Use this method only if your case is special and you don't see automatically tracked user sessions.Helper method for tracking the lifecycle of the application
Sessions should be tracked automatically- Parameters:
application-Applicationwhose activities starts and stops should be tracked automatically- Throws:
IllegalArgumentException- ifapplicationis null. *
-
reportEvent
Sends report by event name.- Parameters:
eventName- Event name. In theeventNameparameter, pass a short name or description of the event.- Throws:
IllegalArgumentException- IfeventNameis null.- See Also:
-
reportError
Sends an error. Use this method to report un unexpected situation. If you use this method errors will be grouped byerrorstacktrace. If you want to influence the way errors are grouped usereportError(String, String, Throwable)orreportError(String, String)- Parameters:
message- Short description or name of the error.error-Throwableobject for the error. Can be null.- Throws:
IllegalArgumentException- Ifmessageis null.- See Also:
-
reportError
Sends an error. Use this method to report un unexpected situation. This method should be used if you want to customize error grouping. If not usereportError(String, Throwable)- Parameters:
identifier- An identifier used for grouping errors. Errors that have the same identifiers will belong in one group. Do not use dynamically formed strings or exception messages as identifiers to avoid having too many small crash groups. Cannot be null.message- Short description or name of the error. Can be null.- Throws:
IllegalArgumentException- Ifidentifieris null.
-
reportError
public static void reportError(@NonNull String identifier, @Nullable String message, @Nullable Throwable error) Sends an error. Use this method to report un unexpected situation. This method should be used if you want to customize error grouping. If not usereportError(String, Throwable)errorstacktrace will NOT be used for grouping, onlyidentifier.- Parameters:
identifier- An identifier used for grouping errors. Errors that have the same identifiers will belong in one group. Do not use dynamically formed strings or exception messages as identifiers to avoid having too many small crash groups. Cannot be null.message- Short description or name of the error. Can be null.error-Throwableobject for the error. Its stacktrace will not be considered for error grouping. Can be null.- Throws:
IllegalArgumentException- Ifidentifieris null.
-
reportUnhandledException
Sends unhandled exception byThrowableobject.- Parameters:
exception-Throwableobject for the unhandled exception.- Throws:
IllegalArgumentException- Ifexceptionis null.- See Also:
-
reportEvent
Sends report by event name and event value.- Parameters:
eventName- Event name. In theeventNameparameter, pass a short name or description of the event.jsonValue- Event value. In theeventValueparameter, pass aJSONObjectrepresented as aStringobject or pass aStringobject represented in theJava JSON format. Maximum level of nesting (for JSON object) - 5.EXAMPLE:
{ "firstName": "John", "lastName": "Smith", "age": 25, "nickname": "JS" "address": { "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", }, "phoneNumbers": [ { "type": "HOME", "number": "212 555-1234" }, { "type": "FAX", "number": "646 555-4567" } ] }- Throws:
IllegalArgumentException- IfeventNameorjsonValueis null.- See Also:
-
reportEvent(String, java.util.Map)reportEvent(String)JSONObject.toString()
-
reportEvent
Sends report by dictionary.- Parameters:
eventName- Event name. In theeventNameparameter, pass a short name or description of the event.attributes- Event value. In theattributesparameter, pass aMapwhose keys are of typeStringand whose values are of supported types:Boolean,String, and the wrappers for the primitive number typesDouble,Integer, ...- Throws:
IllegalArgumentException- IfeventNameis null.- See Also:
-
reportAppOpen
public static void reportAppOpen(@NonNull android.app.Activity activity) Sends report about open app via deeplink- Parameters:
activity- - opened activity with corresponding intent with deeplink
-
reportAppOpen
Sends report about open app via deeplink. Null and empty values will be ignored.- Parameters:
deeplink- Deeplink value.
-
reportAppOpen
public static void reportAppOpen(@NonNull android.content.Intent intent) Sends report about open app via deeplink- Parameters:
intent- - intent used to open activity with deeplink
-
reportReferralUrl
Deprecated.Sets referral URL for this installation. This might be required to track some specific traffic sources like Facebook.- Parameters:
referralUrl- referral URL value.
-
setLocation
public static void setLocation(@Nullable android.location.Location location) Sets
Locationto be used as location for reports of AppMetrica.If location is set using this method, it will be used instead of auto collected location. To switch back to auto collected location, pass
nulltosetLocation(Location).NOTE: Permissions:
Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.ACCESS_FINE_LOCATIONimprove the quality of auto collected location.- Parameters:
location- location that will be used instead of auto collected- See Also:
-
setLocationTracking
public static void setLocationTracking(boolean enabled) Sets whether AppMetrica should include location information within its reports.NOTE: Default value is
false.- Parameters:
enabled-trueto allow AppMetrica to record location information in reports, otherwisefalse.- See Also:
-
setAdvIdentifiersTracking
public static void setAdvIdentifiersTracking(boolean enabled) Enables/disables including advertising identifiers like GAID, Huawei OAID within its reports.NOTE: Default value is true.
- Parameters:
enabled-trueto allow AppMetrica to record advertising identifiers information in reports, otherwisefalse.- See Also:
-
setDataSendingEnabled
public static void setDataSendingEnabled(boolean enabled) Enables/disables data sending to the AppMetrica server. By default, the sending is enabled.NOTE: Disabling this option also turns off data sending from the reporters that initialized for different apiKey.
- Parameters:
enabled-trueto allow AppMetrica sending data, otherwisefalse.
-
activateReporter
public static void activateReporter(@NonNull android.content.Context context, @NonNull ReporterConfig config) Activates the reporter withReporterConfig.- Parameters:
context- Context object.config- The ReporterConfig object.
-
getReporter
@NonNull public static IReporter getReporter(@NonNull android.content.Context context, @NonNull String apiKey) Creates an
For every api key only oneIReporterthat can send events to an alternative api key.IReporterinstance is created. You can either query it each time you need it, or save the reference by yourself.- Parameters:
context- Context objectapiKey- api key of the reporter- Returns:
- reporter instance for given api key
-
getLibraryVersion
- Returns:
- VERSION of library.
- See Also:
-
getLibraryApiLevel
public static int getLibraryApiLevel()- Returns:
- API LEVEL of library.
- See Also:
-
requestDeferredDeeplinkParameters
public static void requestDeferredDeeplinkParameters(@NonNull DeferredDeeplinkParametersListener listener) Requests deferred deeplink parameters. Parameters will be available after receiving Google Play installation referrer from Google Play. Google Play installation referrer is usually received soon after first launch of application. After Google Play installation referrer is received, deferred deeplink parameters will be extracted and delivered toDeferredDeeplinkParametersListener.onParametersLoaded(Map)listener. If error occurs it will be delivered toDeferredDeeplinkParametersListener.onError(DeferredDeeplinkParametersListener.Error, String)- Parameters:
listener- the object that receives callbacks when Google Play referrer is received or error occurs.
-
requestDeferredDeeplink
Requests deferred deeplink. It will be available after receiving Google Play installation referrer from Google Play. Google Play installation referrer is usually received soon after first launch of application. After Google Play installation referrer is received, deferred deeplink will be extracted and delivered toDeferredDeeplinkListener.onDeeplinkLoaded(String)listener. If error occurs it will be delivered toDeferredDeeplinkListener.onError(DeferredDeeplinkListener.Error, String)- Parameters:
listener- the object that receives callbacks when Google Play referrer is received or error occurs.
-
setUserProfileID
Sets the ID of the user profile. NOTE: The string value can contain up to 200 characters.- Parameters:
userProfileID- The custom user profile ID.
-
reportUserProfile
Sends information about the user profile.- Parameters:
profile- TheUserProfileobject. Contains user profile information.
-
reportRevenue
Sends information about the purchase.- Parameters:
revenue- TheRevenueobject. It contains purchase information
-
reportECommerce
Sends e-commerce event.- Parameters:
event- TheECommerceEventobject to be sent.- See Also:
-
putErrorEnvironmentValue
Sets key - value data to be used as additional information, associated with your unhandled exception and error reports.- Parameters:
key- the environment key.value- the environment value. To remove pair from environment passnullvalue.
-
initWebViewReporting
@MainThread public static void initWebViewReporting(@NonNull android.webkit.WebView webView) Adds Javascript interface named "AppMetrica" to WebView's javascript. It allows then to report events to AppMetrica from JS code.
NOTE: This method must be called from main thread.
NOTE: Reporting from JS code will not be enabled on API levels 16 and less due to security issues.- Parameters:
webView- WebView where AppMetrica should enable reporting- See Also:
-
AppMetricaJsInterface
-
getPluginExtension
Creates a
Only oneAppMetricaPluginsinstance that can send plugin events to main API key.AppMetricaPluginsinstance is created per each app process. You can either query it each time you need it, or save the reference by yourself.
NOTE: to use this extension you must activate AppMetrica first viaactivate(android.content.Context, AppMetricaConfig).- Returns:
- plugin extension instance
-
reportAdRevenue
Sends information about ad revenue.- Parameters:
adRevenue- Object containing the information about ad revenue.- See Also:
-
getDeviceId
ReturnsdeviceId.- Parameters:
context- any Context object- Returns:
deviceIdif present,nullotherwise.- See Also:
-
getUuid
Returnsuuid.- Parameters:
context- any Context object- Returns:
uuidif present,nullotherwise.- See Also:
-
putAppEnvironmentValue
Sets key - value pair to be used as additional information, associated with your application runtime's environment. This environment is unique for every unique APIKey and shared between processes. Application's environment persists to storage and retained between application launches. To reset environment useclearAppEnvironment()If called before metrica initialization, environment will be added right after metrica initialize
WARNING: Application's environment is a global permanent state and can't be changed too often. For frequently changed parameters use extended reportMessage methods.
- Parameters:
key- the environment key.value- the environment value. To remove pair from environment passnullvalue.- See Also:
-
clearAppEnvironment
public static void clearAppEnvironment()Clears app environment and removes it from storage.If called before metrica initialization, app environment will be cleared right after init
- See Also:
-
requestStartupParams
public static void requestStartupParams(@NonNull android.content.Context context, @NonNull StartupParamsCallback callback, @NonNull List<String> params) Gets specific startup parameters based on the options in
StartupParamsCallback. Parameters might not be available right away. When they do arrive, thecallbackis informed instantly. If the parameters are already there, thecallbackalso gets notified right away. After one notification, thecallbackis removed.Avoid using anonymous callbacks. They are wrapped by
WeakReferenceand will be removed automatically, which can cause them to disappear unexpectedly after garbage collection (GC).NOTE: This method can be called even without initializing viaactivate(Context, AppMetricaConfig), but it will take more time to get the startup identifiers.- Parameters:
context- Context objectcallback- Object that implements theStartupParamsCallbackinterface.params- List of parameters to request. If the list is empty, the default request is forStartupParamsCallback.APPMETRICA_UUID,StartupParamsCallback.APPMETRICA_DEVICE_ID,StartupParamsCallback.APPMETRICA_DEVICE_ID_HASH.
-
registerAnrListener
Add listener for detect ANR. It should be called afteractivate(android.content.Context, io.appmetrica.analytics.AppMetricaConfig)method.- Parameters:
listener- An object that implementsAnrListenerinterface.
-
reportExternalAttribution
Reports attribution from different sources to AppMetrica.- Parameters:
value- An object that implementsExternalAttributioninterface.
-
reportExternalAdRevenue
Sends information about ad revenue from third-party libraries. See documentation for more information.- Parameters:
values- Objects that are required to build ad revenue event
-
reportAnr
Sends an ANR event (the application is not responding) manually. It is an alternative for automatic ANR tracking, which is enabled in the $AppMetricaConfigconfiguration during SDK activation.- Parameters:
allThreads- A snapshot of all streams with stack traces. Can be received by callingThread.getAllStackTraces().- See Also:
-