Guest article from Google I \ O 2017 and GDG Lead in
Nizhny Novgorod -
Alexander Denisov .
Hi Habr! Most recently, another international technology conference on Google, I / O 2017, was held in Mountain View, California. Someone went to California, someone came to the
I / O Extended organized by the regional offices of the GDG community, someone watched broadcast independently, and someone did not watch at all (Just in case, leave it here:
all I / O 2017 sessions are recorded ). About how good or not very good the conference was this year, opinions are contradictory, I can only say it personally, I really liked it.
Last year I was very interested in what the guys from the Firebase team are doing, and I even wrote an
article about it, so I want to tell you what's new in the Firebase ecosystem and how it can be used.
Fabric Integration
About the fact that Google acquired Fabric from Twitter, I heard some time ago, but on I / O, I personally saw Fabric Manager groups from Rich Paret from Fabric and Firebase cofounder Andrew Lee on the same stage, discussing the prospects for team unification and friendly teasing each other.

')
So, what did we get as a result of this merger? First,
Crahslytics will soon be integrated into Firebase as the main solution for crash reporting ! Already, in the Crash Reporting console we see an invitation to install the Crashlytics service and participate in its testing, and soon it will completely replace Firebase Crash Reporting.

Secondly,
integration with the Digits service now allows authentication by phone number ! Free of charge, it will be possible to carry out 10 thousand authentication per month, which should fully meet the needs of developers. A Digits SDK as an independent product in the near future will receive the status of deprecated.

