Class YandexMetrica
- Method Summary
- Methods inherited from class java.lang.Object
- Method Detail
- activate
- sendEventsBuffer
- resumeSession
- pauseSession
- enableActivityAutoTracking
- reportEvent
- reportError
- reportError
- reportError
- reportUnhandledException
- reportNativeCrash
- reportEvent
- reportEvent
- reportAppOpen
- reportAppOpen
- reportAppOpen
- reportReferralUrl
- setLocation
- setLocationTracking
- setLocationTracking
- setStatisticsSending
- activateReporter
- getReporter
- getLibraryVersion
- getLibraryApiLevel
- requestDeferredDeeplinkParameters
- requestDeferredDeeplink
- requestAppMetricaDeviceID
- setUserProfileID
- reportUserProfile
- reportRevenue
- reportECommerce
- putErrorEnvironmentValue
- initWebViewReporting
- getPluginExtension
- reportAdRevenue
public final class YandexMetrica
extends java.lang.Object
Method Summary
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)
Sessions should be tracked automatically without invoking this method.
|
static int | getLibraryApiLevel() |
static java.lang.String | getLibraryVersion() |
static YandexMetricaPlugins | getPluginExtension()
Creates a
YandexMetricaPlugins instance that can send plugin events to main API key. |
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 | reportAdRevenue(AdRevenue adRevenue)
Sends information about ad revenue.
|
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)
Deprecated.
Will be removed in future versions. 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.
|
Method Detail
activate
public static void activate(@NonNull android.content.Context context, @NonNull YandexMetricaConfig config)
- Parameters:
context
-Context
object. Any application context.config
- YandexMetrica configuration object.- See Also:
YandexMetricaConfig
sendEventsBuffer
public 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.
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
-Activity
object.- Throws:
java.lang.IllegalArgumentException
- Ifactivity
is null.- See Also:
Activity
,Activity.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
-Activity
object.- Throws:
java.lang.IllegalArgumentException
- Ifactivity
is null.- See Also:
Activity
,Activity.onPause()
,resumeSession(android.app.Activity)
enableActivityAutoTracking
public static void enableActivityAutoTracking(@NonNull android.app.Application application)
YandexMetricaConfig.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
-Application
whose activities starts and stops should be tracked automatically- Throws:
java.lang.IllegalArgumentException
- ifapplication
is null. *
reportEvent
public static void reportEvent(@NonNull java.lang.String eventName)
- Parameters:
eventName
- Event name. In theeventName
parameter, pass a short name or description of the event.- Throws:
java.lang.IllegalArgumentException
- IfeventName
is null.- See Also:
reportEvent(String)
reportError
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)
- Parameters:
message
- Short description or name of the error.error
-Throwable
object for the error. Can be null.- Throws:
java.lang.IllegalArgumentException
- Ifmessage
is null.- See Also:
reportUnhandledException(Throwable)
reportError
public static void reportError(@NonNull java.lang.String identifier, @Nullable java.lang.String message)
reportError(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:
java.lang.IllegalArgumentException
- Ifidentifier
is null.
reportError
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
.- 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
-Throwable
object for the error. Its stacktrace will not be considered for error grouping. Can be null.- Throws:
java.lang.IllegalArgumentException
- Ifidentifier
is null.
reportUnhandledException
public static void reportUnhandledException(@NonNull java.lang.Throwable exception)
Throwable
object.- Parameters:
exception
-Throwable
object for the unhandled exception.- Throws:
java.lang.IllegalArgumentException
- Ifexception
is null.- See Also:
YandexMetricaConfig.Builder.withCrashReporting(boolean)
,reportError(String, Throwable)
reportNativeCrash
@Deprecated public static void reportNativeCrash(@NonNull java.lang.String nativeCrash)
String
object.- Parameters:
nativeCrash
-String
object for the native crash. Contains a crash dump information.- Throws:
java.lang.IllegalArgumentException
- IfnativeCrash
is null.- See Also:
YandexMetricaConfig.Builder.withNativeCrashReporting(boolean)
,reportUnhandledException(Throwable)
,reportError(String, Throwable)
reportEvent
public static void reportEvent(@NonNull java.lang.String eventName, @Nullable java.lang.String jsonValue)
- Parameters:
eventName
- Event name. In theeventName
parameter, pass a short name or description of the event.jsonValue
- Event value. In theeventValue
parameter, pass aJSONObject
represented as aString
object or pass aString
object 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:
java.lang.IllegalArgumentException
- IfeventName
orjsonValue
is null.- See Also:
reportEvent(String, java.util.Map)
,reportEvent(String)
,JSONObject.toString()
reportEvent
public static void reportEvent(@NonNull java.lang.String eventName, @Nullable java.util.Map<java.lang.String,java.lang.Object> attributes)
- Parameters:
eventName
- Event name. In theeventName
parameter, pass a short name or description of the event.attributes
- Event value. In theattributes
parameter, pass aMap
whose keys are of typeString
and whose values are of supported types:Boolean
,String
, and the wrappers for the primitive number typesDouble
,Integer
, ...- Throws:
java.lang.IllegalArgumentException
- IfeventName
is null.- See Also:
reportEvent(String, String)
,reportEvent(String)
reportAppOpen
public static void reportAppOpen(@NonNull android.app.Activity activity)
- Parameters:
activity
- - opened activity with corresponding intent with deeplink
reportAppOpen
public static void reportAppOpen(@NonNull java.lang.String deeplink)
- Parameters:
deeplink
- Deeplink value.
reportAppOpen
public static void reportAppOpen(@NonNull android.content.Intent intent)
- Parameters:
intent
- - intent used to open activity with deeplink
reportReferralUrl
public static void reportReferralUrl(@NonNull java.lang.String referralUrl)
- Parameters:
referralUrl
- referral URL value.
setLocation
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.
- Parameters:
location
- location that will be used instead of auto collected- See Also:
setLocationTracking(boolean)
,setLocationTracking(Context, boolean)
setLocationTracking
public static void setLocationTracking(boolean enabled)
NOTE: Default value is false
- Parameters:
enabled
-true
to allow AppMetrica to record location information in reports, otherwisefalse
.- See Also:
setLocation(android.location.Location)
setLocationTracking
public static void setLocationTracking(@NonNull android.content.Context context, boolean enabled)
NOTE: Default value is false
- Parameters:
context
- Context objectenabled
-true
to allow AppMetrica to record location information in reports, otherwisefalse
.- See Also:
setLocation(android.location.Location)
setStatisticsSending
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.
- Parameters:
context
- Context objectenabled
-true
to allow AppMetrica sending statistics, otherwisefalse
.
activateReporter
public static void activateReporter(@NonNull android.content.Context context, @NonNull ReporterConfig config)
ReporterConfig
.- Parameters:
context
- Context object.config
- The ReporterConfig object.
getReporter
@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.- Parameters:
context
- Context objectapiKey
- api key of the reporter- Returns:
- reporter instance for given api key
getLibraryVersion
@NonNull public static java.lang.String getLibraryVersion()
- Returns:
- VERSION of library.
- See Also:
getLibraryApiLevel()
getLibraryApiLevel
public static int getLibraryApiLevel()
- Returns:
- API LEVEL of library.
- See Also:
getLibraryVersion()
requestDeferredDeeplinkParameters
public static void requestDeferredDeeplinkParameters(@NonNull DeferredDeeplinkParametersListener listener)
DeferredDeeplinkParametersListener.onParametersLoaded(Map)
listener. If error occurs it will be delivered to DeferredDeeplinkParametersListener.onError(DeferredDeeplinkParametersListener.Error, String)
- Parameters:
listener
- the object that receives callbacks when Google Play referrer is received or error occurs.
requestDeferredDeeplink
public static void requestDeferredDeeplink(@NonNull DeferredDeeplinkListener listener)
DeferredDeeplinkListener.onDeeplinkLoaded(String)
listener. If error occurs it will be delivered to DeferredDeeplinkListener.onError(DeferredDeeplinkListener.Error, String)
- Parameters:
listener
- the object that receives callbacks when Google Play referrer is received or error occurs.
requestAppMetricaDeviceID
public static void requestAppMetricaDeviceID(@NonNull AppMetricaDeviceIDListener listener)
NOTE: AppMetrica device ID is used in the Logs API and Post API as 'appmetrica_device_id'.
- Parameters:
listener
- The AppMetricaDeviceIDListener object
setUserProfileID
public static void setUserProfileID(@Nullable java.lang.String userProfileID)
- Parameters:
userProfileID
- The custom user profile ID.
reportUserProfile
public static void reportUserProfile(@NonNull UserProfile profile)
- Parameters:
profile
- TheUserProfile
object. Contains user profile information.
reportECommerce
public static void reportECommerce(@NonNull ECommerceEvent event)
- Parameters:
event
- TheECommerceEvent
object to be sent.- See Also:
ECommerceEvent
putErrorEnvironmentValue
public static void putErrorEnvironmentValue(@NonNull java.lang.String key, @Nullable java.lang.String value)
- Parameters:
key
- the environment key.value
- the environment value. To remove pair from environment passnull
value.
initWebViewReporting
@MainThread public static void initWebViewReporting(@NonNull android.webkit.WebView webView)
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
@NonNull public static YandexMetricaPlugins getPluginExtension()
Creates a YandexMetricaPlugins
instance that can send plugin events to main API key.
YandexMetricaPlugins
instance 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 via
activate(android.content.Context, YandexMetricaConfig)
.- Returns:
- plugin extension instance