通过内容创作和效果分析等手段,提升您的应用在 Google 搜索中的排名。
借助搜索引荐信息进行分析
您可以从 Google 搜索指向您应用的链接中提取引荐来源信息,并将这些信息用于其他分析工具。例如,我们的代码实验室中关于跟踪应用引荐的主题介绍了如何结合使用搜索引荐信息与 Google Analytics(分析),从而执行总体应用分析。
如需构建自己的解决方案来跟踪到达您的应用的搜索流量,您可以使用 Android 调试桥向您的应用传递一个测试 android.intent.extra.REFERRER_NAME
extra。以下示例命令演示如何执行此操作,假设您应用软件包名称为 package_name,且应用的网址为 www.examplepetstore.com
:
adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -e android.intent.extra.REFERRER_NAME android-app://com.google.android.googlequicksearchbox/https/www.examplepetstore.com -d http://examplepetstore.com/host_path com.examplepetstore.android
此测试模拟的场景为:在您的应用中打开一个 HTTP 网址,并传入引荐来源信息(指明流量来自 Google 应用)。
提取引荐来源信息
com.google.firebase.appindexing.AndroidAppUri 类可帮助提取引荐来源 URI。您可使用一个 Intent extra 通过以下键提供 HTTP 网址的引荐来源信息:android.intent.extra.REFERRER_NAME
。
以下示例显示了来自各种源的引荐来源值:
- Chrome:
https://www.google.com
- Google 应用:
android-app://com.google.android.googlequicksearchbox/https/www.google.com
- Googlebot:
android-app://com.google.appcrawler
- Google AdsBot App Crawler:
android-app://com.google.adscrawler
下面这段代码演示如何提取搜索引荐来源信息。
Java
public class MeasureActivity extends AppCompatActivity { @Override public Uri getReferrer() { // There is a built in function available from SDK>=22 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { return super.getReferrer(); } Intent intent = getIntent(); Uri referrer = (Uri) intent.getExtras().get("android.intent.extra.REFERRER"); if (referrer != null) { return referrer; } String referrerName = intent.getStringExtra("android.intent.extra.REFERRER_NAME"); if (referrerName != null) { try { return Uri.parse(referrerName); } catch (ParseException e) { // ... } } return null; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // ... Uri referrer = getReferrer(); if (referrer != null) { if (referrer.getScheme().equals("http") || referrer.getScheme().equals("https")) { // App was opened from a browser // host will contain the host path (e.g. www.google.com) String host = referrer.getHost(); // Add analytics code below to track this click from web Search // ... } else if (referrer.getScheme().equals("android-app")) { // App was opened from another app AndroidAppUri appUri = AndroidAppUri.newAndroidAppUri(referrer); String referrerPackage = appUri.getPackageName(); if ("com.google.android.googlequicksearchbox".equals(referrerPackage)) { // App was opened from the Google app // host will contain the host path (e.g. www.google.com) String host = appUri.getDeepLinkUri().getHost(); // Add analytics code below to track this click from the Google app // ... } else if ("com.google.appcrawler".equals(referrerPackage)) { // Make sure this is not being counted as part of app usage // ... } } } // ... } }
Kotlin
class MeasureActivity : AppCompatActivity() { override fun getReferrer(): Uri? { // There is a built in function available from SDK>=22 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { return super.getReferrer() } val intent = intent val referrer = intent?.extras?.get("android.intent.extra.REFERRER") as Uri? if (referrer != null) { return referrer } val referrerName = intent.getStringExtra("android.intent.extra.REFERRER_NAME") if (referrerName != null) { try { return Uri.parse(referrerName) } catch (e: ParseException) { // ... } } return null } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // ... val referrer = referrer if (referrer != null) { if (referrer.scheme == "http" || referrer.scheme == "https") { // App was opened from a browser // host will contain the host path (e.g. www.google.com) val host = referrer.host // Add analytics code below to track this click from web Search // ... } else if (referrer.scheme == "android-app") { // App was opened from another app val appUri = AndroidAppUri.newAndroidAppUri(referrer) val referrerPackage = appUri.packageName if ("com.google.android.googlequicksearchbox" == referrerPackage) { // App was opened from the Google app // host will contain the host path (e.g. www.google.com) val host = appUri.deepLinkUri.host // Add analytics code below to track this click from the Google app // ... } else if ("com.google.appcrawler" == referrerPackage) { // Make sure this is not being counted as part of app usage // ... } } } // ... } }
创作优质的网页和移动内容
您可以同时在应用和关联网站上提供优质内容,以提升应用的排名。这是因为我们的系统会分析这两种媒体资源之间的关联,进而确定 Web 和移动搜索结果的排名。特别要牢记以下几点:
- 确保您的关联网站符合我们的设计和内容准则。
- 遵循移动网站搜索引擎优化 (SEO) 指南中建议的做法。
为了确保向用户提供出色的搜索体验,如发现滥用、欺诈或其他损害用户搜索体验的行为,Google 可能会采取纠正措施。这些措施可能包括对您的 HTTP 网址进行降位,或将其从 Google 搜索结果中移除。