Google App Indexing

Firebase App Indexing 

Let’s make your app more visible!

 

Hello Friends, I am back with a new interesting blog. Today we are going to discuss Firebase App Indexing, an interesting feature and helps in getting more users to your app through Google search, formally it is Google app indexing. This year in Google I/O, Google announced they have renamed Google App Indexing with Firebase App indexing. They also announced more features in Google I/O that we are going to discuss in this blog.

I am happy to share  while developing mobile apps at LetsNurture, we provide app indexing in our apps and helping our clients in getting more downloads/users. It is a matter for all of those who are directly or indirectly connected with App development. It matters a lot for SEO and digital marketers! We can consider App indexing is a new way to Google search. As per Google said, “This is just one step toward bringing apps and the web together, making it even easier to get the right information, regardless of where it’s located.” In addition “The apps that are indexed by Google will rank better as well”.

In this post

In this post, we will have a detailed look into what app indexing means and how it all works. I will also demonstrate how to implement app indexing in android application. Let’s get started!

What is App Indexing?

Sometimes good content often available inside apps but search engines can’t typically find it! To overcome this problem, Google has introduced app indexing. Whenever users search for the content and if your iOS or Android application is already installed, it will launch your app directly from search results. If users don’t have your app yet, an install card shows up in search results for Android. Adding app indexing promotes both types of app results within google search and also provides query autocompletion.

Let’s take an example, consider you have installed IMDb movie app. Then you are searching for any movie result in Google app, here Google gives you result from something like below:

image2

When you search, google gives you a collection of relevant apps from google play in search result with install card.

App install card

Why does App indexing really matter for your Apps?

By adding app indexing in your app means you can directly interact with functionality/content available in your apps.There are many other advantages which make people be an app user:

  • Suggest Search result:  Google search will prompt the user if relevant search content is available in installed apps, including your app icon in the search result.
  • Install suggestion:  App Indexing associates your app and website, so your app install card displays next to your website card.
  • App autocompletion: App Indexing API lets your users see app pages they have visited as suggested results on the google app.

App autocompletion

  • Better experience and increase engagement: It gives a better experience to the user to redirect to  native app content. We can increase engagement with the user who uses your app through an alert.
  • Now On Tap: App Indexing powers Now on Tap’s app results and shows your Android app for its users.

How does it work?

Google Search begins indexing your website and app content within a time frame of 24 hours to a number of days. Google Search scheduling depends on a number of factors. Read about Google’s regular crawling of the web in Search Console Help for details. After indexing completes, you’ll see a message in Google Search Console when content from your app shows up in search (“first impression”). If you don’t see any app links in search after a couple of weeks, check Search Console for crawl errors.

Using the App Indexing API for Android enhances ranking performance for your URLs and provides the basis for link titles and content snippets associated with your content. It also logs the history of actions in your app for users who opt in. Users who opt in to share their action history can view or delete their app activity history at https://history.google.com/.

Test your app’s HTTP URLs in your development environment and in the Search Preview Tool for iOS and Android to make sure they lead to the correct content.

Getting your app indexed

There are a number of steps needed to implement App Indexing, and we will require the support of the developers of both your app and website. In this tutorial, I am going to show you steps for implementing app indexing in Android apps. For implementing App Indexing in iOS, check the documentation. Let’s implement it in Android.

There are four main steps to complete App indexing process:

  • Add HTTP Support URLs in App
  • Configure App indexing API in App
  • Test App Indexing
  • Google Analytic – track your app’s traffic
  • Add HTTP Support URLs in App:
  • Understand your site links:

We need to create a common structure for app and website so the user can access and use it. Let’s take an example of our engineering blog. For an example, our blog  http://engineering.letsnurture.com/ which contain a different section like android , iOS , Php etc.

We need to configure an app to matching content for all sections(android.php,IOS) and all links.

  • Connect your site with app:

You should connect your site with your app using Digital Asset Links. Digital Asset Links take the form of a JSON file called assetlinks.json. Here’re an example  assetlinks.json for an app package named com.yourapplication.app. You’ll need to change the  package name and sha256_cert_fingerprints content to match those for your app.

[{

  "relation": ["delegate_permission/common.handle_all_urls"],

  "target" : { "namespace": "android_app",

    "package_name": "com.yourapplication.app",

               "sha256_cert_fingerprints": ["hash_of_app_certificate"] }

}]

For more you can check here.

  • Receiving incoming links in your app:

Website structure is more important to configure your app for app indexing which we can see in the previous section with different URLs. In an app, first, we need to configure Intent Filter in-app AndroidManifest.xml to listen to user request. Intent filters declare the HTTP URL patterns that your app handles from inbound links; the same URLs used for corresponding pages on your website.

  1. Select the <activity> tag in Android Studio to reveal the lightbulb icon to the left of the tag.
  2. Choose the lightbulb, then select Add URL from the drop-down list.Add URL

Now we need to update activity intent filter with our details:

<activity

           android:name=".AndroidBlogActivity"

           android:label="@string/app_android_blog_name"

           android:theme="@style/AppTheme.NoActionBar">

