Slide 1

Slide 1 text

Firebase Overview for Native Application Daiki Matsudate (@d_date) GDG DevFest Tokyo 2018

Slide 2

Slide 2 text

Daiki Matsudate @d_date FOLIO Co., Ltd.

Slide 3

Slide 3 text

͜ͷຊͷಋೖతͳ࿩Ͱ͢

Slide 4

Slide 4 text

https://booth.pm/ja/ items/835645

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Agenda • ͱΓ͋͑ͣೖΕ͍ͨFirebase • Prediction·ΘΓͷ࿩ • Firestore·ΘΓͷ࿩

Slide 7

Slide 7 text

લఏ

Slide 8

Slide 8 text

1. iOSΤϯδχΞͰ͢

Slide 9

Slide 9 text

2. Έͳ͞ΜͰͭ͘Δ ηογϣϯͰ͢

Slide 10

Slide 10 text

޿͘ઙ͘࿩͍ͯ͘͠͠ͷͰ ࣭໰ߟ͑ͱ͍͍ͯͩ͘͞

Slide 11

Slide 11 text

ͱΓ͋͑ͣೖΕ͍ͨ Firebase

Slide 12

Slide 12 text

ͱΓ͋͑ͣೖΕ͍ͨFirebase • Crashlytics • Performance Monitoring • Google Analytics for Firebase • App Indexing

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

• ΞϓϦͷΫϥογϡϩάΛऩूɾղੳ͢Δ͓ͳ͡Έͷπʔ ϧ • Fabric ͕ Googleʹങऩ͞Ε͔ͯΒ౷߹͕ਐΊΒΕɺ2017 ೥10݄ʹ౷߹ (Crash Reporting͸deprecated) • Cloud Functionͱ࿈ܞՄೳ

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

- Automatic Trace • ΞϓϦͷύϑΥʔϚϯεΛଌఆ͢Δ • Automatic trace • App start • Network • App in foreground / background • Screen

Slide 17

Slide 17 text

- Screen Trace iOS keyWindow಺ʹ͋ΔUIViewControllerͷ ɾStart: viewDidAppear:͕ݺ͹Εͨͱ͖ ɾStop: viewDidDisappear:͕Α͹Εͨͱ͖ɻ ※Container View ControllerͰ͸Ωϟϓνϟ͠ͳ͍

Slide 18

Slide 18 text

Android ͢΂ͯͷActivityͷ ɾStart: onActivityStarted()͕ݺ͹Εͨͱ͖ ɾStop: onActivityStopped()͕ݺ͹Εͨͱ͖ - Screen Trace

Slide 19

Slide 19 text

https://www.youtube.com/watch?v=e-8fiv-vteQ&t=16

Slide 20

Slide 20 text

https://www.youtube.com/watch?v=e-8fiv-vteQ&t=16

Slide 21

Slide 21 text

NetworkΛτϨʔε͢Δࡍͷ஫ҙ఺ • ඪ४ͷAPIҎ֎ʢ௿ϨϕϧAPI΍Socket௨৴ͳ Ͳʣͷ৔߹͸ࣗಈτϨʔε͞Εͳ͍

Slide 22

Slide 22 text

Appendix: Performance Monitoring - Custom Trace let trace = Performance.startTrace(name: "request_trace") let contents: String do { contents = try String(contentsOfFile: fileName, encoding: .utf8) } catch { print("Log file doesn't exist yet") contents = "" } let fileLength = contents.lengthOfBytes(using: .utf8) trace?.incrementMetric("log_file_size", by: Int64(fileLength))

Slide 23

Slide 23 text

let trace = Performance.startTrace(name: "request_trace") let contents: String do { contents = try String(contentsOfFile: fileName, encoding: .utf8) } catch { print("Log file doesn't exist yet") contents = "" } let fileLength = contents.lengthOfBytes(using: .utf8) trace?.incrementMetric("log_file_size", by: Int64(fileLength)) 1. Call startTrace with 2. Set your metric with Appendix: Performance Monitoring - Custom Trace

Slide 24

