Skip to content

Commit

Permalink
Adds targeting for days_since_install and days_since_update
Browse files Browse the repository at this point in the history
  • Loading branch information
tarikeshaq committed Sep 30, 2021
1 parent b38af5c commit 20042b6
Show file tree
Hide file tree
Showing 14 changed files with 858 additions and 80 deletions.
3 changes: 2 additions & 1 deletion CHANGES_UNRELEASED.md
Expand Up @@ -22,4 +22,5 @@ Use the template below to make assigning a version number during the release cut

### What's new

- Nimbus can now target on `is_already_enrolled`. Which is true only if the user is already enrolled in experiment. ([#4490](https://github.com/mozilla/application-services/pull/4490))
- Nimbus can now target on `is_already_enrolled`. Which is true only if the user is already enrolled in experiment. ([#4490](https://github.com/mozilla/application-services/pull/4490))
- Nimbus can now target on `days_since_install` and `days_since_update`. Which reflect the days since the user installed the application and the days since the user last updated the application. ([#4491](https://github.com/mozilla/application-services/pull/4491))
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions components/nimbus/Cargo.toml
Expand Up @@ -34,6 +34,7 @@ sha2 = "0.9"
hex = "0.4"
once_cell = "1"
uniffi = { version = "^0.14", optional = true }
chrono = { version = "0.4", features = ["serde"]}

[build-dependencies]
uniffi_build = { version = "^0.14", features = [ "builtin-bindgen" ], optional = true }
Expand Down
Expand Up @@ -618,6 +618,7 @@ open class Nimbus(
locale = deviceInfo.localeTag,
os = "Android",
osVersion = Build.VERSION.RELEASE,
installationDate = packageInfo?.firstInstallTime,
customTargetingAttributes = appInfo.customTargetingAttributes)
}
}
1 change: 1 addition & 0 deletions components/nimbus/ios/Nimbus/NimbusCreate.swift
Expand Up @@ -81,6 +81,7 @@ public extension Nimbus {
osVersion: device.systemVersion,
androidSdkVersion: nil,
debugTag: "Nimbus.rs",
installationDate: nil,
customTargetingAttributes: appSettings.customTargetingAttributes
)
}
Expand Down
157 changes: 96 additions & 61 deletions components/nimbus/src/enrollment.rs

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions components/nimbus/src/evaluator.rs
Expand Up @@ -30,6 +30,8 @@ pub struct TargetingAttributes {
#[serde(flatten)]
pub app_context: AppContext,
pub is_already_enrolled: bool,
pub days_since_install: Option<i32>,
pub days_since_update: Option<i32>,
}

/// Determine the enrolment status for an experiment.
Expand Down Expand Up @@ -238,14 +240,6 @@ mod tests {
use super::*;
use crate::{BucketConfig, Experiment, RandomizationUnit};

impl From<AppContext> for TargetingAttributes {
fn from(app_context: AppContext) -> Self {
Self {
app_context,
..Default::default()
}
}
}
#[test]
fn test_targeting() {
// Here's our valid jexl statement
Expand All @@ -268,6 +262,7 @@ mod tests {
android_sdk_version: Some("29".to_string()),
debug_tag: None,
custom_targeting_attributes: None,
..Default::default()
}
.into();
assert_eq!(targeting(expression_statement, &targeting_attributes), None);
Expand All @@ -288,6 +283,7 @@ mod tests {
android_sdk_version: Some("29".to_string()),
debug_tag: None,
custom_targeting_attributes: None,
..Default::default()
}
.into();
assert_eq!(targeting(expression_statement, &targeting_attributes), None);
Expand All @@ -308,6 +304,7 @@ mod tests {
android_sdk_version: Some("29".to_string()),
debug_tag: None,
custom_targeting_attributes: None,
..Default::default()
}
.into();
assert!(matches!(
Expand All @@ -333,6 +330,7 @@ mod tests {
android_sdk_version: Some("29".to_string()),
debug_tag: None,
custom_targeting_attributes: None,
..Default::default()
}
.into();
assert!(matches!(
Expand Down Expand Up @@ -369,6 +367,7 @@ mod tests {
android_sdk_version: Some("29".to_string()),
debug_tag: None,
custom_targeting_attributes: Some(custom_targeting_attributes),
..Default::default()
}
.into();
assert_eq!(targeting(expression_statement, &targeting_attributes), None);
Expand All @@ -389,6 +388,7 @@ mod tests {
android_sdk_version: Some("29".to_string()),
debug_tag: None,
custom_targeting_attributes: None,
..Default::default()
}
.into();
assert!(matches!(
Expand Down Expand Up @@ -417,6 +417,7 @@ mod tests {
android_sdk_version: Some("29".to_string()),
debug_tag: None,
custom_targeting_attributes: None,
..Default::default()
}
.into();
targeting_attributes.is_already_enrolled = true;
Expand Down

0 comments on commit 20042b6

Please sign in to comment.