Getting Started with Firebase Invites for Android

Getting Started with Firebase Invites for Android

Okay I know I said the Getting Started series has been completely covered and concluded in the Performance Monitoring post.

“And that about sums it up for the ‘Getting Started With’ series. I’m preparing a whole variety of changes here at EricDecanini.com that you should be excited about.”

Of course, it’s me we’re talking about here. I’m DESTINED to forget something. And a pretty important one at that too!

Here in the Firebase ecosystem, we love our marketing and it should come as no question to any of us that word of mouth is the most powerful type of marketing of all. It is however, the hardest one to get going.

In comes Firebase Invites. To put it in a nutshell, you use them to share content in your app which you can send through email, Facebook messenger, or however you set it up.

So how does it work?

When you launch the Invites UI, the user can pick among his contacts to send a referral link (by SMS or Email). This link is a dynamic link, so it will open your app with the referral code if it’s installed, or take the user to Play Store if it isn’t. As you might know with dynamic links, the referral code will be retained after the installation process. You can then use this referral code to say, give your new users the discount they deserve, or the recipe they might want. (Cheeky examples from Firebase themselves).

Getting Started

As with everything, we start with importing our Invites and Dynamic Links dependencies. You will also need to setup Firebase beforehand.

Sending Invites

It’s dead simple. It’s an intent… and that’s pretty much it. An intent with a callback… wait what? A callback?… More on that later.

This intent will launch the pre-defined Firebase Invites UI which handles all the heavy lifting. All you need to do is set a few parameters to keep it personalised like the image and the CAT text.

Method Channels Description
setMessage Email & SMS Sets the default message sent with invitations. This message can be edited by the sender in the invitation dialog. Cannot exceed 100 characters.
setDeepLink Email & SMS Sets the link into your app that is sent with invitations. Specify this to share specific content with the recipient or to otherwise present a custom experience when a user opens your app from an invitation.
setCustomImage Email Sets the URL of a custom image to include in email invitations. The image must be square and around 600×600 pixels. The image can be no larger than 4000×4000 pixels.
setCallToActionText Email Sets the call-to-action text of the button rendered in email invitations. Cannot exceed 32 characters.
setEmailHtmlContent Email Recommended: Sets the content of an email invitation. Set this to send rich HTML email invitations. Your HTML should include the placeholder string %%APPINVITE_LINK_PLACEHOLDER%%, which is replaced with the URL the recipient opens to accept the invitation. When you specify custom email messages, the setDescriptionsetCustomImage, and setCallToActionText methods have no effect.
setEmailSubject Email Required if setEmailHtmlContent is used. Sets the subject line of email invitations.

In fact, here’s the list of parameters you can use to customise your app invite screen.

Callback?

Now why might there be a callback, you might ask?

In all honesty, your invites process would work just fine without handling the callback, however there are a couple things to note:

Your app might want to save the Invitation IDs of the recipients sent to. On top of that, you would want to gracefully handle any errors in case things go wrong or the process was cancelled by the user.

Receiving Invites

You would receive an invite as if it were a dynamic link, but an extra special one. Because Firebase bestowed upon us the wonderful method of FirebaseAppInvite.getInvitation from which we can get the invitation ID. Now we can use this ID to confirm that both the sender and the receiver of the invite can receive some nice bonuses from your app.

Conclusion

To be honest, I really didn’t add much to this. I do go on about how Firebase documentations are a bit of a pain, but with Invites, it’s actually squeaky clean. Even their examples are exemplary. I didn’t think any examples of my own would’ve been much better.

In any case, I think I can say for real that this is the last of the Getting Started With series…. I think.