[fenix] Closes EXP-2986 - Add adjust params to custom attributes for messaging display triggers (https://github.com/mozilla-mobile/fenix/pull/28518)

* Add adjust params to custom attributes for messaging display triggers

* Add isNotificationEnabled to display trigger attributes
pull/600/head
jhugman 2 years ago committed by GitHub
parent 1322a6dbfa
commit 0e795b267b

@ -9,12 +9,12 @@ import mozilla.components.service.nimbus.NimbusApi
import mozilla.components.service.nimbus.NimbusAppInfo
import mozilla.components.service.nimbus.NimbusBuilder
import mozilla.components.support.base.log.logger.Logger
import org.json.JSONObject
import org.mozilla.experiments.nimbus.internal.NimbusException
import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.gleanplumb.CustomAttributeProvider
import org.mozilla.fenix.nimbus.FxNimbus
/**
@ -29,21 +29,14 @@ private const val TIME_OUT_LOADING_EXPERIMENT_FROM_DISK_MS = 200L
* Create the Nimbus singleton object for the Fenix app.
*/
fun createNimbus(context: Context, urlString: String?): NimbusApi {
// These values can be used in the JEXL expressions when targeting experiments.
val customTargetingAttributes = CustomAttributeProvider.getCustomTargetingAttributes(context)
val isAppFirstRun = context.settings().isFirstNimbusRun
if (isAppFirstRun) {
context.settings().isFirstNimbusRun = false
}
// These values can be used in the JEXL expressions when targeting experiments.
val customTargetingAttributes = JSONObject().apply {
// By convention, we should use snake case.
put("is_first_run", isAppFirstRun)
// This camelCase attribute is a boolean value represented as a string.
// This is left for backwards compatibility.
put("isFirstRun", isAppFirstRun.toString())
}
// The name "fenix" here corresponds to the app_name defined for the family of apps
// that encompasses all of the channels for the Fenix app. This is defined upstream in
// the telemetry system. For more context on where the app_name come from see:

@ -5,7 +5,9 @@
package org.mozilla.fenix.gleanplumb
import android.content.Context
import androidx.core.app.NotificationManagerCompat
import org.json.JSONObject
import org.mozilla.fenix.ext.areNotificationsEnabledSafe
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.utils.BrowsersCache
import java.text.SimpleDateFormat
@ -19,17 +21,48 @@ import java.util.Locale
object CustomAttributeProvider {
private val formatter = SimpleDateFormat("yyyy-MM-dd", Locale.US)
/**
* Return a [JSONObject] of custom attributes used for experiment targeting.
*
* These are only evaluated right at the beginning of start up, so any first run experiments needing
* targeting attributes which aren't set until after startup e.g. are_notifications_enabled
* will unlikely to targeted as expected.
*/
fun getCustomTargetingAttributes(context: Context): JSONObject {
val isFirstRun = context.settings().isFirstNimbusRun
return JSONObject(
mapOf(
// By convention, we should use snake case.
"is_first_run" to isFirstRun,
// This camelCase attribute is a boolean value represented as a string.
// This is left for backwards compatibility.
"isFirstRun" to isFirstRun.toString(),
),
)
}
/**
* Returns a [JSONObject] that contains all the custom attributes, evaluated when the function
* was called.
*
* This is used to drive display triggers of messages.
*/
fun getCustomAttributes(context: Context): JSONObject {
val now = Calendar.getInstance()
val settings = context.settings()
return JSONObject(
mapOf(
"is_default_browser_string" to BrowsersCache.all(context).isDefaultBrowser.toString(),
"is_default_browser" to BrowsersCache.all(context).isDefaultBrowser,
"date_string" to formatter.format(now.time),
"number_of_app_launches" to context.settings().numberOfAppLaunches,
"number_of_app_launches" to settings.numberOfAppLaunches,
"adjust_campaign" to settings.adjustCampaignId,
"adjust_network" to settings.adjustNetwork,
"adjust_ad_group" to settings.adjustAdGroup,
"adjust_creative" to settings.adjustCreative,
"are_notifications_enabled" to NotificationManagerCompat.from(context).areNotificationsEnabledSafe(),
),
)
}

@ -130,8 +130,8 @@ features:
DEVICE_IOS: os == 'iOS'
ALWAYS: "true"
NEVER: "false"
I_AM_DEFAULT_BROWSER: "is_default_browser_string == 'true'"
I_AM_NOT_DEFAULT_BROWSER: "is_default_browser_string == 'false'"
I_AM_DEFAULT_BROWSER: "is_default_browser"
I_AM_NOT_DEFAULT_BROWSER: "is_default_browser == false"
USER_ESTABLISHED_INSTALL: "number_of_app_launches >=4"
actions:
ENABLE_PRIVATE_BROWSING: ://enable_private_browsing

Loading…
Cancel
Save