[MUSIC PLAYING]
DOUG STEVENSON: Hey, everybody.
Welcome to "#AskFirebase."
My name is Doug Stevenson, @CodingDoug on Twitter.
And fun fact about me--
I'm not wearing any pants under here.
It's a little breezy.
For those of you who haven't seen the show before,
you ask the questions, and I give the answers.
And hopefully, one of them will be right.
So without further ado, let's get to the first question.
This question comes from Doc Wheeler on YouTube.
"Hey, there."
Hey, there back at you, Doc.
"Can Google Analytics for Firebase
be used during development?
I'd like to show stakeholders what
the analytics for the mobile app would look like."
Doc, I have two things to say about that.
First, tell them to put down the steaks.
It's not very sanitary.
Second thing is, you've probably noticed
that Google Analytics for Firebase in the console
doesn't look very exciting.
If you only have a couple of users,
you can use it during development.
But it's just not going to give you
a very accurate view of how your development users are actually
using your app.
Instead, why don't you send them to the Firebase Console?
There's a demo app there that has very rich analytics.
It comes from a game called "Flood It,"
and you can download that from the market.
You can also watch a brief presentation
I gave about that at the Firebase Summit in Berlin.
The link to that is in the description below.
But when you go to the Console, there's
a box there with a plus sign on it
that you use to create a project.
Just below that, there's a box that says, Explore a Demo App.
Click that, that will take you to the Firebase Console, where
you can see all the rich analytics from "Flood It."
There's thousands of users who are using it.
It's really cool to look at.
Send your stakeholders there, but only
after they wash their hands.
Thanks for the question, doc.
Next question.
This next question comes from Mike on the Firebase Slack.
"How do I write code that observes security rules when
using the Admin SDK?"
I'll tell you why he's asking this.
Normally when you initialize the Admin SDK,
you do so with admin privileges, which means you get full read
and write access throughout the database,
regardless of any security rules or validation
rules that might be in place.
What Mike wants to do, is he wants
to use the Admin SDK to do rights
that observe those rules.
So if a right would trigger a violation of a security rule,
that should fail.
And it turns out you can do this if you initialize the Admin
SDK with the database auth variable override property
and the initialization object.
That's a lot of words.
But the result of that is if you give it a user ID to simulate,
that user ID will then essentially be simulated
for all the read and write.
So at that point, if you trigger a security rule that
would cause the right to fail, it will fail, and you'll know.
And so that's what you can do to make sure
the Admin SDK observes security rules.
Great question.
Oh, if you haven't seen the Firebase Slack,
sign up for that today.
If you go to Firebase.community--
that's a weird URL, but you can type it
in your browser-- do that.
You can sign up for the Firebase Slack
and you can chat with lots of people who are using Firebase,
and even some of the staffers.
It's a lot of fun.
Check it out.
I'll see you there.
Next question.
So addictive.
This next question comes from Martin on Stack Overflow.
"Is there a way to perform a transaction
when writing data to Realtime Database with the REST API?"
Now, this is a great question because, up until recently,
there was no way to do that.
So let's unpack this a little bit more.
In Realtime Database, a transaction
is necessary to prevent two clients from clobbering
each other's data if they both want
to write it at the same time.
We obviously need a way to prevent that.
Well, with the way Realtime Database handles it,
is it gives you a transaction mechanism
to allow the clients to go back and forth through the server
to negotiate what the value should be
at the end of the transaction.
You might use this if you were, say, incrementing a counter.
You have two clients that want to increment,
but they need to do it in a certain order.
So the transaction will help prevent both clients
from incrementing incorrectly.
So that's a transaction.
But you couldn't do that with the REST API in the past.
But as of today, now you can do transactions with the REST API.
As you know, REST API goes over HTTP.
And this new feature allows you to use the ETag header
of the HTTP request to go back and forth through the server
to manage what the correct value should be.
Go read the blog post on that.
The link is in the description below.
It should come pretty handy if you're a user of the REST API.
Great question.
Thanks, Martin.
Next question.
This next question comes from Alexander on YouTube.
And Alexander asks, "Is there a Kotlin API
for Cloud functions?"
The answer is, kind of.
As you know, Kotlin's a language that you
use to build Android apps, and maybe server apps as well.
It compiles down to Bytecode normally.
But it turns out, Kotlin also compiles down to JavaScript.
As you know, JavaScript is a language
that you can use to build Cloud functions.
And if you can use Kotlin to build JavaScript and JavaScript
can be used to build a Cloud functions,
it stands to reason you could use Kotlin
to build Cloud functions.
You can totally do this.
I played with it earlier.
It works, but it's not exactly the most pleasing experience.
It turns out you need this extra tooling in place
to do this transpiling of Kotlin to JavaScript, which is
extra work, extra maintenance.
Also, you end up writing what amounts
to code that looks exactly like JavaScript,
it's just in a Kotlin file.
Which, there's not a whole lot of advantage to doing that.
So what I recommend instead is using an editor
like VS Code, which is JavaScript-aware.
Many of us here on the Firebase channel on YouTube
use VS Code for our JavaScript presentations.
You'll notice it has fun things like auto completion and code
help.
So it's very JavaScript-aware, very smart.
It's a blast.
That's what I recommend you use instead of Kotlin, for now.
Great question.
Thanks for the question.
This next question comes from Damej on YouTube.
"Where can I get a Firebase shirt?"
And a lot of people ask this question, especially when
I post pictures of the shirts that we're
giving away at various events.
So we have a blue shirt like this one, or a black shirt.
Both are very fun, very comfortable.
To get a shirt, you will have to go to one of the events
that Firebase sponsors or that we speak at.
If you want to know what events are coming up,
follow us on Twitter.
We'll let you know what's coming up.
Thanks for the question, Damej.
Time for the next question.
This next question comes from Agus on YouTube.
"Hi, Firebase," smiley--
Hi, Agus.
"I'm building an Android app with Firebase,
and I want to send a notification to the app
when something changes in the database.
How can I build that?"
Turns out, you can do this with Cloud Functions for Firebase.
What you do is you write a database trigger,
and you specify in that database trigger
the location of the database that, when it changes,
should trigger your function.
And then after that, you can use the Admin SDK
to send the notification.
It's actually pretty easy, and it's very commonly requested.
In fact, it's so common that we've actually
written some sample code for you to get started.
There's a link to GitHub in the description below that
will take you right to a sample project.
So get started with that.
Great question, Agus.
Thank you.
This is so much fun.
I can't put it down.
It's so hard to put down.
I'm going to put it down right--
I need to-- I need to get it out of my hands.
I need to put it down.
[DELIGHTFUL PING]
All right, this next question comes from Ahmer, also
on YouTube.
Ahmer asks, "Could you please explain the phone number
authentication in a video?"
I'd be happy to do that, Ahmer, except it's already been done
by my pal Laurence Maroney.
Laurence, you're my pal, right?
You're my buddy?
Awesome.
I'll high five you later.
Laurence has done a number of videos right here
on the Firebase channel on YouTube that describe how
to get phone number authentication up and running
in your app-- web, Android, iOS--
it's all there.
Watch those videos.
Let me know how it goes for you.
Thanks the question, Ahmer.
Take it easy.
Well, that's all the time we have for this episode.
Be sure to keep sending in your questions
with hashtag #AskFirebase.
You might also be interested in my other show called
"#MeetFirebase," where you get to meet the Googlers that make
Firebase happen.
Follow it all right here on the Firebase channel on YouTube,
and I'll see you next time.
Now I'm going to keep playing with this.
[MUSIC PLAYING]