Hide

App Indexing API

The App Indexing API provides a way for developers to notify Google about deep links in their native apps and allows the Google app, version 3.6 and above, to drive re-engagement through Google Search query autocompletions, providing fast and easy access to inner pages in apps. The deep links reported using the App Indexing API are also used by Google to index app content and are surfaced in Google Search results.



Overview of the App Indexing API

In this video, product manager Lawrence Chang presents an overview of the new App Indexing API for Android that lets you specify links -- through your app itself -- for App Indexing. It also gives you a way to re-engage users through the Google app autocompletions. We'll provide step-by-step guidelines for how to get started. Take a few minutes and find out how to increase user engagement using the App Indexing API.


Using the API

In order to integrate the App Indexing API into your app, you will first need to set up your project to include Google Play Services. Please be sure to update your project configuration as shown in the examples below:

AndroidManifest.xml

<application
  ...

  <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

  ...
</application>

build.gradle (if using Android Studio)

dependencies {
  ...

  compile 'com.google.android.gms:play-services-appindexing:7.0.0'

  ...
}

Once your project is configured to use Google Play Services API, follow these steps for any activity that supports deep links:

  1. Create an instance of GoogleApiClient in the onCreate() method of your activity.
  2. Notify Google each time a new activity is viewed using the AppIndexApi.start() method. This can be called in the onStart() method of each activity. The start() method should report the content that the user is currently looking at in your app. When that content changes, and the user is looking at something else, the app should call end() on the exiting content and then start() for the new content that is shown. The usual way this works is with onStart() and onStop(), but it need not in the case of fragments or other scrolling-type UIs, for example.
  3. Disconnect your client in your onStop() method.

MainActivity.java

import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;

...

public class MainActivity extends Activity {

  static final Uri APP_URI = Uri.parse("android-app://com.google.developers/appindexingdemo/restaurant1/");
  static final Uri WEB_URL = Uri.parse("http://appindexingdemo.google.com/restaurant1/");
  private GoogleApiClient mClient;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    ...

    mClient = new GoogleApiClient.Builder(this).addApi(AppIndex.APP_INDEX_API).build();

    ...
  }

  @Override
  public void onStart() {
    super.onStart();

    ...

    // Connect your client
    mClient.connect();

    // Define a title for your current page, shown in autocompletion UI
    String title = "App Indexing API Title";

    // Construct the Action performed by the user
    Action viewAction = Action.newAction(Action.TYPE_VIEW, title, WEB_URL, APP_URI);

    // Call the App Indexing API start method after the view has completely rendered
    AppIndex.AppIndexApi.start(mClient, viewAction);

    ...
  }

  @Override
  public void onStop() {
    ...

    // Call end() and disconnect the client
    String title = "App Indexing API Title";
    Action viewAction = Action.newAction(Action.TYPE_VIEW, title, WEB_URL, APP_URI);
    AppIndex.AppIndexApi.end(mClient, viewAction);
    mClient.disconnect();

    ...

    super.onStop();
  }
}

The AppIndexApi.start() method accepts the Action performed by the user within the app. The Action contains the title of the content as well as the deep link that can take users directly to the current view of the app. The title provided here will be used in the Google app query autocompletions. If there is corresponding web content, the web URL parameter should be passed in as well; otherwise, you can pass in null.

Also see the AppIndexApi reference documentation for details.

Quality Guidelines

Google may take corrective action (e.g., demoting or removing your app deep links from Google Search results and query autocompletions) in cases where we see abuse, deception, or other actions that hurt the search experience for our users. In particular, you should avoid:

  • Calling the API on content the user is not acting on.
  • Calling the API more than once per user action.
  • Calling the API with a title that is misleading or incorrect.

Note that Google may react to other misleading practices not listed here. The examples above are not exhaustive. Google may take action on other practices or techniques that hurt the search experience.

Finally, once you have done everything in the launch checklist, Google will be able to start indexing your app. You can check for any issues that arise in Webmaster Tools.