Backed out changeset 074b8a59783f (bug 1891509) for causing fenix lint failures....
[gecko.git] / mobile / android / docs / mma.rst
blob6d484f63896f3a1c93acf3b20947b8ba1738400b
1 .. -*- Mode: rst; fill-column: 100; -*-
3 ======================================
4  MMA Mobile Marketing Automation
5 ======================================
7 We want to engage with users more. MMA is the project for this purpose. When a user performs a certain
8 UI action, he/she will see a prompt and have a chance to  interact with it. For example, if a user uses
9 Firefox 10 times a week, but Firefox is not his default browser, we'll prompt the user the next time
10 when he launchers our app, and guide him to set us as default browser.
12 Mozilla is using a third party framework called "Leanplum" in order to achieve above goal for
13 Android 56 release. Leanplum is a San Francisco company, founded in 2012. We put their SDK in
14 our codebase and sync upstream when there's a major update. Please find it in ``mobile/android/thirdparty/com/leanplum``.
15 The SDK is documented at https://www.leanplum.com/docs/android/
17 There are three major component in Leanplum SDK.
18 1. Events : Triggers when users perform certain actions. An event will normally trigger a prompt message.
19 2. Deep Links : Actions that users can perform to interact with the prompt message.
20 3. Messages :  Campaigns that we want to engage with users. Messages is a combination of an Event and a Deep Link.
22 Data collection
23 ~~~~~~~~~~~~~~~
25 Who will have Leanplum enabled?
26 ======================================================
28 * We use Switchboard https://wiki.mozilla.org/Firefox/Kinto to filter users to have Leanplum enabled. Currently, for users in the USA
29   and whose locale is set to English, 10% of that users will have Leanplum enabled.
30 * If the user has "Health Report" setting enabled.
31 * If above two are true, when the app starts, and switchboard configure arrived, Firefox for Android will send the
32   triggers and message interaction history to Leanplum server when available.
35 Where does data sent to the Leanplum backend go?
36 ======================================================
38 The Leanplum SDK is hard-coded to send data to the endpoint https://www.leanplum.com.  The endpoint is
39 defined by ``com.leanplum.internal.Constants.API_HOST_NAME`` at
40 https://searchfox.org/mozilla-central/rev/c49a70b53f67dd5550eec8a08793805f2aca8d42/mobile/android/thirdparty/com/leanplum/internal/Constants.java#32.
42 The user is identified by Leanplum using a random UUID generated by Firefox for Android when Leanplum is initialized for the first time.
43 This unique identifier is only used by Leanplum and can't be tracked back to any Firefox users.
46 What data is collected and sent to the Leanplum backend?
47 ==========================================================
49 The Leanplum SDK collects and sends two messages to the Leanplum backend.  The messages have the
50 following parameters::
52   // Sent every time when an event is triggered
53   "action" -> "track"                   // track: an event is tracked.
54   "event" -> "Launch"                   // Used when an event is triggered. e.g. E_Saved_Bookmark.
55   "info" -> ""                          // Used when an event is triggered. Basic context associated with the event.
56   "value" -> 0.0                        // Used when an event is triggered. Value of that event.
57   "messageId" -> 5111602214338560       // Used when an event is triggered. The ID of the message.
59   // Sent when the app starts
60   "action" -> "start"                   // start: Leanplum SDK starts. heartbeat
61   "userAttributes" -> "{                // A set of key-value pairs used to describe the user.
62     "Focus Installed" -> true           // If Focus for Android is installed.
63     "Klar Installed" -> true            // If Klar for Android is installed.
64     "Pocket Installed" -> true          // If Pocket for Android is installed.
65     "Signed In Sync" -> true            // If the user has signed in to Mozilla account.
66     "Default Browser" -> true           // If the user has set Firefox for Android as default browser.
67     "Pocket in Top Sites" -> true       // If Pocket recommendations for Top Sites home panel are enabled (by default or through user action)
68   }
69   "appId" -> "app_6Ao...."              // Leanplum App ID.
70   "clientKey" -> "dev_srwDUNZR...."     // Leanplum client access key.
71   "systemName" -> "Android OS"          // Fixed String in SDK.
72   "locale" -> "zh_TW"                   // System Locale.
73   "timezone" -> "Asia/Taipei"           // System Timezone.
74   "versionName" -> "55.0a1"             // Firefox for Android version.
75   "systemVersion" -> "7.1.2"            // System version.
76   "deviceModel" -> "Google Pixel"       // System device model.
77   "timezoneOffsetSeconds" -> "28800"    // User timezone offset with PST.
78   "deviceName" -> "Google Pixel"        // System device name.
79   "region" -> "(detect)"                // Not used. We strip play-SERVICES-location so this is will be the default stub value in Leanplum SDK.
80   "city" -> "(detect)"                  // Same as above.
81   "country" -> "(detect)"               // Same as above.
82   "location" -> "(detect)"              // Same as above.
83   "newsfeedMessages" -> " size = 0"     // Not used. New Leanplum Inbox message(Leanplum feature) count.
84   "includeDefaults" -> "false"          // Not used. Always false.
86   // Other life cycle actions
87   "action" -> "heartbeat"               // heartbeat: every 15 minutes when app is in the foreground
88                                         // pauseSession: when app goes to background
89                                         // resumeSession: when app goes to foreground
91   // Sent for every action
92   "userId" -> "b13b3c239d01aa7c"        // Set by Firefox for Android, we use random uuid so users are anonymous to Leanplum.
93   "deviceId" -> "b13b3c239d01aa7c"      // Same as above.
94   "sdkVersion" -> "2.2.2-SNAPSHOT"      // Leanplum SDK version.
95   "devMode" -> "true"                   // If the SDK is in developer mode. For official builds, it's false.
96   "time" -> "1.497595093902E9"          // System time in second.
97   "token" -> "nksZ5pa0R5iegC7wj...."    // Token come from Leanplum backend.
100   "gcmRegistrationId" -> "APA91...."    // Send GCM token to Leanplum backend. This happens separately when Leanplum SDK gets initialized.
102 Notes on what data is collected
103 -------------------------------
105 User Identifier:
106 Since Device ID is a random UUID, Leanplum can't map the device to any know Client ID in Firefox for Android nor Advertising ID.
108 Events:
109 Most of the Leanplum events can be mapped to a single combination of Telemetry event (Event+Method+Extra).
110 Some events are not collected in Mozilla Telemetry. This will be addressed separately in each campaign review.
111 There are three elements that are used for each event. They are: event name, value(default: 0.0), and info(default: "").
112 Default value for event value is 0.0. Default value for event info is empty string.
114 List of current Events related data that is sent:
116 * When a page could be reader mode and is visible to the user
118 .. code-block:: json
120     {
121       "event": "E_Reader_Available"
122     }
124 * Download videos or any other media
126 .. code-block:: json
128     {
129       "event" : "E_Download_Media_Saved_Image"
130     }
132 * Save password and login from door hanger
134 .. code-block:: json
136     {
137       "event" : "E_Saved_Login_And_Password"
138     }
140 * Save a bookmark from Firefox for Android menu
142 .. code-block:: json
144     {
145       "event" : "E_Saved_Bookmark"
146     }
148 * Load the bookmark from home panel
150 .. code-block:: json
152     {
153       "event" : "E_Opened_Bookmark"
154     }
156 * Interact with search url area
158 .. code-block:: json
160     {
161       "event" : "E_Interact_With_Search_URL_Area"
162     }
164 * Interact with search widget
166 .. code-block:: json
168     {
169       "event" : "E_Interact_With_Search_Widget"
170     }
172 * When a screenshot is taken
174 .. code-block:: json
176     {
177       "event" : "E_Screenshot"
178     }
180 * Open a new tab
182 .. code-block:: json
184     {
185       "event" : "E_Opened_New_Tab"
186     }
188 * App start but Firefox for Android is not set as default browser
190 .. code-block:: json
192     {
193       "event" : "E_Launch_But_Not_Default_Browser"
194     }
196 * General app start event
198 .. code-block:: json
200     {
201       "event" : "E_Launch_Browser"
202     }
204 * The user just dismissed on-boarding
206 .. code-block:: json
208     {
209       "event" : "E_Dismiss_Onboarding"
210     }
212 * Sign in Firefox Account
214 .. code-block:: json
216     {
217       "event" : "E_User_Signed_In_To_FxA"
218     }
220 * Firefox Sync finished event
222 .. code-block:: json
224     {
225       "event" : "E_User_Finished_Sync"
226     }
228 * The user just resumed the app from background
230 .. code-block:: json
232     {
233       "event" : "E_Resumed_From_Background"
234     }
236 * User set Firefox for Android as default browser and resumed the app
238 .. code-block:: json
240     {
241       "event" : "E_Changed_Default_To_Fennec"
242     }
244 * User installed the Focus app
246 .. code-block:: json
248     {
249       "event" : "E_Just_Installed_Focus"
250     }
252 * User installed the Klar app
254 .. code-block:: json
256     {
257       "event" : "E_Just_Installed_Klar"
258     }
260 * User accessed the promo webpage for the Awesomescreen's Firefox promo banner.
262 .. code-block:: json
264     {
265       "event" : "E_Opened_Firefox_Promo"
266     }
268 * User dismissed the Awesomescreen's Firefox promo banner.
270 .. code-block:: json
272     {
273       "event" : "E_Dismissed_Firefox_Promo"
274     }
276 Deep Links:
277 Deep links are actions that can point Firefox for Android to open certain pages or load features such as `show bookmark list` or
278 `open a SUMO page`. When users see a prompt Leanplum message, they can click the button(s) on it. These buttons can
279 trigger the following deep links:
281 * Link to open pages specifically in Firefox for Android (firefox://open?url=)
282 * Link to Set Default Browser settings (firefox://default_browser)
283 * Link to specific Add-on page (http://link_to_the_add_on_page)
284 * Link to sync signup/sign in (firefox://sign_up)
285 * Link to default search engine settings (firefox://preferences_search)
286 * Link to “Save as PDF” feature (firefox://save_as_pdf)
287 * Take user directly to a Sign up for a newsletter (http://link_to_newsletter_page)
288 * Link to bookmark list (firefox://bookmark_list)
289 * Link to history list (firefox://history_list)
290 * Link to main preferences (firefox://preferences)
291 * Link to privacy preferences (firefox://preferences_privacy)
292 * Link to notifications preferences (firefox://preferences_notifications)
293 * Link to accessibility preferences (firefox://preferences_accessibility)
294 * Link to general setting (firefox://preferences_general)
295 * Link to home page setting (firefox://preferences_home)
297 Messages :
298 Messages are prompts to the user from Leanplum. Messages can be in-app prompts or push notifications. The interaction of that prompt will be kept and sent to Leanplum backend (such
299 as "Accept" and "Show"). A messages is a combination of an Event and a Deep Link. The combinations are downloaded from Leanplum
300 when Leanplum SDK is initialized. When the criteria is met (set in Leanplum backend, could be when an event happens a certain number of times,
301 and/or targeting certain user attribute ), a prompt message will show up. And there may be buttons for users to click. Those clicks
302 may trigger deep links.
304 We use another Mozilla's Google Cloud Messaging(GCM) sender ID to send push notifications.
305 These push notifications will look like the notifications that Sync sends out.
306 Sender ID let GCM knows Mozilla is sending push notifications via Leanplum.
307 GCM will generate a token at client side. We'll send this GCM token to Leanplum so Leanplum knows whom to send push notifications.
308 This token is only useful to Mozilla's sender ID so it's anonymized to other parties.
309 Push Notifications can be triggered by Events, or be sent by Mozilla marketing team manually.
311 The list of current messages for Android can be found here: https://wiki.mozilla.org/Leanplum_Contextual_Hints#Android
313 Technical notes
314 ~~~~~~~~~~~~~~~
316 Build flags controlling the Leanplum SDK integration
317 ======================================================
319 To test this locally, add lines like:
321 export MOZ_ANDROID_MMA=1
322 ac_add_options --with-leanplum-sdk-keyfile=/path/to/leanplum-sdk-developer.token
324 MOZ_ANDROID_MMA depends on MOZ_ANDROID_GOOGLE_PLAY_SERVICES and MOZ_ANDROID_GCM.
325 Since Leanplum requires Google Play Services library, those flags are a proxy for it, and enable respectively.
327 We want to enable MOZ_ANDROID_MMA in Nightly, but only for
328 MOZILLA_OFFICIAL builds.  Since MOZILLA_OFFICIAL is still defined in
329 old-configure.in, we can't integrate it in
330 mobile/android/moz.configure, and therefore we enable using the
331 automation mozconfigs.
333 Technical notes on the Leanplum SDK integration
334 ================================================
336 Just like Adjust, MmaDelegate uses mmaInterface to inject the MmaLeanplumImp and MmaStubImp.
337 Constants used by Leanplum is in MmaConstants. Services in AndroidManifest are in
338 ``mobile/android/base/MmaAndroidManifest_services.xml.in`` which is also injected by build flag
339 MOZ_ANDROID_MMA.
341 Notes and links
342 =================
344 * Leanplum web page: http://leanplum.com/
345 * Leanplum SDK github repo: https://github.com/Leanplum/Leanplum-Android-SDK