Annotate App Activity

The App Indexing API lets you annotate the actions users take in
your app, and send that data to Google. Google can then surface
the content from those actions to users via query
autocompletions from the Google app.

For example, suppose a user has previously viewed a page in the Zagat app about the
"Calafia Cafe." Zagat uses the App Indexing API to note the fact that the user viewed the page.
Later, the same user wants to find that cafe they were reading about, and searches for
"cala..." in the Google app. Using the data reported through the API,
a query autocompletion for "Calafia Cafe" appears for the user, who can quickly return
to the same page in the Zagat app from before.

Modify deep link activities

The sample below illustrates how you'd modify the deep link activities
in your app to send content view activity to Google, which is a common use case for using
the App Indexing API. You can use the API to annotate other kinds of activities as
well, such as System Voice Actions. Here,
AppIndexApi.start() method accepts
the action performed by the user within the app. The action contains
the title of the content, which can appear in Google app query autocompletions.
It also contains the deep link leading users to the specific app view, and the web URL
for any corresponding web content.

In this example, you'll need to modify any view activity that supports deep links if you want to annotate and send
the views to Google. Here's a common modification:

Create an instance of GoogleApiClient in
the onCreate() method of your activity.

Use the newAction() helper convenience method to generate an Action object.

This object represents the type of activity taken in your app by the user, and it also
includes the page title and relevant URLs for the content. If there is no
corresponding web content, you can pass in null. You can also use the more
generic methods on Action.Builder to create an action with a description
and other rich metadata.

Use the AppIndexApi.start() method to indicate the start of the activity,
passing in the Action object you created above.

Use AppIndexApi.end() when the user completes the action.

Disconnect your client in your onStop()
method.

Typically, you'll set this up within the onStart()
and onStop() methods of your app, but it's not strictly
necessary, such as when sending fragments or other scrolling-type UIs.

Quality Guidelines and Practices

In order to ensure a great search experience for users, Google may take corrective action
in cases where we see abuse, deception, or other actions that hurt the search experience for
users. This can include actions such as demoting or removing your app deep links from
Google Search results and query autocompletions. Note that Google may react to other
misleading practices not listed here.

Best Practices

Only call the AppIndexApi.start() method once each time the user
explicitly chooses to view some content.

Use an accurate and descriptive title for your Action.
The text defined in this title may be used in the Google app query autocompletions.
See this Help Forum
article for a more detailed guide on how to write a good title.

If users are interacting with content in the app, and not just viewing
it, make sure to set an appropriate type for the Action
(for example Action.TYPE_LISTEN.)

Recommended: Inform your users that links visited in the app may
be shared with Google to improve the search experience.