> ## Documentation Index
> Fetch the complete documentation index at: https://docs.choicely.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Firebase Project Setup

> Create and configure a Firebase project for your Choicely app

## Create Choicely Brand and App

To create Choicely brand and App visit [Choicely Tutorials](https://www.choicely.com/tutorials/how-to-create-apps-with-choicely-using-an-app-template).

## Create and link Firebase project with your app and Choicely Studio

1. Go to [Firebase Console](https://console.firebase.google.com/) and create a new project.

2. Give it a name, accept the Firebase terms and click "Continue".

3. Enable and configure Google Analytics if needed and click "Create Project".

4. When your Firebase project will be ready click "Continue". You will be redirected to your project's overview page.

5. Hit the gear icon and select "Project settings" to see your Porject name and Project ID.

   <Frame>
     <img src="https://mintcdn.com/choicely/5ATW2QVKA6uvu958/images/mobile-sdk/firebase-project-settings.png?fit=max&auto=format&n=5ATW2QVKA6uvu958&q=85&s=1c69af27c223271aae72c0715edef1f3" alt="Firebase project settings" width="442" height="216" data-path="images/mobile-sdk/firebase-project-settings.png" />
   </Frame>

6. Copy your Porject name and Project ID. Go to your app's Choicely Studio, select "Settings" -> "General Settings" -> "Firebase settings".

   <Frame>
     <img src="https://mintcdn.com/choicely/5ATW2QVKA6uvu958/images/mobile-sdk/studio-general-settings.png?fit=max&auto=format&n=5ATW2QVKA6uvu958&q=85&s=6c8c3853f396471752cdec538e7ce6a7" alt="Studio General settings" width="986" height="542" data-path="images/mobile-sdk/studio-general-settings.png" />
   </Frame>

7. Click "edit" on your predefined Firebase project and set the Porject name with Project ID. Click the "Save" button.

   <Frame>
     <img src="https://mintcdn.com/choicely/5ATW2QVKA6uvu958/images/mobile-sdk/studio-firebase-settings.png?fit=max&auto=format&n=5ATW2QVKA6uvu958&q=85&s=b676f2bf9464a2e0e636d321224ba7d6" alt="Studio Firebase settings" width="371" height="603" data-path="images/mobile-sdk/studio-firebase-settings.png" />
   </Frame>

   <Note>
     If you want to enable realtime updates feature you will need to set a "Database url" too. See the next section to learn where to get it.
   </Note>

8. In order to link the Firebase Project with your apps go back to Firebase project overview page and click "Add app". Follow the instructions to add all app platforms you need.

   <Frame>
     <img src="https://mintcdn.com/choicely/5ATW2QVKA6uvu958/images/mobile-sdk/firebase-platforms.png?fit=max&auto=format&n=5ATW2QVKA6uvu958&q=85&s=27fc8649f8e9ce3ab087a13db421e66d" alt="Firebase platforms" width="414" height="132" data-path="images/mobile-sdk/firebase-platforms.png" />
   </Frame>

## Enable Firebase realtime updates feature

1. On your Firebase project overview page go to "Build" menu section and select "Realtime Database". Click "Create Database" button, select an appropriate server location and data write rules. Click "Enable" button.

2. Copy the realtime database rules into your clipboard. You will need them in the next step.

   ```json theme={null}
   {
     "rules": {
       "apps":{
         "$app_key":{
           ".read": true,
           ".write": false
         }
       },
       "screens":{
         "$screen_key":{
           ".read": true,
           ".write": false
         }
       },
       "articles":{
         "$article_key":{
           ".read": true,
           ".write": false
         }
       },
       "contests":{
         "$contest_key":{
           ".read": true,
           ".write": false
         }
       },
       "conventions":{
         "$convention_key":{
           ".read": true,
           ".write": false
         }
       },
       "feeds":{
         "$feed_key":{
           ".read": true,
           ".write": false
         }
       },
       "surveys":{
         "$survey_key":{
           ".read": true,
           ".write": false
         }
       },
       "shops":{
         "$shop_key":{
           ".read": true,
           ".write": false
         }
       },
       "maps":{
         "$map_key":{
           ".read": true,
           ".write": false
         }
       },
       "users":{
         "$user_id":{
           ".read": "$user_id === auth.uid",
           ".write": "$user_id === auth.uid",
           "email": {
               ".write": "$user_id === auth.uid"
           },
           "year_of_birth": {
               ".write": "$user_id === auth.uid"
           },
           "name": {
               ".write": "$user_id === auth.uid"
           },
           "gender": {
               ".write": "$user_id === auth.uid"
           },
           "consents": {
               ".write": "$user_id === auth.uid"
           },
           "updated": {
               ".write": "$user_id === auth.uid"
           },
           "$other": {
               ".write": false
           },
           "city": {
               "countryCode": {
                   ".write": "$user_id === auth.uid"
               },
               "id": {
                   ".write": "$user_id === auth.uid"
               },
               "name": {
                   ".write": "$user_id === auth.uid"
               },
               "stateName": {
                   ".write": "$user_id === auth.uid"
               },
               "$other": {
                   ".write": false
               },
               ".write": "$user_id === auth.uid"
           }
         }
       },
       "$other": {
         ".read": false,
         ".write": false,
         ".validate": false
       },
       ".write": false
     }
   }
   ```

3. In the opened Realtime Database page go to "Rules" tab, paste the rules from previous step and click "Publish".

   <Frame>
     <img src="https://mintcdn.com/choicely/5ATW2QVKA6uvu958/images/mobile-sdk/realtime-database-rules.png?fit=max&auto=format&n=5ATW2QVKA6uvu958&q=85&s=e145fe95b366e56d5da2e8197f8d4b39" alt="Firebase realtime database rules" width="2528" height="1397" data-path="images/mobile-sdk/realtime-database-rules.png" />
   </Frame>

4. Go to "Data" tab on Realtime Database page, copy the database url, paste it in your app's Studio Firebase settings and click "Save":

   <Frame>
     <img src="https://mintcdn.com/choicely/5ATW2QVKA6uvu958/images/mobile-sdk/firebase-settings-database.png?fit=max&auto=format&n=5ATW2QVKA6uvu958&q=85&s=e905b57819433e1885ca9ec8011fd17f" alt="Firebase settings database url" width="371" height="603" data-path="images/mobile-sdk/firebase-settings-database.png" />
   </Frame>

5. The next thing to do is to get the Web API key. On your Firebase project overview page go to "Build" -> "Authentication" side menu section. Click "Get Started button" and select "Google" as a provider.

   <Frame>
     <img src="https://mintcdn.com/choicely/5ATW2QVKA6uvu958/images/mobile-sdk/authentication.png?fit=max&auto=format&n=5ATW2QVKA6uvu958&q=85&s=db5e631553539f7060a24e0d25bbcab3" alt="Authentication" width="920" height="310" data-path="images/mobile-sdk/authentication.png" />
   </Frame>

6. Enable Google as a Sign-in provider, set your support email and click "Save".

   <Frame>
     <img src="https://mintcdn.com/choicely/5ATW2QVKA6uvu958/images/mobile-sdk/enable-google.png?fit=max&auto=format&n=5ATW2QVKA6uvu958&q=85&s=2f8378b24f26f6907455aa2ee93e4358" alt="Enable Google" width="734" height="582" data-path="images/mobile-sdk/enable-google.png" />
   </Frame>

7. Now you have your Web API Key set under "Project Overview" -> "Project settings" -> "General" tab. Copy and paste it in your app's Studio Firebase settings.

   <Frame>
     <img src="https://mintcdn.com/choicely/5ATW2QVKA6uvu958/images/mobile-sdk/firebase-settings-web.png?fit=max&auto=format&n=5ATW2QVKA6uvu958&q=85&s=d5b98f1a556638e14773ddf7dcce062c" alt="Firebase settings web API key" width="371" height="600" data-path="images/mobile-sdk/firebase-settings-web.png" />
   </Frame>

8. Double check your apps `GoogleService-Info.plist`. The `DATABASE_URL` property should be the same as database url you pasted in Studio Firebase settings.

9. Go to [Google Cloud Console](https://console.cloud.google.com/) and select your project. Open the side menu and navigate to "IAM and admin" -> "IAM" section. Click "Grant access" button Under "Allow" and "View by principals" tabs.

   <Frame>
     <img src="https://mintcdn.com/choicely/5ATW2QVKA6uvu958/images/mobile-sdk/firebase-iam-section.png?fit=max&auto=format&n=5ATW2QVKA6uvu958&q=85&s=2160e3068889d9cb866a9a7c018f54de" alt="Firebase IAM section" width="760" height="406" data-path="images/mobile-sdk/firebase-iam-section.png" />
   </Frame>

10. Add `choicely-studio@choicely.iam.gserviceaccount.com` as principal and assign "BigQuery Data Viewer" with "Firebase Admin" roles to it. Click the "Save" button.

    <Frame>
      <img src="https://mintcdn.com/choicely/5ATW2QVKA6uvu958/images/mobile-sdk/firebase-grant-access.png?fit=max&auto=format&n=5ATW2QVKA6uvu958&q=85&s=9d7cff4d5640b886dd28585662a9f31f" alt="Firebase grant access" width="533" height="815" data-path="images/mobile-sdk/firebase-grant-access.png" />
    </Frame>

11. That's it! You're now ready to start using realtime updates features in your apps.
