diff --git a/skills/firebase-remote-config-basics/SKILL.md b/skills/firebase-remote-config-basics/SKILL.md new file mode 100644 index 0000000..a58b007 --- /dev/null +++ b/skills/firebase-remote-config-basics/SKILL.md @@ -0,0 +1,34 @@ +--- +name: firebase-remote-config-basics +description: Comprehensive guide for Firebase Remote Config, including template management and SDK usage. Use this skill when the user needs help setting up Remote Config, managing feature flags, or updating app behavior dynamically. +compatibility: This skill is best used with the Firebase CLI, but does not require it. Firebase CLI can be accessed through `npx -y firebase-tools@latest`. +--- + +# Remote Config + +This skill provides a complete guide for getting started with Remote Config on Android or iOS. Remote Config allows you to change the behavior and appearance of your app without publishing an app update by maintaining a cloud-based configuration template. + +## Prerequisites + +Provisioning Remote Config requires both a Firebase project and a Firebase app, either Android or iOS. To manage the Remote Config template and conditions via the command line, use the Firebase CLI. See the `firebase-basics` skill for references on project initialization. + +## SDK Setup + +To learn how to set up Remote Config in your application code, choose your platform: + +* **Android**: [android_setup.md](references/android_setup.md) +* **iOS**: [ios_setup.md](references/ios_setup.md) + +## SDK Usage + +The SDK provides a number of features to make your application dynamic and responsive to user segments. + +* **Set In-App Defaults**: Define baseline values to ensure the app functions offline or before the first fetch. +* **Fetch and Activate**: Retrieve values from the Firebase backend and apply them to the local UI/Logic. +* **Real-time Updates**: Listen for server-side configuration changes to update the app instantly without a refresh. +* **Template Management**: Use the Firebase CLI to version-control, get, and deploy your config JSON files. + +To learn how to implement advanced targeting, conditions, and A/B testing, consult the documentation for your platform. + +* **Android**: [Get started with Firebase Remote Config on Android](https://firebase.google.com/docs/remote-config/get-started?platform=android) +* **iOS**: [Get started with Firebase Remote Config on Apple Platforms](https://firebase.google.com/docs/remote-config/get-started?platform=ios) \ No newline at end of file diff --git a/skills/firebase-remote-config-basics/references/android_setup.md b/skills/firebase-remote-config-basics/references/android_setup.md new file mode 100644 index 0000000..d360557 --- /dev/null +++ b/skills/firebase-remote-config-basics/references/android_setup.md @@ -0,0 +1,100 @@ +# Firebase Remote Config Android Setup Guide + +Important references: + +- Refer to the `firebase-basics` skills, particularly those for project and app setup, before proceeding. + +## Project and App Setup + +Before you begin, ensure you have the following. If a `google-services.json` file is present, then use that Firebase project and app. Otherwise you may need to create them. + +- **Firebase CLI**: Installed and logged in (see `firebase-basics`). +- **Firebase Project**: Created via `npx -y firebase-tools@latest projects:create` (see `firebase-basics`). +- **Firebase App**: Created via `npx -y firebase-tools@latest apps:create ` + +The `google-services.json` file must be present in the Android app's module directory. If missing, get the config using the Firebase CLI: `npx -y firebase-tools@latest apps:sdkconfig ANDROID `. + +## Add Dependencies to Gradle Build + +These changes are made to your Android project's Gradle files. Google Analytics is highly recommended as it enables conditional targeting based on user properties and audiences. + +### Project-level `build.gradle.kts` (`/build.gradle.kts`) + +Ensure the Google Services plugin is in the `plugins` block: + +```kotlin +plugins { + // ... other plugins + id("com.google.gms.google-services") version "4.4.0" apply false +} +``` + +### App-level `build.gradle.kts` (`//build.gradle.kts`) + +1. Add the Google Services plugin to the `plugins` block: + + ```kotlin + plugins { + // ... other plugins + id("com.google.gms.google-services") + } + ``` + +2. Add the Firebase Remote Config and Analytics dependencies. Using the Firebase Bill of Materials (BoM) is the best practice for version management. + + ```kotlin + dependencies { + // ... other dependencies + + // Import the Firebase BoM + implementation(platform("com.google.firebase:firebase-bom:32.7.0")) + + // Add the dependencies for Remote Config and Analytics + implementation("com.google.firebase:firebase-config") + implementation("com.google.firebase:firebase-analytics") + } + ``` + + +## Follow up Steps + +The following steps cover the essential patterns for using Remote Config effectively. + +### Set In-App Defaults +Define default values so your app has functional logic before it ever fetches a template from the server. Create an XML file (e.g., `res/xml/remote_config_defaults.xml`): + ```xml + + + + welcome_message + Welcome to the app! + + + is_feature_enabled + false + + + ``` +Then, initialize the SDK in your Activity or Application class: + + ```kotlin + val remoteConfig = Firebase.remoteConfig + remoteConfig.setDefaultsAsync(R.xml.remote_config_defaults) + ``` + + +### Fetch and Activate Values +To apply values from the cloud, you must fetch them and then activate them. + ```kotlin + remoteConfig.fetchAndActivate() + .addOnCompleteListener(this) { task -> + if (task.isSuccessful) { + val updated = task.result + println("Config params updated: $updated") + } else { + println("Fetch failed") + } + // Access a value + val message = remoteConfig.getString("welcome_message") + } + ``` \ No newline at end of file diff --git a/skills/firebase-remote-config-basics/references/ios_setup.md b/skills/firebase-remote-config-basics/references/ios_setup.md new file mode 100644 index 0000000..bd1b520 --- /dev/null +++ b/skills/firebase-remote-config-basics/references/ios_setup.md @@ -0,0 +1,71 @@ +# Firebase Remote Config iOS Setup Guide + +Important references: + +- Refer to the `firebase-basics` skills, particularly those for iOS setup, before proceeding. +- Refer to the `xcode-project-setup` skills. + +## Project and App Setup + +Use the `firebase-tools` CLI to set up the project if necessary. + +1. **Find Bundle ID:** Read the Xcode project to find the iOS bundle ID. Check the `PRODUCT_BUNDLE_IDENTIFIER` value in the `.pbxproj` file or the `Info.plist` file. +2. **Create Firebase Project:** If no project exists, create one: + `npx -y firebase-tools@latest projects:create --display-name="My Awesome App"` +3. **Create Firebase App:** Register the iOS app with the discovered bundle ID: + `npx -y firebase-tools@latest apps:create IOS ` +4. **Link the GoogleService-Info.plist file:** Use the script in the `xcode-project-setup` skill to obtain the config and link. + +## Add Swift Package Dependencies + +Install the Remote Config and Analytics SDKs using the Swift package manager, or the script in the `xcode-project-setup` skill. + +Install the `FirebaseRemoteConfig` and `FirebaseAnalytics` packages from the [https://github.com/firebase/firebase-ios-sdk.git](https://github.com/firebase/firebase-ios-sdk.git) repository. + +## Initialize Firebase in App Code + +Modify the application's entry point to initialize Firebase. Refer to the iOS setup reference in the firebase-basics skill. + +## Follow up Steps + +The following steps cover the essential patterns for using Remote Config effectively in your iOS app. + +### Set In-App Defaults +Define default values so your app behaves as intended before it connects to the backend. Create a property list file (e.g., RemoteConfigDefaults.plist): + + ```xml + + + + + welcome_message + Welcome to the app! + is_feature_enabled + + + + ``` + +Then, initialize the SDK and set the defaults: + + ```swift + import FirebaseRemoteConfig + + let remoteConfig = RemoteConfig.remoteConfig() + remoteConfig.setDefaults(fromPlist: "RemoteConfigDefaults") + ``` +### Fetch and Activate Values +To retrieve values from the cloud and apply them to your app: + + ```swift + remoteConfig.fetchAndActivate { (status, error) in + if status == .successFetchedFromRemote || status == .successUsingPreFetchedData { + print("Config fetched and activated!") + } else { + print("Config not fetched") + } + + // Access a value + let message = remoteConfig.configValue(forKey: "welcome_message").stringValue + } + ``` \ No newline at end of file