自定义“欢迎回来”屏幕
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
个性化内容可以给您的用户带来惊喜,并根据他们的偏好、使用历史记录和语言区域,从他们与应用的第一次互动就开始提供个性化的体验。Firebase 可让您根据
Google Analytics指标,并自定义您的应用,
Firebase Remote Config控制台。Firebase
通过结合使用这两项功能,您可以自定义应用的欢迎回来
向其展示您的应用。
本指南将引导您完成在 Android 上创建自己的个性化“欢迎回来”屏幕的过程。
首先,您需要一个关联到 Firebase 项目的 Android 应用。如果您还没有这样的应用,请参阅面向 Android 的使用入门,以关联您的应用。
实现概览
实现应用个性化欢迎屏幕包括 3 个主要步骤:
- 设置 Remote Config 以存储要
个性化。例如,您能以参数的形式存储欢迎屏幕消息。这样,您就可以更新此消息而无需重新发布您的应用。
- 设置 Analytics 以定义受众群体和/或用户属性
Remote Config来定位您的用户。这两个功能都可以用于定位;然而,它们之间有很大的区别。本指南稍后将讨论它们各自的相对优势。
- 配置 Remote Config 条件,以根据以下条件自定义参数
您设置的Analytics受众群体或用户属性。
在 Remote Config 中设置参数
确定要自定义的应用元素后,请使用
Remote Config,用于存储参数。我们将在本指南的其余部分中介绍如何打造个性化欢迎屏幕消息。
在 Firebase 控制台中的操作
- 前往 Remote Config 参数
页面。Firebase如果
如果您从未在应用中配置过 Remote Config,请点击添加您的第一个
参数。
填写参数键和默认值,例如 welcome_message
和 Welcome to this sample app
。
Remote Config 参数配置。">
点击发布更改。
在 Android 应用中的操作
添加代码以读取并显示您刚在
Firebase 控制台。例如:
final FirebaseRemoteConfig config = FirebaseRemoteConfig.getInstance();
config.getInstance.fetch(CACHE_EXPIRATION_MS)
.addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
config.activateFetched();
String welcomeMessage = config.getString("welcome_message");
}
}
});
您也可以按照
在 Android 上使用 Firebase Remote Config
以读取并显示您在控制台中创建的参数。如果您
Android 演示指南
了解有效的示例应用实现。
开启开发者模式,以便在测试时立即看到配置更改。
测试是否生效
- 打开您的应用,并确保它显示参数的当前值
在 Remote Config 界面中。
- 在控制台中更改值,然后点击发布更改。
- 重启您的应用。此时应显示新的参数值。
设置Analytics受众群体或用户属性
在此步骤中,您将使用 Analytics 来定义哪些用户应看到
个性化的内容。在本演示中,我们将使用用户属性来执行此操作
但您也可以定义
受众群体。
这些方法是类似的,但您应注意,一旦用户添加到受众群体,他们就无法离开或被移除。如果用于定位的属性可能会更改,请改用用户属性。
在 Firebase 控制台中的操作
- 前往 Analytics 用户属性
页面。Firebase点击新建用户属性。
为用户属性命名并提供描述。例如,如果您基于用户是喜欢狗还是猫来自定义应用,则可以将其命名为 animal_preference
。
Analytics 用户属性配置。">
点击创建。
在 Android 应用中的操作
- 按照设置用户属性中的步骤学习如何在应用中设置用户属性。例如,您可以询问用户是喜欢猫还是狗,并相应地设置字符串值。您可以跳过在控制台中注册属性的步骤,就像在上一部分中的操作一样。
- 按照调试事件中的步骤为您的应用启用调试模式。
测试是否生效
- 打开您的应用,并导航到设置用户属性的位置。
- 打开 Analytics DebugView 页面
(位于 Firebase 控制台中)。
- 查看是否设置了任何用户属性(相应内容可能会延迟几分钟才显示)。
现在您的应用有了可配置的参数、用作变量的用户属性(或受众群体),您可以创建条件来个性化参数的值。
在 Firebase 控制台中的操作
- 前往 Remote Config
(位于 Firebase 控制台中)。
- 点击参数并进行修改。
- 点击添加条件的值。
- 选择定义新的条件。
- 为条件指定名称。例如,“喜欢猫”可反映之前的用户偏好。
在适用条件下,选择用户属性(或受众群体中的用户,如果是
您在“Analytics”中创建了一个受众群体),并选择您的参数,然后
定义与您的参数值的条件关系。
Remote Config 条件。">
点击创建条件。
输入一个值来反映新条件。例如,可以用“喵!”作为向“喜欢猫”的用户显示的欢迎信息。
点击更新以保存更改。
点击发布更改以在应用中启用新的条件和值。
测试是否生效
- 打开您的应用,并导航到设置用户属性的位置。
- 打开 Analytics DebugView 页面
(位于 Firebase 控制台中)。
- 查看是否设置了任何用户属性(相应内容可能会延迟几分钟才显示)。
- 重新启动您的应用,并验证是否已设置个性化元素。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-09-03。
[null,null,["最后更新时间 (UTC):2025-09-03。"],[],[],null,["Personalized content can delight your users and provide an experience from the\nvery first interaction with your app based on their preferences, usage history,\nand locale. Firebase allows you to define audiences based on\nGoogle Analytics metrics and customize your application with\nFirebase Remote Config directly from the Firebase console.\n\nUsing these two features together, you can customize your app's welcome back\nscreen for a repeat user based on their preferences or activity in your app.\n\nThis guide walks you through the process to create your own personalized\n\"welcome back\" screen on Android.\n\nTo get started, you'll need an Android app connected to a Firebase project. If\nyou don't already have one, see [Get started for Android](/docs/android/setup)\nto connect your app.\n\nImplementation overview\n\nImplementing your app's personalized welcome screen consists of 3 broad steps:\n\n1. **Set up Remote Config to hold parameters for the elements to be\n personalized.** For example, you might store the welcome screen message as a parameter. This way you can update the message without republishing your app.\n2. **Set up Analytics to define audiences and/or user properties for\n Remote Config to target your users.** Both features can be used for targeting; however, there are important differences between them. The relative advantages of each are discussed later in this guide.\n3. **Configure Remote Config conditions to customize your parameter based on\n the Analytics audiences or user properties you set up.**\n\nSet up parameters in Remote Config\n\nOnce you identify the elements of your app you want to customize, use\nRemote Config to store parameters. We'll explore personalizing the welcome\nscreen message in the rest of this guide.\n\nWhat to do in the Firebase console\n\n1. Go to the [Remote Config parameter](https://console.firebase.google.com/project/_/config) page in the Firebase console. If you've never configured Remote Config in your app, click **Add Your First\n Parameter**.\n2. Fill out a parameter key and default value. For example, `welcome_message`\n and `Welcome to this sample app`.\n\n Remote Config parameter configuration.\"\\\u003e\n3. Click **Publish Changes**.\n\nWhat to do in the Android app\n\n1. Add code to read and display the parameter you just added to your app in the\n Firebase console. For example:\n\n final FirebaseRemoteConfig config = FirebaseRemoteConfig.getInstance();\n config.getInstance.fetch(CACHE_EXPIRATION_MS)\n .addOnCompleteListener(this, new OnCompleteListener\u003cVoid\u003e() {\n @Override\n public void onComplete(@NonNull Task\u003cVoid\u003e task) {\n if (task.isSuccessful()) {\n config.activateFetched();\n\n String welcomeMessage = config.getString(\"welcome_message\");\n }\n }\n });\n\n You can also follow the steps in\n [Use Firebase Remote Config on Android](/docs/remote-config/get-started?platform=android)\n to read and display the parameter that you created in the console. If you get\n stuck, the [Android walkthrough](/docs/remote-config/android) guides you\n through the working sample app implementation.\n2. Turn on\n [developer mode](/docs/reference/android/com/google/firebase/remoteconfig/FirebaseRemoteConfigSettings.Builder#setDeveloperModeEnabled(boolean))\n to see config changes immediately while testing.\n\nTest that it works\n\n1. Open your app and make sure that it shows the current value of the parameter in the [Remote Config UI](https://console.firebase.google.com/project/_/config).\n2. Change the value in the console and click **Publish Changes**\n3. Restart your app. The new parameter value should be shown.\n\nSet up Analytics audiences or user properties\n\nIn this step you'll use Analytics to define the users who should see\npersonalized content. In this walkthrough, we'll use a user property to do this\nbut you could also define an\n[Audience](//support.google.com/firebase/answer/6317509?hl=en&ref_topic=6317489).\nThese approaches are similar, but you should be aware that once a user is added\nto an Audience, they cannot leave it or be removed. If the attribute you want to\nuse for targeting could change, use a user property instead.\n\nWhat to do in the Firebase console\n\n1. Go to the [Analytics user property](https://console.firebase.google.com/project/_/analytics/userproperty) page in the Firebase console. Click **New User Property**.\n2. Give the user property a name and description. For example, if you were\n customizing an app based on whether a user prefers dogs or cats, you might\n name it `animal_preference`.\n\n Analytics user property configuration.\"\\\u003e\n3. Click **Create**.\n\nWhat to do in the Android app\n\n1. Follow the steps in [Set User Properties](/docs/analytics/android/properties#set_user_properties) to learn to set your user property in your application. For example, you might ask a user if they prefer cats or dogs and set a string value accordingly. You can skip over the steps to register your property in the console as you've already done that in the previous section.\n2. Follow the steps in [Debugging Events](/docs/analytics/debugview) to enable debug mode for your app.\n\nTest that it works\n\n1. Open your app and navigate to where your user property is set.\n2. Open the [Analytics DebugView page](https://console.firebase.google.com/project/_/analytics/debugview) in the Firebase console.\n3. Look to see if any user properties have been set (there might be a few minutes of delay before anything shows up).\n\nConfigure Remote Config conditions\n\nNow that your app has parameters that can be configured, and user properties\n(or audiences) to use as variables, you can create conditions to personalize\nthe values of your parameters.\n\nWhat to do in the Firebase console\n\n1. Go to [Remote Config](https://console.firebase.google.com/project/_/config) in the Firebase console.\n2. Click your parameter to edit it.\n3. Click **Add value for condition**.\n4. Select **Define new condition**.\n5. Give your condition a name. For example, \"Prefers cats\" to reflect the user preference from earlier.\n6. Under **Applies if** , select **User property** (or **User in audience** if\n you created an Audience in Analytics), and select your parameter, and\n define a conditional relationship with your parameter values.\n\n Remote Config condition.\"\\\u003e\n7. Click **Create condition**.\n\n8. Enter a value to reflect the new condition. For example, the welcome message\n for \"Prefers cats\" could be \"Meow!\".\n\n9. Click **Update** to save your changes.\n\n10. Click **Publish Changes** to enable the new conditions and values in your\n app.\n\nTest that it works\n\n1. Open your app and navigate to where your user property is set.\n2. Open the [Analytics DebugView page](https://console.firebase.google.com/project/_/analytics/debugview) in the Firebase console.\n3. Look to see if any user properties have been set (there might be a few minutes of delay before anything shows up).\n4. Restart your app and verify that your personalized elements have been set."]]