I immediately wanted to screw the phone authorization to my application and show how easy it is to do it, but as it turned out the service is now available only for iOS and WEB developers, the Android version will have to wait another couple of weeks.
Dynamic hosting with Firebase Cloud Functions
Back in March, on Google NEXT'17, the guys from the Firebase team told about the launch of the new Cloud Functions for Firebase service. The service provides the ability to host small JavaScript functions directly in the Google Cloud infrastructure, and execute them in response to events caused by Firebase services or HTTP requests.
This allows customizing or
expanding the standard operation of Firebase services with its features, such as sending a welcome email to each new user (Authentication), tracking and deleting obscene language in posts or chats (Realtime Database), converting images when loading into the storage (Storage) and so on.
For those who have not tried, I will show an example of using Cloud Functions. Let's take the
FriendlyChat source code from GitHub, the application I described in last year’s article. Tie it to a clean Firebase project and add a Cloud Function that will automatically greet all new users in the chat.
The first step is to install
Node.js , and then install the Firebase Command Line Interface (CLI) with the command:
npm -g install firebase-tools
log in to the interface with the command
firebase login
create a folder for your project, go to it and create the project itself by the team
firebase init functions
As a result, a project structure will be created in the folder, go to the functions folder and find
index.js , and our functions will be stored here. If you open a file, then it will only have one line -
const functions = require ('firebase-functions') ; - this is actually the Firebase SDK connection. Add the Admin SDK connection there:
const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase);
Preparations are finished, now we implement the function itself, it will trigger the event of creating a new user in the Authentication service, that is, when the user enters the chat for the first time:
exports.addWelcomeMessages = functions.auth.user().onCreate(event => { const user = event.data; console.log('A new user signed in for the first time.'); const fullName = user.displayName || 'Anonymous';
It remains to upload the function to the cloud and that's it:
firebase deploy --only functions
you can run the application, and after authorization, the bot happily welcomes the new user in the chat.
But all this was presented before I / O! Directly on it, Firebase introduced a novelty that should please the web development community. The Firebase Hosting service, which previously allowed working only with static content, was expanded by integration with Cloud Functions, and now
works with dynamic content generated by the Cloud Functions service .
Now developers engaged in progressive web applications will be able to completely abandon their server and use only Firebase.
I'd like to give examples, but I haven’t yet written about Web development using Firebase, and the article would have turned out too big, so expect the following article completely dedicated to web development and using Cloud Functions.
Firebase Performance Monitoring
Often, insufficient performance and / or stability of the application are the main cause of user dissatisfaction. But it’s not always easy to understand why an application is not productive or stable enough to help with this difficult task, the Firebase team launched a beta test of Performance Monitoring in beta. Firebase Performance Monitoring is a new free tool that helps you understand when bad code or complex network conditions affect your user interface.
In order for the service to start collecting data on the performance of your application, you must connect the Performance Monitoring SDK, then the service will immediately begin to collect data. The service will provide reports in the form of so-called
traces (trace) - performance reports between two events in your application. Immediately after the connection, data for automatic traces will begin to be collected:
- App start trace - measures the time between when the user started the application and when the application responded
- App in background trace - measures the time the application is in the background.
- App in foreground trace - measures application activity time
Connect the service to the application to see how it looks. I took the standard application from google codelabs -
FriendlyChat and connected it to my database. Now we will connect Performance Monitoring, for this we will add to the project-level build.gradle in the buildscript → repositories section:
jcenter()
and to the buildscript section → dependencies
classpath 'com.google.firebase:firebase-plugins:1.1.0'
then in app-level build.gradle in the dependencies section
compile 'com.google.firebase:firebase-perf:10.2.6'
and under apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.firebase-perf'
Voila, the service is connected, now automatic traces are started when the application starts.
Since there are not enough automatic traces, it is possible to create custom traces using the API provided by the SDK. They can be supplemented with performance counters related to performance, for example, the number of times the UI has been unavailable for longer than a specified period of time.
Custom traces are added very simply, before the section of code that we want to trace we add:
Trace myTrace = FirebasePerformance.getInstance().newTrace("test_trace"); myTrace.start();
and after the plot
myTrace.stop();
I added the tracing of the download image to the chat, well, for the sake of interest, add a counter
myTrace.incrementCounter("storage_load");
But the results in the console are not immediately available, they will appear there within 12 hours.

Advanced Analytics
To begin with, Firebase Analytics no longer exists, now the service is called
Google Analytics for Firebase , and this is no accident. The service was developed jointly by the Firebase and Google Analytics teams, and all reports are now available not only in the Firebase console, but also in the Google Analytics interface.


New report types StreamView and DebugView were presented at the beginning of the year, but this does not detract from their degree of usefulness. StreamView visualizes events as they arrive in Firebase Analytics and provides an overview of how your users interact with your application in real time, rather than with a delay of up to 12 hours. And with DebugView, you can see at a glance which events are logged.

And one more news that everyone has been waiting for, now analytic
information on user events and parameters can be viewed in reports directly in the console , and not upload data to BigQuery, as it was necessary earlier. To do this, just adjust the report parameters in the same console.
Added all sorts of interesting features, integration with AdMob, automatic Screen Tracking, free Storage Tier in BigQuery .... so I suppose that analytics still have to write a separate article.
Firebase SDK - now in open source
Yes it is. The source code for the Firebase SDK is now available for review on GitHub. Not all of course, at the moment, the source is available
Firebase iOS SDK 4.0 ,
Firebase JavaScript SDK 4.0 and Firebase Admin SDKs (
Node.js ,
Java and
Python ). The following promise to lay out the Android SDK, we look forward to.

Now you can correct Google, if something in the code you do not like! That is, now, if you find any bugs from your point of view, you can simply create an issue through the standard GitHub issue tracker and the Firebase team will consider it. The entire project can also be found in the
Google Open Source Directory .
Pleasant trifles
And finally, I will briefly talk about all the nice little things that have been added to existing services.
Realtime Database:
- Expanded capabilities, now available up to 100,000 simultaneous connections
- Added the ability to profile, profiler allows you to analyze the speed of working with data, throughput and delay time depending on the level
Storage:
- Added mapping to existing cloud storage bucket, now you can work with them via Firebase
- Now you can choose the region in which your data will be stored. This can be useful both from a legal point of view and in terms of performance.
Cloud Messaging:
- Token authentication support for APN has been added, and the connection and registration logic in the client's SDK has been greatly simplified.
TestLab:
- Added Game Loop support and FPS monitoring, which, in combination with the Unity SDK and C ++ SDK presented earlier, should make Firebase attractive for game developers.
- Added the ability to simulate the network level, you can select the connection speed 4G, 3G, etc.
- In the data center appeared Google Pixel and Galaxy S7 for testing applications on real devices of the latest generation
- Appeared access to Android O
And also, without being tied to any of the services, I’ll add that Swift support was implemented in the iOS SDK, which should please iOS developers working with Firebase.
So, what conclusions can be drawn? Nothing super unexpected and amazing on the I / O was presented. But Firebase is growing, growing slowly and confidently. Using its services as a backend it is already possible to create completely competitive applications, analyze their work, manage their promotion and monetize. And the further, the more interesting tools appears to users.
PS: On I / O, an interesting offer was announced from Firebase -
Alpha program (it won't open without VPN). Those who register and express their desire to participate in the program will have the opportunity to check for updates to the Firebase services prior to their release. They will not be perfect (I think that in some places quite raw), but by taking part in the Alpha community, forming feedback on products that are not yet released, you will help determine the future of Firebase!