UserActions
Stay organized with collections
Save and categorize content based on your preferences.
Provides methods for logging actions that the user takes in the app.
This is a simple example for logging that the user has started to view an article:
UserActions.getInstance(getApplicationContext()).start(
Actions.newView(
"Index your app with Google App Index",
"//example.net/articles/02101984.html"));
Public Constructor Summary
Public Method Summary
abstract Task<Void>
|
end( Action
action)
Logs that the user has stopped doing something in the app.
|
synchronized static UserActions
|
|
abstract Task<Void>
|
start( Action
action)
Logs that the user has started doing something in the app.
|
Inherited Method Summary
From class java.lang.Object
Object
|
clone()
|
boolean |
|
void |
finalize()
|
final Class<?>
|
getClass()
|
int |
hashCode()
|
final void |
notify()
|
final void |
notifyAll()
|
String
|
toString()
|
final void |
wait(long arg0, int arg1)
|
final void |
wait(long arg0)
|
final void |
wait()
|
Constants
public static final String
APP_INDEXING_API_TAG
The tag used for logging debug information for calls to UserActions
class.
To enable logging:
adb shell setprop log.tag.UserActions DEBUG
Constant Value: "UserActions"
Public Methods
public abstract Task<Void> end (Action
action)
Logs that the user has stopped doing something in the app.
Use this method for a user action of some duration that has come to an end, like
when the user has finished viewing an article or stopped listening to a song, as well
as for instantaneous actions the user has taken, such as sending a message or adding a
song to a playlist. For these instantaneous actions, don't call
start(Action)
at all, but just
end(Action)
.
Parameters
action |
The Action
describing either the instantaneous action the user has just taken, or the more
long-lived activity the user has stopped doing in the app; for the latter
start(Action) should be called before calling
end(Action) . |
Returns
- A
Task
indicating the result of the operation.
public static synchronized UserActions
getInstance (Context
context)
Returns an instance of UserActions
.
This variant does not require Firebase initialization. Instead, the application
context is inferred from the context
that is explicitly passed in.
public abstract Task<Void> start (Action
action)
Logs that the user has started doing something in the app.
Use this method for a user action of some duration, like viewing an article, or
listening to a song. If the action is instantaneous, such as sending a message or
adding a song to a playlist, then make a single call to
end(Action)
instead.
Parameters
action |
The Action
describing what the user has started doing in the app. |
Returns
- A
Task
indicating the result of the operation.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["\u003cp\u003e\u003ccode\u003eUserActions\u003c/code\u003e enables logging user activity within an Android application for App Indexing purposes.\u003c/p\u003e\n"],["\u003cp\u003eDirect use of the \u003ccode\u003eplay-services-appindex\u003c/code\u003e SDK is discouraged; developers should utilize the Google Shortcuts Integration Library for donating dynamic shortcuts.\u003c/p\u003e\n"],["\u003cp\u003eKey methods include \u003ccode\u003estart()\u003c/code\u003e to log the beginning of a user action and \u003ccode\u003eend()\u003c/code\u003e to signal its completion or an instantaneous action.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetInstance()\u003c/code\u003e provides access to a \u003ccode\u003eUserActions\u003c/code\u003e instance for logging user interactions.\u003c/p\u003e\n"],["\u003cp\u003eLogging debug information requires enabling the "UserActions" tag via \u003ccode\u003eadb\u003c/code\u003e.\u003c/p\u003e\n"]]],["The `UserActions` class logs user activities within an app, primarily for dynamic shortcuts and app indexing. To record actions, use `getInstance(Context)` to get an instance. Use `start(Action)` to log the beginning of user activities like viewing content. Use `end(Action)` to log the completion of an activity or instantaneous actions, like sending a message. The `APP_INDEXING_API_TAG` constant is used for logging debug information. The library is used to donate dynamic shortcuts to Google Assistant.\n"],null,["# UserActions\n\npublic abstract class **UserActions** extends [Object](//developer.android.com/reference/java/lang/Object.html) \n| Direct use of play-services-appindex SDK is not supported. You should use the [Google\n| Shortcuts Integration Library](//developer.android.com/jetpack/androidx/releases/core#core-google-shortcuts-1.0.0) to donate dynamic shortcuts to Google Assistant. [Android shortcuts](//developer.android.com/guide/topics/ui/shortcuts) provide users with quick methods to perform an action or access content in an app. For more information, see the full documentation on [pushing dynamic shortcuts to\n| Assistant](//developers.google.com/assistant/app/dynamic-shortcuts).\n\nProvides methods for logging actions that the user takes in the app.\n\nThis is a simple example for logging that the user has started to view an article: \n\n UserActions.getInstance(getApplicationContext()).start(\n Actions.newView(\n \"Index your app with Google App Index\",\n \"//example.net/articles/02101984.html\"));\n \n### Constant Summary\n\n|-------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------|\n| [String](//developer.android.com/reference/java/lang/String.html) | [APP_INDEXING_API_TAG](/android/reference/com/google/android/gms/appindex/UserActions#APP_INDEXING_API_TAG) | The tag used for logging debug information for calls to [UserActions](/android/reference/com/google/android/gms/appindex/UserActions) class. |\n\n### Public Constructor Summary\n\n|---|-----------------------------------------------------------------------------------------------|\n| | [UserActions](/android/reference/com/google/android/gms/appindex/UserActions#UserActions())() |\n\n### Public Method Summary\n\n|---------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract Task\\\u003c[Void](//developer.android.com/reference/java/lang/Void.html)\\\u003e | [end](/android/reference/com/google/android/gms/appindex/UserActions#end(com.google.android.gms.appindex.Action))([Action](/android/reference/com/google/android/gms/appindex/Action) action) Logs that the user has stopped doing something in the app. |\n| synchronized static [UserActions](/android/reference/com/google/android/gms/appindex/UserActions) | [getInstance](/android/reference/com/google/android/gms/appindex/UserActions#getInstance(android.content.Context))([Context](//developer.android.com/reference/android/content/Context.html) context) Returns an instance of [UserActions](/android/reference/com/google/android/gms/appindex/UserActions). |\n| abstract Task\\\u003c[Void](//developer.android.com/reference/java/lang/Void.html)\\\u003e | [start](/android/reference/com/google/android/gms/appindex/UserActions#start(com.google.android.gms.appindex.Action))([Action](/android/reference/com/google/android/gms/appindex/Action) action) Logs that the user has started doing something in the app. |\n\n### Inherited Method Summary\n\nFrom class java.lang.Object \n\n|----------------------------------------------------------------------------|--------------------------------------------------------------------------------|\n| [Object](//developer.android.com/reference/java/lang/Object.html) | clone() |\n| boolean | equals([Object](//developer.android.com/reference/java/lang/Object.html) arg0) |\n| void | finalize() |\n| final [Class](//developer.android.com/reference/java/lang/Class.html)\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| [String](//developer.android.com/reference/java/lang/String.html) | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nConstants\n---------\n\n#### public static final [String](//developer.android.com/reference/java/lang/String.html)\n**APP_INDEXING_API_TAG**\n\nThe tag used for logging debug information for calls to [UserActions](/android/reference/com/google/android/gms/appindex/UserActions)\nclass.\n\nTo enable logging: \n\n`adb shell setprop `*log.tag.UserActions*` `*DEBUG* \nConstant Value: \"UserActions\"\n\nPublic Constructors\n-------------------\n\n#### public **UserActions** ()\n\nPublic Methods\n--------------\n\n#### public abstract Task\\\u003c[Void](//developer.android.com/reference/java/lang/Void.html)\\\u003e **end** ([Action](/android/reference/com/google/android/gms/appindex/Action) action)\n\nLogs that the user has stopped doing something in the app.\n\nUse this method for a user action of some duration that has come to an end, like\nwhen the user has finished viewing an article or stopped listening to a song, as well\nas for instantaneous actions the user has taken, such as sending a message or adding a\nsong to a playlist. For these instantaneous actions, don't call [start(Action)](/android/reference/com/google/android/gms/appindex/UserActions#start(com.google.android.gms.appindex.Action)) at all, but just [end(Action)](/android/reference/com/google/android/gms/appindex/UserActions#end(com.google.android.gms.appindex.Action)). \n\n##### Parameters\n\n| action | The [Action](/android/reference/com/google/android/gms/appindex/Action) describing either the instantaneous action the user has just taken, or the more long-lived activity the user has stopped doing in the app; for the latter [start(Action)](/android/reference/com/google/android/gms/appindex/UserActions#start(com.google.android.gms.appindex.Action)) should be called before calling [end(Action)](/android/reference/com/google/android/gms/appindex/UserActions#end(com.google.android.gms.appindex.Action)). |\n|--------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n\n##### Returns\n\n- A [Task](/android/reference/com/google/android/gms/tasks/Task) indicating the result of the operation. \n\n#### public static synchronized [UserActions](/android/reference/com/google/android/gms/appindex/UserActions)\n**getInstance** ([Context](//developer.android.com/reference/android/content/Context.html) context)\n\nReturns an instance of [UserActions](/android/reference/com/google/android/gms/appindex/UserActions).\n\nThis variant does not require Firebase initialization. Instead, the application\ncontext is inferred from the `context` that is explicitly passed in. \n\n#### public abstract Task\\\u003c[Void](//developer.android.com/reference/java/lang/Void.html)\\\u003e **start** ([Action](/android/reference/com/google/android/gms/appindex/Action) action)\n\nLogs that the user has started doing something in the app.\n\nUse this method for a user action of some duration, like viewing an article, or\nlistening to a song. If the action is instantaneous, such as sending a message or\nadding a song to a playlist, then make a single call to [end(Action)](/android/reference/com/google/android/gms/appindex/UserActions#end(com.google.android.gms.appindex.Action)) instead. \n\n##### Parameters\n\n| action | The [Action](/android/reference/com/google/android/gms/appindex/Action) describing what the user has started doing in the app. |\n|--------|--------------------------------------------------------------------------------------------------------------------------------|\n\n##### Returns\n\n- A [Task](/android/reference/com/google/android/gms/tasks/Task) indicating the result of the operation."]]