<intent-filter android:label="@string/app_name" android:autoVerify="true">
       <action android:name="android.intent.action.VIEW" />
       <category android:name="android.intent.category.DEFAULT" />
       <category android:name="android.intent.category.BROWSABLE" />
       <!-- Accepts URIs that begin with "engineering.letsnurture.com" -->
       <data android:scheme="http"
           android:host="engineering.letsnurture.com"
           android:pathPrefix="/android" />
   </intent-filter>

       </activity>

<activity

           android:name=".PhpBlogActivity"

           android:label="@string/app_php_blog_name"

           android:theme="@style/AppTheme.NoActionBar">

<intent-filter android:label="@string/app_name" android:autoVerify="true">
       <action android:name="android.intent.action.VIEW" />
       <category android:name="android.intent.category.DEFAULT" />
       <category android:name="android.intent.category.BROWSABLE" />
       <!-- Accepts URIs that begin with "engineering.letsnurture.com" -->
       <data android:scheme="http"
           android:host="engineering.letsnurture.com"
           android:pathPrefix="/php" />
   </intent-filter>

       </activity>

 

Now, when a user finds the /android, /PHP link on your site and chooses to view the search result, your app launches and presents the related activity to view the blog. In the app we need to write correct app logic to handle incoming URL. Let’s see how to handle incoming URL.

  • Handle incoming URL:

Now that you’ve set the Intent Filter in your AndroidManifest.xml, your app launches a specific activity based on the URL passed to it. For example, the AndroidBlogActivity activity launches in response to a URL matching http://engineering.letsnurture.com/android.

Now it’s time to add some code in activity:

In the related activity, you can call getIntent() for the details from this intent. So your onCreate code would look like below:

@Override

 protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_android);

    onNewIntent(getIntent());

 }

 

onCreate() passes the results of getIntent() (an Intent) to onNewIntent, for processing. The URL is available as a result of getDataString(), so it’s relatively simple to parse it. For example, suppose you want your app to display a specific blog category. To parse out the last element of the URL (the blog category), build a URI to retrieve the blog category, and display blog category in Webview, code like below:

 protected void onNewIntent(Intent intent) {

   String action = intent.getAction();

   String data = intent.getDataString();

   if (Intent.ACTION_VIEW.equals(action) && data != null) {

       String blogCategory = data.substring(data.split("/")[0]); //android

       Uri contentUri = Uri.parse("http://engineering.letsnurture.com/"+ blogCategory+”/”)

       showBlogInWebView(contentUri);

   }

}

 

That’s it! Now App indexing is supporting in your app. Now you can check your app to launch from the search result. See below screenshots:

App indexing 

  • Configure App indexing API in App:

The android app indexing API indexes user actions in your app, such as TYPE_VIEW. This lets your users see app pages they have visited as result in Search autocomplete.

Following below steps which enable App Indexing API in your app.:

1. Add Google Play Service

Add below gradle line in your build.gradle. :

 

dependencies {

...

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

...

}

2. Import classes

import com.google.android.gms.appindexing.Action;

import com.google.android.gms.appindexing.AppIndex;

import com.google.android.gms.common.api.GoogleApiClient;

3. Add app indexing call

Let’s take an example to get idea how to index or add user call for relevant activity. Define the title, description, URL, and type for relevant activities and build the Action object. This enables search results to show your preferred app page title and description, and to serve richer results like play actions.

public class MainActivity extends Activity {

 private GoogleApiClient mClient;

 private Uri mUrl;

 private String mTitle;

 private String mDescription;

 @Override

 protected void onCreate(Bundle savedInstanceState) {

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

   mUrl = "http://examplepetstore.com/dogs/standard-poodle";

   mTitle = "Standard Poodle";

   mDescription = "The Standard Poodle stands at least 18 inches at the withers";

 }

 public Action getAction() {

   Thing object = new Thing.Builder()

       .setName(mTitle)

       .setDescription(mDescription)

       .setUrl(mUrl)

       .build();

   return new Action.Builder(Action.TYPE_VIEW)

       .setObject(object)

       .setActionStatus(Action.STATUS_TYPE_COMPLETED)

       .build();

 }

 

Regarding fragments: You structure fragments in the same way as the activity in the example above. But because fragments may execute many times within an activity, or there may be multiple fragments, you should take care to make the API call only once. Here are some guidelines:

  1. If the activity calls the API, then don’t call the API again from any fragment within the activity.
  2. If the activity doesn’t call the API, and you want a fragment to call it instead, then make sure only one fragment calls the API and only one time.
  3. Two easy way to add App indexing code in class:

image7 image8

4. Indicate the app activity

Call activity start after the view completely renders, passing in the App Indexing object defined above. Call the AppIndexApi.end() method after the activity completes, and disconnect your client.

@Override

public void onStart() {

  super.onStart();

  mClient.connect();

  AppIndex.AppIndexApi.start(mClient, getAction());

}

@Override

public void onStop() {

  AppIndex.AppIndexApi.end(mClient, getAction());

  mClient.disconnect();

  super.onStop();

}
  • Test your app:

Pranay Patel

Software Engineer at @LetsNurture || #AndroidDev #twitter || @SOreadytohelp #github #java #database #security #ethicalhacking || #TEA

Want to work with us? We're hiring!
  • Tasneem Bohra

    I want to index data that is coming from server so I can not call on onStart method, but Its not working.