Slide 24 text

let target = "https://www.google.com/images/branding/googlelogo/2x/ googlelogo_color_272x92dp.png" guard let targetUrl = URL(string: target) else { return } guard let metric = HTTPMetric(url: targetUrl, httpMethod: .get) else { return } metric.start() var request = URLRequest(url:targetUrl) request.httpMethod = "GET" let task = URLSession.shared.dataTask(with: request) { data, response, error in if let httpResponse = response as? HTTPURLResponse { metric.responseCode = httpResponse.statusCode } metric.stop() ɾSpecified network trace Appendix: Performance Monitoring - Custom Trace

Slide 25

Slide 25 text

let target = "https://www.google.com/images/branding/googlelogo/2x/ googlelogo_color_272x92dp.png" guard let targetUrl = URL(string: target) else { return } guard let metric = HTTPMetric(url: targetUrl, httpMethod: .get) else { return } metric.start() var request = URLRequest(url:targetUrl) request.httpMethod = "GET" let task = URLSession.shared.dataTask(with: request) { data, response, error in if let httpResponse = response as? HTTPURLResponse { metric.responseCode = httpResponse.statusCode } metric.stop() 1. Initialize HTTPMetric 3. Call stop() when finished 2.Call start() ɾSpecified network trace Appendix: Performance Monitoring - Custom Trace

Slide 26

Slide 26 text

Google Analytics for Firebase

Slide 27

Slide 27 text

Google Analytics for Firebase • ϞόΠϧ޲͚Google Analytics • WebͷGoogle Analytics • BigQuery -> Data Studioͱ͍͏ར༻Λ૝ఆ • WebଆͷGAͱ౷߹͢ΔͷʹTag ManagerΛ࢖ͬͨΓ͢Δ

Slide 28

Slide 28 text

App Index

Slide 29

Slide 29 text

App Index • ݕࡧ݁ՌʹΞϓϦΛදࣔ͢Δ • μ΢ϯϩʔυϘλϯ͖ͭ • iOS: Universal LinksΛ༗ޮʹ • Android: AppIndexͷϥΠϒϥϦΛೖΕΔ • apple-app-site-associationΛϗετ͢Δ

Slide 30

Slide 30 text

ͱΓ͋͑ͣೖΕ͍ͨFirebase ·ͣ͸ೖΕͯΈΑ͏ͥʂ

Slide 31

Slide 31 text

Predictionपล

Slide 32

Slide 32 text

Firebase Prediction • 7೔ؒͷσʔλΛݩʹϢʔβʔͷ࣍ͷߦಈΛ༧ଌ ͢Δ • ʮ཭୤ͦ͠͏(churn)ʯʮ཭୤͠ͳͦ͞͏ʯʮ՝ۚ ͦ͠͏(purchase)ʯʮ՝ۚ͠ͳͦ͞͏ʯͷ̐ଐੑ ΛσϑΥϧτͰਪଌͰ͖Δ • AnalyticsͷEventΛݩʹΧελϜ͢Δ͜ͱ΋Ͱ͖Δ

Slide 33

Slide 33 text

Prediction x Remote Config • PredictionͰ༧ଌͨ͠Ϣʔβʔଐੑʹରͯ͠ɺ Remote ConfigΛઃఆͰ͖Δ → ʮ཭୤ͦ͠͏ʯͳϢʔβʔʹରͯ͠ɺΩϟϯϖʔ ϯΛଧͭ

Slide 34

Slide 34 text

A/B Testing • ର৅ͷϢʔβʔଐੑΛࢦఆͯ͠ɺA/BςετͰ͖Δ • ςετର৅ʹ͸PredictionͰ༧ଌͨ͠ଐੑ΋ར༻Մೳ

Slide 35

Slide 35 text

Prediction x Messaging • PredictionͰ༧ଌͨ͠Ϣʔβʔଐੑʹରͯ͠ɺNotification ΛൃՐͰ͖Δ → ʮ཭୤ͦ͠͏ʯͳϢʔβʔʹରͯ͠ɺ௨஌ΛૹΔ

Slide 36

Slide 36 text

In-app messaging

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

Predictionपล • PredictionͰϢʔβʔͷߦಈΛ༧ଌ • ༧ଌͰ͖ͨΒ࿈ܞ͢Δ • A / B Testing • Cloud Messaging • In-App Messaging

Slide 41

Slide 41 text

Firestoreपล

Slide 42

Slide 42 text

Firestoreपล • Firebase Realtime Database • Firebase Firestore • Firebase Cloud Function

Slide 43

Slide 43 text

Firebase Database

Slide 44

Slide 44 text

• NoSQL cloud database • Realtime Data Sync with JSON Tree • Available data on offline Firebase Database

Slide 45

Slide 45 text

Firebase Database

Slide 46

Slide 46 text

NoSQL

Slide 47

Slide 47 text

NoSQL = Denormalization

Slide 48

Slide 48 text

Denormalization in NoSQL { "users": { "user1": { "name": "Alice" }, "user2": { "name": "Bob" } }, "links": { "link1": { "title": "Example", "href": "http://example.org", "submitted": "user1" } }, "comments": { "comment1": { "link": "link1", "body": "This is awesome!", "author": "user2" } } }

Slide 49

Slide 49 text

Denormalization in NoSQL { "users": { "user1": { "name": "Alice" }, "user2": { "name": "Bob" } }, "links": { "link1": { "title": "Example", "href": "http://example.org", "submitted": "user1" } }, "comments": { "comment1": { "link": "link1", "body": "This is awesome!", "author": "user2" } } }

Slide 50

Slide 50 text

Denormalization in NoSQL { "users": { "user1": { "name": "Alice" }, "user2": { "name": "Bob" } }, "links": { "link1": { "title": "Example", "href": "http://example.org", "submitted": "user1" } }, "comments": { "comment1": { "link": "link1", "body": "This is awesome!", "author": "user2" } } } Join data in client

Slide 51

Slide 51 text

• 10:40 - Firestore Database Design / Room I • 13:30 - Realtime Database for High traffic production application / Room J • 14:50 - Realtime Database in Production / Room C + D • Related Session

Slide 52

Slide 52 text

• NoSQL cloud database • Realtime Data Sync with JSON Tree • Available data on offline Firebase Database

Slide 53

Slide 53 text

Cloud Firestore

Slide 54

Slide 54 text

• Stores data in documents organized in collections • Sending data with protobuf, which have more types • Introduced reference type, so requires less denormalization and data flattening • Indexed queries with compound sorting and filtering Cloud Firestore

Slide 55

Slide 55 text

Cloud Firestore

Slide 56

Slide 56 text

Cloud Firestore Reference type

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

Cloud Functions • Firebase΍HTTPϦΫΤετΛτϦΨʔʹͯ͠ɺόοΫΤ ϯυͷίʔυΛ࣮ߦ͢Δ • ίʔυ͸Google ͷCloudʹϓογϡ͢Δ

Slide 59

Slide 59 text

Cloud Functions • Cloud Firestore • Realtime Database • Firebase Authentication • Google Analytics for Firebase • Crashlytics • Cloud Storage • Cloud Pub/Sub • HTTP

Slide 60

Slide 60 text

Ex: Cloud Firestore • υΩϡϝϯτ͕ੜ੒͞Εͨͱ͖ • υΩϡϝϯτ͕ߋ৽͞Εͨͱ͖ • υΩϡϝϯτ͕࡟আ͞Εͨͱ͖ • ্هͷΠϕϯτ͕ൃੜͨ͠ͱ͖

Slide 61

Slide 61 text

Use Case: Firestore x Function • AlgoliaʹΑΔશจݕࡧ • BigQuery • etc…

Slide 62

Slide 62 text

Recap • ͱΓ͋͑ͣೖΕ͓͖͍ͯͨFirebase • Predictionͱͦͷपล • ௨஌ͱͦͷपล • Databaseͱͦͷपล

Slide 63

Slide 63 text

Thank you!

Slide 64

Slide 64 text

Q & A