Firebase App Indexing

 

Did you know you can have your native app show up in Google Search results? You can do this with Firebase App Indexing (formerly Google App Indexing) and you can implement this for iOS and Android apps.

How Does This Work?

First, I want to mention, that to my knowledge, Google doesn’t download your app, run it and index the content it finds as it would a website, this would be incredibly difficult (though as I mention below that doesn’t stop Google).

What Google and other search engines do, is link a website to an app. For example if you have a website with a recipe on it and you can view this recipe in your app with some greater functionality, then Android can load the App instead of the webpage. Google still indexes websites and determines how they are related.

App Indexing has 2 main parts.

  1. Showing your app in search results and deep linking into your app
  2. Tracking the users actions while in your app.

Overview

Setting up App Indexing is detailed below but for some context and simplification here are the steps at a high level

  1. Create your website assets.json file. Follow App Links in Android for details on how to.
  2. Register your website in Google Search Console. (Note: Use the same user account as your Google Play Store account)
  3. Verify your website from your App by following App Indexing on Google
  4. Create your Intent in your App to handle Deep Linking
  5. Install and implement Xamarin.GooglePlayServices.AppIndexing or Xamarin.Google.iOS.AppIndexing

Overall it is one of the more complex setup’s I have seen.

Website Linking

I covered this part in Android App Links (Create Your Assets.json), that is most of what you need to do. Google automatically checks your assets.json file on your website and starts indexing as appropriate. You do need to register your app but we will go through this a bit further below.

Google Search Console

Go to Google Search Console and register your site. Make sure you use the same account as your Google Play Store Account that has your app. Enter in your Android package name.

Second make sure you have added your website as a property as well. You can change “Android App” to “Website” to do this.

AddProperty

Now associate your App with your website by going to App Associate Site.

Verify Your Website and App

Next is the final piece to connect your website and app together in Google’s view. This involves 12 steps and I am just going to direct you to the App Indexing on Google Search page to follow these steps to complete this section.

Handling Deep Linking

Next you need to get your app to recognize when it has been opened via an App Link. I go through this in Android App Links. You will need to Create An Intent and this registers your app with the device to tell it that you want your app to open when a URL matching your website address is clicked. After the app opens you may want it to go to a specific page, have a look at Handle App Launch that details this process.

Controlling Access

You might not want every page on your website to launch your app as your app might not be able to handle them as they don’t have a native counterpart. You can create a noindex.xml file.

 <?xml version="1.0" encoding="utf-8"?>
 <search-engine xmlns:android="http://schemas.android.com/apk/res/android">
     <noindex android:value="notification"/>
     <noindex uri="http://appindexingsample.com/teachers/hidden-page"/>
     <noindex uriPrefix="http://appindexingsample.com/chefs/hidden_prefix"/>
 </search-engine>

Place in this file in your resources folder under a folder called xml.

xml/noindex.xml

Reference it in AndroidManifest.xml as shown below

<application>
    <activity android:name="com.xamarin.app" ...>
    ...
    </activity>
    <meta-data android:name="search-engine" android:resource="@xml/noindex"/>
</application>

App Indexing API

To enhance this further you can track which pages inside your app people are visiting if the user agrees to it. This isn’t a business analytics product, this is for Google to see what the users are doing inside your app and adjust their search results based off that. It also lets the activity inside the app be visible on the users search autocomplete and history.

In Android you need the Xamarin.GooglePlayServices.AppIndexing package. Then for each activity you need to implement the below code to tell Google when someone is viewing a page in your app related to a URL.

public class MainActivity : AppCompatActivity
{ 
    private GoogleApiClient _client = null;
    private string url, title, description, schema = "";
    protected override void OnCreate(Android.OS.Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        
        ...
 
        _client = new GoogleApiClient.Builder(this).AddApi(AppIndex.API).Build();
        url = "the url you are viewing";
        title = "title of the page";
        description = "description of the page";
        // Check out https://schema.org/docs/full.html for a full list of schemas
        schema = "http://schema.org/Recipe";
     }
 
     public IndexingAction AppIndexAction
     {
         get
         {
             // Yes it's really called Thing.Builder in the API. I didn't make that up.
             var item = new Thing.Builder()
                                 .SetName(title)
                                 .SetDescription(description)
                                 .SetUrl(Android.Net.Uri.Parse(url))
                                 .Build();
 
              var thing = new IndexingAction.Builder(IndexingAction.TypeView)
                                            .SetObject(item)
                                            .SetActionStatus(IndexingAction.StatusTypeCompleted)
                                            .Build();
 
              return thing.JavaCast<IndexingAction>();
          }
      }
      protected override async void OnStart() 
      { 
          base.OnStart(); 
          _client.Connect(); 
          await AppIndex.AppIndexApi.StartAsync(_client, AppIndexAction); 
      } 

      protected override async void OnStop() 
      { 
          base.OnStop(); 
          await AppIndex.AppIndexApi.EndAsync(_client, AppIndexAction); 
          _client.Disconnect(); 
      }
 }

If you want to know how to do this in Xamarin Forms, then look ahead to Xamarin Forms AppLinks (coming soon). Xamarin developed a specific package just for Xamarin Forms and takes away a lot of the heavy lifting.

iOS App

You can also implement App Indexing in your iOS app. The process is the similar, however you will want to look at Universal Links to ensure you handle the app launch when coming in through a URL.

Next you need to add a reference to Xamarin.Google.iOS.AppIndexing then you must register the App via the following code below in the FinishedLaunching method.

AppIndexing.SharedInstance.RegisterApp("YOUR_ITUNES_ID");

Testing your Implementation

If you want to test what your app search result will look like, Google has 2 tools for you check your implementation.

If you want to test handling the URL on your app, have a look at Xamarin.iOS Universal Links and Xamarin.Android App Links to see implementation information.

Indexing App-Only Content

While I have previously stated that you must have a corresponding Google indexed website for your app indexing to work, there is something going on in Google to index App only content. It is not publicly available yet but you might be able to get a preview if you fill out their Indexing App-Only Content Expression of Interest form.


XAMARIN.FORMS MONTHLY NEWSLETTER

JOIN 1,000+ SUBSCRIBERS

  1. Don't miss out on updates
  2. The latest info from this site, Xamarin and the community
  3. Unsubscribe at any time*

* We use MailChimp, with double opt-in, and instant unsubscribe

Microsoft MVP | Xamarin MVP | Xamarin Certified Developer | Exrin MVVM Framework | Xamarin Forms Developer | Melbourne, Australia

Related Posts

One Comment

  1. Hazel Stenhouse

    Hello, constantly i used to check weblog posts here in the early hours in the daylight, as i like to find out more and more.

Leave A Comment?