# Firebase Cloud Messaging Export Integration Firebase is a mobile- and web application development platform that helps you deliver richer app experiences. You can send direct notifications to your mobile app and website through Firebase Cloud Messaging. The Realtime Database and Cloud Firestore can stock document-structured data and synchronize the corresponding apps in milliseconds whenever a data transformation occurs. The app and its database listen to each other, providing your customers with a more reactive app experience. Using Firebase **Cloud Functions you** can write backend code to respond to events happening in the Firebase platform without having to deal with any servers. ## Prerequisites - Basic knowledge of Treasure Data, including the [TD Toolbelt](https://toolbelt.treasuredata.com/). - A Google Firebase Project. - For substitution, NULL values will be truncated to ““ (empty string). If the substitution is for a numeric column, there will be a warning and the record is skipped. - Because the messages are sent individually, we will not revert the whole sessions. The error messages are logged to the TD Console, but the job will continue. - Strong knowledge of the Firebase message template structure. ## Use the TD Console to Create Your Connection ### Create a New Connection When you configure a data connection, you provide authentication to access the integration. In Treasure Data, you configure the authentication and then specify the source information. 1. Open TD Console. 2. Navigate to Integrations Hub > Catalog. 3. Search for and select Firebase. ![](/assets/image-20200519-215903.52e326f47355487197798de2bf799b978ede99fd43793a96f2bf4f3963567dfb.0991c1f0.png) The following dialog opens. ![](/assets/image-20200519-220112.b3533425c4b5b067b33da54249c7783ede22ec31f9adcac96cf169b3a4617631.0991c1f0.png) 4. Type or paste the credential from your [Google Developer Console service account](https://firebase.google.com/docs/cloud-messaging/auth-server). ![](/assets/image-20200608-200049.7b4d29c1032bfd3d5b58712d5bdaaa6e1fab724027656cd2a19f8f3d48307243.0991c1f0.png) 1. Select **Done.** - See [Firebase document](https://firebase.google.com/docs/admin/setup#:~:text=To%20authenticate%20a%20service%20account,confirm%20by%20clicking%20Generate%20Key) to create a new service account key. ## Configure Export Results in Your Data Connection In this step, you create or reuse a query. In the query, you configure the data connection. ### Configure the Connection by Specifying the Parameters 1. Open the TD Console. 2. Navigate to **Data Workbench** > **Queries**. 3. Select the query that you plan to use to export data. 4. Select **Export Results** located at top of your query editor. The Choose Integration dialog opens. You have two options when selecting a connection to use to export the results, using an existing connection or creating a new one. ![](/assets/image-20200605-093602.2443bc93d261fe564b0e947b2b2acd38be82163c057edda478c09aea5fda086d.0991c1f0.png) 5. Use an existing connection 1. Type the connection name in the search box to filter. 2. Select your connection 3. Specify the export details. ![](/assets/image-20200623-143430.689552521d31473cb2941b2ae836f5d9fdd00cbe62b4d20f95a5039f6efaebfb.0991c1f0.png) - **Project Id:** project ID of your Firebase project. - **Message Template:** the connector replaces all substitution columns and aliases (___column_name___) in the template to the individual messages to send Firebase Message. All substitution columns and aliases exist in the export data. - **Fast Mode:** Enable parallel run with no validations, no errors logs and no retries. Default: false - **Max retries** (optional): Number of retries before the system gives up. Default: 7. - **Initial retry time wait in milliseconds** (optional): The time, in milliseconds, between the first and second attempt. Default: 500, which is equivalent to 0.5 seconds. - **Max retry wait in milliseconds** (optional): The time, in milliseconds, between the second and all subsequent attempts. Default: 300000, which is equivalent to 5 minutes. The following is a sample template configuration: ```json { "message": { "notification": { "title": "___title___", "body": "___body___" }, "topic": "weather" } } ``` ![](/assets/image-20200623-144229.34358ba75e480b13a162dab769c2126080ea906eafc0c2b61026b07cae2cfaaa.0991c1f0.png) ### Example of a Query to Populate Firebase From Treasure Data, run the following query and export results to a connection for Firebase: ```SQL Select 'test_body' as body, 'test_title' as title ``` ### Optionally Use Scheduled Jobs for Export You can use Scheduled Jobs with Result Export, to periodically write the output result to a target destination that you specify. ## Activate a Segment in Audience Studio You can also send segment data to the target platform by creating an activation in the Audience Studio. 1. Navigate to **Audience Studio**. 2. Select a parent segment. 3. Open the target segment, right-mouse click, and then select **Create Activation.** 4. In the **Details** panel, enter an Activation name and configure the activation according to the previous section on Configuration Parameters. 5. Customize the activation output in the **Output Mapping** panel. ![](/assets/ouput.b2c7f1d909c4f98ed10f5300df858a4b19f71a3b0834df952f5fb24018a5ea78.8ebdf569.png) - Attribute Columns - Select **Export All Columns** to export all columns without making any changes. - Select **+ Add Columns** to add specific columns for the export. The Output Column Name pre-populates with the same Source column name. You can update the Output Column Name. Continue to select **+ Add Columns**to add new columns for your activation output. - String Builder - **+ Add string** to create strings for export. Select from the following values: - String: Choose any value; use text to create a custom value. - Timestamp: The date and time of the export. - Segment Id: The segment ID number. - Segment Name: The segment name. - Audience Id: The parent segment number. 1. Set a **Schedule**. ![](/assets/snippet-output-connector-on-audience-studio-2024-08-28.a99525173709da1eb537f839019fa7876ffae95045154c8f2941b030022f792c.8ebdf569.png) - Select the values to define your schedule and optionally include email notifications. 1. Select **Create**. If you need to create an activation for a batch journey, review [Creating a Batch Journey Activation](/products/customer-data-platform/journey-orchestration/batch/creating-a-batch-journey-activation). i ## Optionally Configure Export Results in Workflow Within Treasure Workflow, you can specify the use of this data connector to export data. ```yaml timezone: UTC _export: td: database: sample_datasets +td-result-into-firebase: td>: queries/sample.sql result_connection: your_connections_name result_settings: service_account_json: '{"type":"service_account","project_id":"project_id","private_key_id":"####"}' project_id: project_id message_template: {"message":{"notification":{"title":"___title___","body":"___body___"},"topic":"weather"}} fast_mode: true retry_count: 7 retry_initial_wait_millis: 500 max_retry_wait_millis: 300000 ``` Optionally, read more information on using data connectors in [workflow to export data](/int/treasure-data-data-exchange-export-integration).