public final class YandexMetrica
extends java.lang.Object
YandexMetrica.java
This file is a part of the AppMetrica.
Version for Android © 2015 YANDEX
You may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://legal.yandex.com/metrica_termsofuse/
Modifier and Type | Method and Description |
---|---|
static void |
activate(android.content.Context context,
java.lang.String apiKey)
|
static int |
getLibraryApiLevel() |
static java.lang.String |
getLibraryVersion() |
static boolean |
isMetricaProcess(android.content.Context context)
Specifies in what process we are now.
|
static void |
onPauseActivity(android.app.Activity activity)
Helper method for tracking the life cycle of the application.
|
static void |
onResumeActivity(android.app.Activity activity)
Helper method for tracking the life cycle of the application.
|
static void |
reportError(java.lang.String message,
java.lang.Throwable error)
Sends error by message and
Throwable object. |
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 |
reportUnhandledException(java.lang.Throwable exception)
Sends unhandled exception by
Throwable object. |
static void |
setCollectInstalledApps(boolean collect)
Whether collect installed apps list.
|
static void |
setCustomAppVersion(java.lang.String appVersion)
Sets the application version.
|
static void |
setEnvironmentValue(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 |
setLocation(android.location.Location location)
Sets
Location to be used as location for reports of Yandex Metrica.If location is set using this method, it will be used instead of auto collected location. |
static void |
setReportCrashesEnabled(boolean enabled)
Whether to capture and send reports about crashes automatically.
|
static void |
setReportNativeCrashesEnabled(boolean enabled)
Whether to capture and send reports about native crashes automatically.
|
static void |
setSessionTimeout(int sessionTimeout)
Set the timeout for expiring session.
|
static void |
setTrackLocationEnabled(boolean enabled)
Sets whether Yandex Metrica should include location information within its reports.
|
public static void activate(android.content.Context context, java.lang.String apiKey)
context
- Context
object. Any application context.apiKey
- Application api key.java.lang.IllegalArgumentException
- If some passed parameter is invalid.java.lang.IllegalStateException
- If the Yandex Metrica for Apps is incorrectly configured.Context
public static void onResumeActivity(android.app.Activity activity)
Activity.onResume()
.activity
- Activity
object.java.lang.IllegalArgumentException
- If activity
is null.Activity
,
Activity.onResume()
,
onPauseActivity(android.app.Activity)
public static void onPauseActivity(android.app.Activity activity)
Activity.onPause()
.activity
- Activity
object.java.lang.IllegalArgumentException
- If activity
is null.Activity
,
Activity.onPause()
,
onResumeActivity(android.app.Activity)
public static void reportEvent(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(java.lang.String message, java.lang.Throwable error)
Throwable
object.message
- Short description or name of the message.error
- Throwable
object for the error.java.lang.IllegalArgumentException
- If message
is null.reportUnhandledException(Throwable)
public static void reportUnhandledException(java.lang.Throwable exception)
Throwable
object.exception
- Throwable
object for the unhandled exception.java.lang.IllegalArgumentException
- If exception
is null.setReportCrashesEnabled(boolean)
,
reportError(String, Throwable)
public static void reportNativeCrash(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.setReportNativeCrashesEnabled(boolean)
,
reportUnhandledException(Throwable)
,
reportError(String, Throwable)
public static void reportEvent(java.lang.String eventName, 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.
{
"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(java.lang.String eventName, 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
or attributes
is null.reportEvent(String, String)
,
reportEvent(String)
public static void setSessionTimeout(int sessionTimeout)
By default, the session times out if the app is inactive for 10 seconds. To change this time limit, pass the YandexMetrica.setSessionTimeout(int sessionTimeoutSeconds) method your time limit in seconds. The minimum acceptable value for the sessionTimeoutSeconds parameter is 10 seconds. If a value less than 10 is set, the value will automatically be 10 seconds.
Under the duration of sessions, in the concept of Metrica, means the following (see example):
EXAMPLE: Let the duration of session timeout is 2 minutes. Then, if interaction with your application started after 2 minutes of inactivity with the application, then a new session will be created, otherwise the session will continue.
sessionTimeout
- Timeout in seconds.public static void setReportCrashesEnabled(boolean enabled)
NOTE: Default value is true
enabled
- true
if we need to send reports about crashes,
otherwise false
. In the case of false
you can still send
information about crashes via reportUnhandledException(Throwable)
method.public static void setReportNativeCrashesEnabled(boolean enabled)
enabled
- true
if we need to send reports about native crashes,
otherwise false
. In the case of false
you can still send
information about native crashes via reportNativeCrash(String)
method.setReportCrashesEnabled(boolean)
public static void setLocation(android.location.Location location)
Location
to be used as location for reports of Yandex Metrica.null
to setLocation(Location)
.
Manifest.permission.ACCESS_COARSE_LOCATION
,
Manifest.permission.ACCESS_FINE_LOCATION
improve the quality of auto collected location.setTrackLocationEnabled(boolean)
public static void setTrackLocationEnabled(boolean enabled)
NOTE: Default value is true
enabled
- true
to allow Yandex Metrica to record location information in reports,
otherwise false
.setLocation(android.location.Location)
public static void setCustomAppVersion(java.lang.String appVersion)
android:versionName
of
the AndroidManifest.xml file.
appVersion
- Application version.java.lang.IllegalArgumentException
- If appVersion
is null/empty.PackageInfo.versionName
public static void setCollectInstalledApps(boolean collect)
collect
- whether installed apps list should be collected.public static void setEnvironmentValue(java.lang.String key, java.lang.String value)
key
- the environment key.value
- the environment value.public static java.lang.String getLibraryVersion()
getLibraryApiLevel()
public static int getLibraryApiLevel()
getLibraryVersion()
public static boolean isMetricaProcess(android.content.Context context)
context
- Context
object.true
if now we are in the process of Metrica, otherwise false
.