public final class YandexMetrica
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static void |
activate(android.content.Context context,
YandexMetricaConfig config)
|
static void |
activateReporter(android.content.Context context,
ReporterConfig config)
Activates the reporter with
ReporterConfig. |
static void |
enableActivityAutoTracking(android.app.Application application)
Helper method for tracking the lifecycle of the application
|
static int |
getLibraryApiLevel() |
static java.lang.String |
getLibraryVersion() |
static IReporter |
getReporter(android.content.Context context,
java.lang.String apiKey)
Creates an
IReporter that can send events to an alternative api key. |
static void |
initWebViewReporting(android.webkit.WebView webView)
Adds Javascript interface named "AppMetrica" to WebView's javascript.
|
static void |
pauseSession(android.app.Activity activity)
Helper method for tracking the life cycle of the application.
|
static void |
putErrorEnvironmentValue(java.lang.String key,
java.lang.String value)
Sets key - value data to be used as additional information, associated
with your unhandled exception and error reports.
|
static void |
registerReferrerBroadcastReceivers(android.content.BroadcastReceiver... anotherReferrerReceivers)
Deprecated.
GooglePlay will stop sending broadcasts since March 1st, 2020,
so this method will become a stub. The main way to get referrer
is through Google Play Services library, which is now added as a dependency to AppMetrica SDK.
Registers referrer receivers from different SDKs. AppMetrica deliver referrer broadcast to it upon receipt. Only one BroadcastReceiver class can be specified per app. If you need to incorporate two or more BroadcastReceivers from different SDKs, you will need to register all broadcast receivers viaregisterReferrerBroadcastReceivers(android.content.BroadcastReceiver...) |
static void |
reportAppOpen(android.app.Activity activity)
Sends report about open app via deeplink
|
static void |
reportAppOpen(android.content.Intent intent)
Sends report about open app via deeplink
|
static void |
reportAppOpen(java.lang.String deeplink)
Sends report about open app via deeplink.
|
static void |
reportECommerce(ECommerceEvent event)
Sends e-commerce event.
|
static void |
reportError(java.lang.String identifier,
java.lang.String message)
Sends an error.
|
static void |
reportError(java.lang.String identifier,
java.lang.String message,
java.lang.Throwable error)
Sends an error.
|
static void |
reportError(java.lang.String message,
java.lang.Throwable error)
Sends an error.
|
static void |
reportEvent(java.lang.String eventName)
Sends report by event name.
|
static void |
reportEvent(java.lang.String eventName,
java.util.Map<java.lang.String,java.lang.Object> attributes)
Sends report by dictionary.
|
static void |
reportEvent(java.lang.String eventName,
java.lang.String jsonValue)
Sends report by event name and event value.
|
static void |
reportNativeCrash(java.lang.String nativeCrash)
Sends native crash by
String object. |
static void |
reportReferralUrl(java.lang.String referralUrl)
Deprecated.
|
static void |
reportRevenue(Revenue revenue)
Sends information about the purchase.
|
static void |
reportUnhandledException(java.lang.Throwable exception)
Sends unhandled exception by
Throwable object. |
static void |
reportUserProfile(UserProfile profile)
Sends information about the user profile.
|
static void |
requestAppMetricaDeviceID(AppMetricaDeviceIDListener listener)
Retrieves unique AppMetrica device identifier.
|
static void |
requestDeferredDeeplink(DeferredDeeplinkListener listener)
Requests deferred deeplink.
|
static void |
requestDeferredDeeplinkParameters(DeferredDeeplinkParametersListener listener)
Requests deferred deeplink parameters.
|
static void |
resumeSession(android.app.Activity activity)
Helper method for tracking the life cycle of the application.
|
static void |
sendEventsBuffer()
Initiates forced sending of all stored events from the buffer.
|
static void |
setLocation(android.location.Location location)
Sets
Location to be used as location for reports of AppMetrica. |
static void |
setLocationTracking(boolean enabled)
Sets whether AppMetrica should include location information within its reports.
|
static void |
setLocationTracking(android.content.Context context,
boolean enabled)
Sets whether AppMetrica should include location information within its reports.
|
static void |
setStatisticsSending(android.content.Context context,
boolean enabled)
Enables/disables statistics sending to the AppMetrica server.
|
static void |
setUserProfileID(java.lang.String userProfileID)
Sets the ID of the user profile.
|
public static void activate(@NonNull
android.content.Context context,
@NonNull
YandexMetricaConfig config)
context - Context object. Any application context.config - YandexMetrica configuration object.YandexMetricaConfigpublic static void sendEventsBuffer()
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.
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() ()}.activity - Activity object.java.lang.IllegalArgumentException - If activity is null.Activity,
Activity.onResume(),
pauseSession(android.app.Activity)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().activity - Activity object.java.lang.IllegalArgumentException - If activity is null.Activity,
Activity.onPause(),
resumeSession(android.app.Activity)public static void enableActivityAutoTracking(@NonNull
android.app.Application application)
Helper method for tracking the lifecycle of the application
On devices running API level 14 (ICE_CREAM_SANDWICH) or above, applications can be used instead of explicit calls ofresumeSession(android.app.Activity) and pauseSession(android.app.Activity)application - Application whose activities starts and stops should be tracked
automaticallyjava.lang.IllegalArgumentException - if application is null.
*public static void reportEvent(@NonNull
java.lang.String eventName)
eventName - Event name. In the eventName parameter,
pass a short name or description of the event.java.lang.IllegalArgumentException - If eventName is null.reportEvent(String)public static void reportError(@NonNull
java.lang.String message,
@Nullable
java.lang.Throwable error)
error stacktrace.
If you want to influence the way errors are grouped use
reportError(String, String, Throwable) or
reportError(String, String)message - Short description or name of the error.error - Throwable object for the error. Can be null.java.lang.IllegalArgumentException - If message is null.reportUnhandledException(Throwable)public static void reportError(@NonNull
java.lang.String identifier,
@Nullable
java.lang.String message)
reportError(String, Throwable)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.java.lang.IllegalArgumentException - If identifier is null.public static void reportError(@NonNull
java.lang.String identifier,
@Nullable
java.lang.String message,
@Nullable
java.lang.Throwable error)
reportError(String, Throwable)
error stacktrace will NOT be used for grouping, only identifier.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 - Throwable object for the error.
Its stacktrace will not be considered for error grouping. Can be null.java.lang.IllegalArgumentException - If identifier is null.public static void reportUnhandledException(@NonNull
java.lang.Throwable exception)
Throwable object.exception - Throwable object for the unhandled exception.java.lang.IllegalArgumentException - If exception is null.YandexMetricaConfig.Builder.withCrashReporting(boolean),
reportError(String, Throwable)public static void reportNativeCrash(@NonNull
java.lang.String nativeCrash)
String object.nativeCrash - String object for the native crash. Contains a crash dump information.java.lang.IllegalArgumentException - If nativeCrash is null.YandexMetricaConfig.Builder.withNativeCrashReporting(boolean),
reportUnhandledException(Throwable),
reportError(String, Throwable)public static void reportEvent(@NonNull
java.lang.String eventName,
@Nullable
java.lang.String jsonValue)
eventName - Event name. In the eventName parameter,
pass a short name or description of the event.jsonValue - Event value. In the eventValue parameter,
pass a JSONObject represented as a String object or
pass a String object represented in the Java 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"
}
]
}
java.lang.IllegalArgumentException - If eventName or jsonValue is null.reportEvent(String, java.util.Map),
reportEvent(String),
JSONObject.toString()public static void reportEvent(@NonNull
java.lang.String eventName,
@Nullable
java.util.Map<java.lang.String,java.lang.Object> attributes)
eventName - Event name. In the eventName parameter,
pass a short name or description of the event.attributes - Event value. In the attributes parameter,
pass a Map whose keys are of type String
and whose values are of supported types:
Boolean, String,
and the wrappers for the primitive number types
Double, Integer, ...java.lang.IllegalArgumentException - If eventName is null.reportEvent(String, String),
reportEvent(String)public static void reportAppOpen(@NonNull
android.app.Activity activity)
activity - - opened activity with corresponding intent with deeplinkpublic static void reportAppOpen(@NonNull
java.lang.String deeplink)
deeplink - Deeplink value.public static void reportAppOpen(@NonNull
android.content.Intent intent)
intent - - intent used to open activity with deeplinkpublic static void reportReferralUrl(@NonNull
java.lang.String referralUrl)
referralUrl - referral URL value.public static void setLocation(@Nullable
android.location.Location location)
Sets Location to 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 null to setLocation(Location).
NOTE: Permissions:
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION
improve the quality of auto collected location.
location - location that will be used instead of auto collectedsetLocationTracking(boolean),
setLocationTracking(Context, boolean)public static void setLocationTracking(boolean enabled)
NOTE: Default value is true
enabled - true to allow AppMetrica to record location information in reports,
otherwise false.setLocation(android.location.Location)public static void setLocationTracking(@NonNull
android.content.Context context,
boolean enabled)
NOTE: Default value is true
context - Context objectenabled - true to allow AppMetrica to record location information in reports,
otherwise false.setLocation(android.location.Location)public static void setStatisticsSending(@NonNull
android.content.Context context,
boolean enabled)
NOTE: Disabling this option also turns off data sending from the reporters that initialized for different apiKey.
context - Context objectenabled - true to allow AppMetrica sending statistics,
otherwise false.public static void activateReporter(@NonNull
android.content.Context context,
@NonNull
ReporterConfig config)
ReporterConfig.context - Context object.config - The ReporterConfig object.@NonNull public static IReporter getReporter(@NonNull android.content.Context context, @NonNull java.lang.String apiKey)
Creates an IReporter that can send events to an alternative api key.
IReporter instance is created.
You can either query it each time you need it, or save the reference by yourself.context - Context objectapiKey - api key of the reporter@NonNull public static java.lang.String getLibraryVersion()
getLibraryApiLevel()public static int getLibraryApiLevel()
getLibraryVersion()@Deprecated
public static void registerReferrerBroadcastReceivers(@NonNull
android.content.BroadcastReceiver... anotherReferrerReceivers)
Registers referrer receivers from different SDKs. AppMetrica deliver referrer broadcast to it upon receipt.
Only one BroadcastReceiver class can be specified per app. If you need to incorporate two or more BroadcastReceivers from different SDKs, you will need to register all broadcast receivers viaregisterReferrerBroadcastReceivers(android.content.BroadcastReceiver...)anotherReferrerReceivers - the list of receivers for delivery referrer broadcastpublic static void requestDeferredDeeplinkParameters(@NonNull
DeferredDeeplinkParametersListener listener)
DeferredDeeplinkParametersListener.onParametersLoaded(Map) listener.
If error occurs it will be delivered to
DeferredDeeplinkParametersListener.onError(DeferredDeeplinkParametersListener.Error, String)listener - the object that receives callbacks when Google Play referrer is received or
error occurs.public static void requestDeferredDeeplink(@NonNull
DeferredDeeplinkListener listener)
DeferredDeeplinkListener.onDeeplinkLoaded(String) listener.
If error occurs it will be delivered to
DeferredDeeplinkListener.onError(DeferredDeeplinkListener.Error, String)listener - the object that receives callbacks when Google Play referrer is received or
error occurs.public static void requestAppMetricaDeviceID(@NonNull
AppMetricaDeviceIDListener listener)
NOTE: AppMetrica device ID is used in the Logs API and Post API as 'appmetrica_device_id'.
listener - The AppMetricaDeviceIDListener objectpublic static void setUserProfileID(@Nullable
java.lang.String userProfileID)
userProfileID - The custom user profile ID.public static void reportUserProfile(@NonNull
UserProfile profile)
profile - The UserProfile object. Contains user profile information.public static void reportRevenue(@NonNull
Revenue revenue)
revenue - The Revenue object. It contains purchase informationpublic static void reportECommerce(@NonNull
ECommerceEvent event)
event - The ECommerceEvent object to be sent.ECommerceEventpublic static void putErrorEnvironmentValue(@NonNull
java.lang.String key,
@Nullable
java.lang.String value)
key - the environment key.value - the environment value. To remove pair from environment pass null value.@MainThread
public static void initWebViewReporting(@NonNull
android.webkit.WebView webView)
webView - WebView where AppMetrica should enable reportingAppMetricaJsInterface