Maximizing Efficiency and Profitability with OnePlanâs Professional Service A...
Â
Android 103 - Firebase and Architecture Components
1. ANDROID 103 - FIREBASE AND
ARCHITECTURE COMPONENTS
KATE HENDERSON & KAI KOENIG
2. HELLO
HELLO
Iâm Kate!
Iâm an Android Developer, GDG Organiser, Carpenter
Find me on Twitter: @Mistyepd
and Iâm Kai!
Iâm a { Software Engineer | Pilot | GDG Organiser | â¨
Gamer | Dad to 1 cat and 3 chickens | ⌠}
Find me on Twitter: @AgentK
8. WHAT IS FIREBASE?
⸠Mobile and web application development platform
⸠Collection of various integrated services
⸠Analytics
⸠Development (Messaging, Auth, RT Database, Storage, Crash Reporting etc)
⸠Grow/Outreach (NotiďŹcation, App Indexing, Remote ConďŹg, Admob etc)
⸠Some free, others commercial
FIREBASE AND FIREBASE ANALYTICS
9. FIREBASE ANALYTICS
⸠A.k.a. Google Analytics for Firebase
⸠Free analytics and reporting solution
⸠Focus:
⸠General app usage and user demographics
⸠Built-in and custom events
⸠User engagement
FIREBASE AND FIREBASE ANALYTICS
10. ANALYTICS FEATURES (I)
⸠Max. 500 Events
⸠max. 25 parameters per event
⸠1 âvalueâ parameter per event
⸠Up to 25 User Properties
⸠Filters
⸠Integration with other Google/Firebase products
FIREBASE AND FIREBASE ANALYTICS
11. ANALYTICS FEATURES (II)
⸠Dashboard
⸠Audience Segmentation
⸠Conversion/Attribution
⸠Funnels/Cohorts
⸠Streamview (NEW!)
⸠Inferred Data from Google (Play)
FIREBASE AND FIREBASE ANALYTICS
12. MANUAL SETUP
⸠Login to Firebase console, create a Firebase project
⸠Allows to import existing Google projects, e.g. from Google Cloud Messaging
⸠âAdd Firebase to your Android appâ
⸠Specify package name of your app
⸠Rinse and repeat for the debug version of your app
SETUP AND INTEGRATION
18. GOOGLE-SERVICES.JSON (I)
⸠Data ďŹle that contains all the information to hook Firebase into your Android
project:
SETUP AND INTEGRATION
{
"project_info": {
"project_number": "45364632432432",
"firebase_url": "https://something.firebaseio.com",
"project_id": "something",
"storage_bucket": "something.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:45364632432432:android:45362432ae",
"android_client_info": {
"package_name": âcom.this.is.my.package.appâ
}
},
...
19. GOOGLE-SERVICES.JSON (II)
⸠The ďŹle is typically placed in /app
⸠Build ďŹavors:
⸠All in one Firebase project: add more apps to your Firebase setup - 1 ďŹle
⸠Each ďŹavor in its own Firebase project: multiple services ďŹles, usually placed
in the ďŹavorâs root directory
⸠Firebase Analytics is app-scoped, other Firebase services are project-scoped
SETUP AND INTEGRATION
20. APP
STEP FA 1 - ADD LIBRARIES
⸠References to FA libraries in Gradle ďŹles
⸠When app runs - there should be some FA output in logical
21. APP
STEP FA 2 - ADD LIBRARIES
⸠Add new Button to DetailActivity
⸠Wire up onClick event handler in Data Binding
⸠When clicked, we âsimulateâ a purchase (showing a Toast)
22. WHAT ARE ANALYTICS EVENTS?
⸠System/app or user action that can be tracked
⸠Firebase supports a huge range of built-in events (FirebaseAnalytics.Event)
with built-in parameters (FirebaseAnalytics.Param)
⸠Alternatively: track your own custom events
⸠Logged with:â¨
<firebaseInstance>.logEvent(type, bundle)
⸠General: use built-in events whenever possible!
ANALYTICS EVENTS
23. BUILT-IN EVENTS (I)
⸠Automatically collected:
⸠ďŹrst_open, app_update, app_remove etc
⸠PredeďŹned, but not automatically collected:
⸠4 categories of events: general, retail/commerce, lead generation, gaming
⸠There are predeďŹned parameters, too
⸠Some parameters are mandatory, most data is optional though
ANALYTICS EVENTS
24. BUILT-IN EVENTS (II)
⸠Simple example:â¨
â¨
â¨
⸠Create Bundle
⸠Send event type and Bundle object to Firebase
⸠Google recommends to NOT use strings, but the Event/Param constants
ANALYTICS EVENTS
Bundle params = new Bundle();
params.putString("image_name", name);
params.putString("full_text", text);
mFirebaseAnalytics.logEvent("share_image", params);
25. CUSTOM EVENTS
⸠Simple example:â¨
â¨
â¨
⸠Come up with whatever you want as event and parameter names
⸠Modify built-in events by adding more parameters
⸠Can be done very informal, but personally I prefer to have typed payload
objects that I validate and then parse into logEvent() calls
ANALYTICS EVENTS
params.putString(âflight_number", flightNumber);
params.putString("destinationAirport", destAP);
mFirebaseAnalytics.logEvent(âflight_selected", params);
26. EVENT REPORTING
⸠Even if you have NO events you want to track, Firebase Analytics is worthwhile
having for the automatically collected events
⸠On the Firebase Analytics event list, you can set events to be treated as
conversions goals
⸠Some (built-in) events are always treated as conversion
⸠Necessary for funnels and integration with Google Ad Campaigns
ANALYTICS EVENTS
28. APP
STEP FA 3 - ADD CODE FOR PURCHASE EVENT
⸠Track event in onClick handler on DetailViewModel
29. APP
STEP FA 4 - ADD CODE FOR âACHIEVEMENTâ EVENT
⸠When users add new movies we now track an event in FA
30. BEHIND THE SCENES
⸠Firebase SDK in your app logs an event or changes a user property
⸠Data gets saved locally on the device
⸠Google Play services on the device then once per hour post the collected data
to the Firebase backend to save processing power and battery
⸠Android: once per hour for all apps
⸠iOS: once per hour for each each
⸠Conversion events trigger a batch upload instantly
SETUP AND INTEGRATION
31. TESTING AND DEBUGGING YOUR INTEGRATION
⸠Real-time/local via ADB, with a 24hr delay in the FA console or via Streamview:
SETUP AND INTEGRATION
08-02 13:33:15.607 1591-2140/? D/FA: Logging event (FE): sign_up, Bundle[{sign_up_method=unspeciďŹed,
ďŹrebase_event_origin(_o)=app, ďŹrebase_screen_class(_sc)=Main, ďŹrebase_screen_id(_si)=-1488012662865927065}]
08-02 13:33:15.766 1591-2140/? D/FA: Logging event (FE): sign_up_female, Bundle[{sign_up_method=unspeciďŹed,
ďŹrebase_event_origin(_o)=app, ďŹrebase_screen_class(_sc)=Main, ďŹrebase_screen_id(_si)=-1488012662865927065}]
adb shell setprop log.tag.FA VERBOSE
adb shell setprop log.tag.FA-SVC VERBOSE
adb logcat -v time -s FA FA-SVC
36. FUNNELS
FIREBASE ANALYTICS CONSOLE
⸠Chain of events, funnel tracks the retention of users
⸠âHow many of the users who install, sign_up for free and eventually buy a
membership?â
37. USER RETENTION OVER TIME
FIREBASE ANALYTICS CONSOLE
⸠âHow many of the users who installed still use the app after <n> days?â
38. USER RETENTION COHORTS
FIREBASE ANALYTICS CONSOLE
⸠How many of the users who installed still use the app broken down by weeks
41. FIREBASE CRASHLYTICS
PROBLEM
⸠Our app runs on thousands of devices out there
⸠How can we get information on what happens on userâs devices?
⸠Crashes, Exceptions, Errors, Slowness etc
⸠Crashlytics tracks errors and crashes for you
⸠Note: distributing your app in Google Play will also give you bug/crash
statistics - they can have an inďŹuence on your Play store ranking
42. APP
STEP FC 1 - ADD LIBRARIES
⸠Adding the libraries to Gradle
⸠Starts logging fatal errors right away (see in logcat)
43. APP
STEP FC 2 - ADD A BUTTON TO CRASH THE APP
⸠New Button on DetailView
⸠Crashlytics.getInstance().crash() - simulates a proper app crash
44. APP
STEP FC 2 - ADD A BUTTON TO CRASH THE APP
⸠New Button on DetailView
⸠Crashlytics.getInstance().crash() - simulates a proper app crash
45. APP
STEP FC 3 - ADDING AN APPLICATION CLASS AND STARTING CRASHLYTICS
⸠A custom application class allows you access to the application lifecycle
⸠Setup in Manifest, inherit from an Application or AppCompat class
⸠Launching Crashlytics manually to enable debugging
⸠Create an exception (Division by Zero) and deal with it in try/catch
46. APP
STEP FC 4 - CLEANUP
⸠Just cleanup the manually fabricated exception
48. FIREBASE MESSAGING
INTRO
⸠Communicate with a device
⸠Commonly used to send âPush NotiďŹcationsâ
⸠Requires 2 services
⸠Messaging Service
⸠ID Service
⸠Device Token used to push to a particular device
49. APP
STEP FN 1 - LIBRARIES
⸠Adding the libraries to Gradle
50. APP
STEP FN 2 - ID SERVICE
⸠Adding 2 services to Manifest
⸠onTokenRefresh in ID Service
51. APP
STEP FN 3 - MESSAGING SERVICE
⸠Implementation of Messaging service
⸠Difference between immediate handling of message and job scheduling
52. APP
STEP FN 4 - NOTIFICATION
⸠Showing a notiďŹcation on the phone
⸠Icons
54. APP
STEP AC 1 - ENTITIES
⸠Add all the room gradle dependencies
⸠Convert Film to a Entity
⸠Annotations we use
⸠@Entity
⸠@ColumnInfo
⸠@PrimaryKey
55. APP
STEP AC 2 - MAKE ROOM FOR EVERYTHING
⸠Realise I made a mistake in step 1 (annotationProcessor vs kapt)
⸠Create a DataManager to use the same database instance everywhere
⸠Add abstract Database deďŹnition
⸠Add Dao for ďŹlms
⸠More annotations!!!
56. APP
STEP AC 3 - USE DATAMANAGER FOR OFFLINE REMOTE DATA
⸠Use DataManager in the MainActivity to fetch the remote list and update the
database
⸠Observe the LiveData
⸠Still manually combining local and remote lists
57. APP
STEP AC 4 - USE DATAMANAGER FOR LOCAL DATA
⸠Let DataManger save local ďŹlms to the database
⸠Stop manually refreshing the ďŹlms list onActivityResult
⸠Delete LocalData
⸠Notice we arenât migrating existing locally saved ďŹlms
59. APP
WHY VIEWMODEL?
⸠Doesnât recreate everything on rotate
⸠Google supported
⸠Separation of logic and data from the
activity
60. APP
STEP AC 5 - VIEWMODEL (THE GOOGLE VERSION)
⸠Create ViewModel with lazy{ }
⸠Move DataManager calls into ViewModel
⸠Observe the ďŹlm list via the ViewModel
⸠Next Step -> List ordering?
64. RESOURCES
NEXT STEPS
⸠Books:
⸠Kotlin: https://kotlinlang.org/docs/books.html
⸠Android: Soooooo many. Make sure you buy something that is current (at
least for Android 7, better for 8)