Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Remote Configを導入して、Notificationsは導入しませんでした

Remote Configを導入して、Notificationsは導入しませんでした

Remote ConfigとNotificationとAnalyticsに関してさくっと話しました。
Otemachi_firebase #1

Ryo Sakaguchi

July 13, 2016
Tweet

More Decks by Ryo Sakaguchi

Other Decks in Technology

Transcript

  1. Agenda • What’s Remote Config • What’s Notifications • Remote

    Config, Pros/Cons • Notifications, Pros/Cons • Analytics with Remote Config
  2. Step1 Firebaseͷґଘؔ܎Λ௥Ճ // Add dependencies to app/build.gradle compile 'com.google.firebase:firebase-core:9.2.0' compile

    ‘com.google.firebase:firebase-config:9.2.0' // Create singleton Remote Config object remoteConfig = FirebaseRemoteConfig.getInstance() val configSettings = FirebaseRemoteConfigSettings.Builder() .setDeveloperModeEnable(BuildConfig.DEBUG).build() remoteConfig.setConfigSettings(configSettings)
  3. Step2 σϑΥϧτ஋Λઃఆ // Create default parameter like this. res/xml/remote_config_default_params.xml <defaultsMap>

    <entry> <key>show_review_dialog</key> <value>false</value> </entry> </defaultsMap> // set default parameters by “setDefaults()” remoteConfig = FirebaseRemoteConfig.getInstance() remoteConfig.setDefaults(R.xml.remote_config_default_params)
  4. Step4 αʔόʔ͔Β஋Λऔಘ // Fetch the parameter from server. override fun

    onPostResume() {
 super.onPostResume() // cacheExpireΛ։ൃ࣌͸0ʹ͢Δͱɺ஋ͷมߋͷ֬ೝΛ͠΍͘͢ͳΓ·͢ɻ val cacheExpire: Long = 3600L
 remoteConfig.fetch(cacheExpire)
 .addOnFailureListener({
 Log.d(TAG, "Failure")
 })
 .addOnSuccessListener ({ // औಘͨ͠ύϥϝʔλʔΛ༗ޮԽ͢Δɻ
 remoteConfig.activateFetched()
 })
 .addOnCompleteListener({
 Log.i(TAG, "Complete")
 })}
  5. Point • ެࣜͷυΩϡϝϯτʹ΋ॻ͍ͯ͋Γ·͕͢ɺdeveloper modeΛ༗ޮԽ͠ͳ͍ ͱɺfetchճ਺ʹ੍ݶ͕ઃఆ͞ΕΔͨΊɺඞͣ༗ޮԽ͠·͠ΐ͏ɻ • ஋ͷfetch͸εϓϥογϡ΍ɺॳճىಈ࣌ʹ·ͱΊͯऔಘ͓͖ͯ͠ɺऔಘՄ൱Λ ࣋ͬͯࠓޙ࠶౓fetch͢Δ͔Ͳ͏͔Λ൑அ͢Ε͹ྑ͍ͱࢥ͍·͢ɻ • ͦͯ͠fetch()͸Αࣦ͘ഊ͠·͢ɻ·ͨɺonCreateͰݺͿͱ͔ͳΓͷ֬཰Ͱࣦ

    ഊɺ·ͨ͸ηοτ͍ͯ͠ΔOnCompleteListener͕ݺ͹Ε·ͤΜͰͨ͠ɻ
 work around ͱͯ͠͸ onPostResumeͰfetchͯ͋͛͠Δ͜ͱͰྑͦ͞͏Ͱ͢ɻ • Ref: http://stackoverflow.com/questions/37501124/firebaseremoteconfig- fetch-does-not-trigger-oncompletelistener-every-time
  6. Versatile message targeting. • Analyticsͱͷ࿈ܞͰ͍ΖΜͳλʔήοτ޲͚ʹϓογϡΛ഑৴Ͱ͖·͢ɻ • ೔ຊޠֶशऀ޲͚ʹ೔ຊจԽʹؔ͢Δ໘നͦ͏ͳ࣭໰Λ഑৴ͨ͠Γ • αϒεΫϦϓγϣϯϓϥϯͷηʔϧΛʮҎલαϒεΫϦϓγϣϯొ࿥Λ ͍͕ͯͨ͠ղ໿ͯ͠͠·ͬͨਓʯʹ͓஌Βͤͨ͠Γ…

    • Console͔ΒखܰʹϓογϡϝοηʔδΛ࡞Δ͜ͱ͕Ͱ͖ΔͷͰɺඇ։ൃ ऀͷΞϧόΠτ͞Μʹ΋͓ئ͍͢Δ͜ͱ͕Ͱ͖Δɻ • Analytics࿈ܞͰͲΜͳϢʔβʔʹ΋഑৴Ͱ͖Δͳ͊ศརͦ͏ͩͳͱࢥͬͯ ಋೖ
  7. Set up(4/6) ࠷ޙʹɺΞϓϦଆ͔ΒϢʔβʔϓϩύςΟΛૹ ৴͠·͢ɻ // ϨϏϡʔର৅Ϣʔβʔͷ࣭໰਺ͷ͖͍͠஋ // ͜͜ͷ஋΋ɺRemoteConfigͰઃఆ͓͚ͯ͠͹ɺϨϏϡʔର৅ʹ͢ΔϢʔβʔͷ࣭ ໰਺Λ͍ͭͰ΋ม͑Δ͜ͱ͕Ͱ͖·͢ɻ val

    threshold = 10 // numberOfQuestions͸ΞϓϦΛ࢖༻͍ͯ͠ΔϢʔβʔͷ࣭໰਺ val reviewTarget = (numberOfQuestions >= threshold).toString() // Firebase AnalyticsʹϢʔβʔϓϩύςΟΛૹ৴ firebaseAnalytics.setUserProperty(“review_target”, reviewTarget)
  8. ͕࣌ؒΞϨ͹࿩͢͜ͱ • Remote Config࢖ͬͯͯؾ͍ͮͨ͜ͱͱ͔ • A/Bςετ͸άϧʔϐϯάͳͲ͕Ͱ͖ͳ͍ͷͰɺҰ࿈ͷྲྀΕͳͲΛςετ͢Δ৔߹͸ͪΐͬͱ೉͕͋Δɻʢνϡʔ τϦΞϧͷҰ࿈ͷςΩετͷςετ౳ʣ • ύοͱࢥ͍͍ͭͨͷ͸ɺRemote Configͷ஋ʹ͸จࣈ਺ͷ੍ݶ͕΄΅΄΅ແ͍ͷͰɺJSONͳΜ͔ΛೖΕ͓͍ͯ

    ͯɺͦΕΛύʔεͯ͠࢖͏Α͏ʹ͢Ε͹ɺॊೈʹมߋ͔ͭάϧʔϐϯά͕Ͱ͖ΔΜ͡Όͳ͍͔ͳͱࢥ͍·ͨ͠ɻ • FirebaseશମΛ௨ͯ͠ࢥͬͨ͜ͱ • Lang-8ͷΑ͏ͳখن໛ͳձࣾ(5ਓن໛)ͱ͔ͩͱɺ͢΂ͯΛࣗࣾ։ൃͰಠࣗʹ΍͍ͬͯΔͱ͍͘Β͕࣌ؒ͋ͬͯ΋ ଍Γͳ͍ͷͰɺ͜͏͍ͬͨϫϯετοϓͰ͍Ζ͍ΖͰ͖Δπʔϧ͸ඇৗʹॿ͔Δͳ͊ͱ͍͏ҹ৅Ͱͨ͠ɻ • ͔͠΋ແྉɻ • ͍Ζ͍Ζফͤͳ͍ɻ • ௥Ճͨ͠ΞϓϦ͕ফͤͳ͍ • ௥Ճͨ͠ϓϩύςΟ΋ফͤͳ͍ • σϑΥϧτͰ༻ҙ͞Ε͍ͯΔ΋ͷ΋ফͤͳ͍ • ͱʹ͔͘ফͤͳ͍