Commit 9fae08da authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Add Getters and Setters for user default browser promo interaction

Adds LogUserInteractionWithFullscreenPromo and
HasUserInteractedWithFullscreenPromoBefore to be able to set and
get the NSUserDefault config to keep track of user interaction
history with the fullscreen default browser promo. Adds calls to
LogUserInteractionWithFullscreenPromo.

Bug: 1107489
Change-Id: I5d73e6e93d8dd20682e65dfe9eb68ef10ca63632
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2363660
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Auto-Submit: Chris Lu <thegreenfrog@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800749}
parent ba251398
...@@ -22,6 +22,7 @@ source_set("whats_new") { ...@@ -22,6 +22,7 @@ source_set("whats_new") {
] ]
deps = [ deps = [
":utils",
"//base", "//base",
"//ios/chrome/app/strings:ios_google_chrome_strings", "//ios/chrome/app/strings:ios_google_chrome_strings",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators", "//ios/chrome/browser/ui/coordinators:chrome_coordinators",
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h" #include "base/metrics/user_metrics_action.h"
#import "ios/chrome/browser/ui/whats_new/default_browser_promo_view_controller.h" #import "ios/chrome/browser/ui/whats_new/default_browser_promo_view_controller.h"
#import "ios/chrome/browser/ui/whats_new/default_browser_utils.h"
#import "ios/chrome/common/ui/confirmation_alert/confirmation_alert_action_handler.h" #import "ios/chrome/common/ui/confirmation_alert/confirmation_alert_action_handler.h"
#import "ios/chrome/common/ui/elements/popover_label_view_controller.h" #import "ios/chrome/common/ui/elements/popover_label_view_controller.h"
#include "ios/chrome/grit/ios_google_chrome_strings.h" #include "ios/chrome/grit/ios_google_chrome_strings.h"
...@@ -67,11 +68,13 @@ enum IOSDefaultBrowserFullscreenPromoAction { ...@@ -67,11 +68,13 @@ enum IOSDefaultBrowserFullscreenPromoAction {
- (void)confirmationAlertDismissAction { - (void)confirmationAlertDismissAction {
UMA_HISTOGRAM_ENUMERATION("IOS.DefaultBrowserFullscreenPromo", CANCEL); UMA_HISTOGRAM_ENUMERATION("IOS.DefaultBrowserFullscreenPromo", CANCEL);
LogUserInteractionWithFullscreenPromo();
[self.handler hidePromo]; [self.handler hidePromo];
} }
- (void)confirmationAlertPrimaryAction { - (void)confirmationAlertPrimaryAction {
UMA_HISTOGRAM_ENUMERATION("IOS.DefaultBrowserFullscreenPromo", ACTION_BUTTON); UMA_HISTOGRAM_ENUMERATION("IOS.DefaultBrowserFullscreenPromo", ACTION_BUTTON);
LogUserInteractionWithFullscreenPromo();
[[UIApplication sharedApplication] [[UIApplication sharedApplication]
openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]
options:{} options:{}
......
...@@ -17,8 +17,20 @@ extern NSString* const kLastHTTPURLOpenTime; ...@@ -17,8 +17,20 @@ extern NSString* const kLastHTTPURLOpenTime;
// past expired logs that have happened too far in the past. // past expired logs that have happened too far in the past.
void LogLikelyInterestedDefaultBrowserUserActivity(); void LogLikelyInterestedDefaultBrowserUserActivity();
// Returns True if the last URL open is within the time threshold that would // Returns true if the user has interacted with the Fullscreen Promo previously.
// indicate Chrome is likely still the default browser. Returns False otherwise. // Returns false otherwise.
bool HasUserInteractedWithFullscreenPromoBefore();
// Logs that the user has interacted with the Fullscreen Promo.
void LogUserInteractionWithFullscreenPromo();
// Returns true if the last URL open is within the time threshold that would
// indicate Chrome is likely still the default browser. Returns false otherwise.
bool IsChromeLikelyDefaultBrowser(); bool IsChromeLikelyDefaultBrowser();
// Returns true if the past behavior of the user indicates that the user fits
// the categorization that would likely benefit from having Chrome set as their
// default browser. Returns false otherwise.
bool IsLikelyInterestedDefaultBrowserUser();
#endif // IOS_CHROME_BROWSER_UI_WHATS_NEW_DEFAULT_BROWSER_UTILS_H_ #endif // IOS_CHROME_BROWSER_UI_WHATS_NEW_DEFAULT_BROWSER_UTILS_H_
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
namespace { namespace {
NSString* const kLastSignificantUserEvent = @"lastSignificantUserEvent"; NSString* const kLastSignificantUserEvent = @"lastSignificantUserEvent";
NSString* const kUserHasInteractedWithFullscreenPromo =
@"userHasInteractedWithFullscreenPromo";
// Time threshold before activity timestamps should be removed. Currently set to // Time threshold before activity timestamps should be removed. Currently set to
// seven days. // seven days.
const NSTimeInterval kUserActivityTimestampExpiration = 7 * 24 * 60 * 60; const NSTimeInterval kUserActivityTimestampExpiration = 7 * 24 * 60 * 60;
...@@ -23,22 +26,27 @@ const NSTimeInterval kLatestURLOpenForDefaultBrowser = 7 * 24 * 60 * 60; ...@@ -23,22 +26,27 @@ const NSTimeInterval kLatestURLOpenForDefaultBrowser = 7 * 24 * 60 * 60;
NSString* const kLastHTTPURLOpenTime = @"lastHTTPURLOpenTime"; NSString* const kLastHTTPURLOpenTime = @"lastHTTPURLOpenTime";
// Helper function to clear all timestamps that occur later than 7 days ago.
NSMutableArray<NSDate*>* SanitizePastUserEvents(
NSMutableArray<NSDate*>* pastUserEvents) {
NSDate* sevenDaysAgoDate =
[NSDate dateWithTimeIntervalSinceNow:-kUserActivityTimestampExpiration];
NSUInteger firstUnexpiredIndex = [pastUserEvents
indexOfObjectPassingTest:^BOOL(NSDate* date, NSUInteger idx, BOOL* stop) {
return ([date laterDate:sevenDaysAgoDate] == date);
}];
if (firstUnexpiredIndex != NSNotFound && firstUnexpiredIndex > 0) {
[pastUserEvents removeObjectsInRange:NSMakeRange(0, firstUnexpiredIndex)];
}
return pastUserEvents;
}
void LogLikelyInterestedDefaultBrowserUserActivity() { void LogLikelyInterestedDefaultBrowserUserActivity() {
NSMutableArray<NSDate*>* pastUserEvents = NSMutableArray<NSDate*>* pastUserEvents =
[[[NSUserDefaults standardUserDefaults] [[[NSUserDefaults standardUserDefaults]
arrayForKey:kLastSignificantUserEvent] mutableCopy]; arrayForKey:kLastSignificantUserEvent] mutableCopy];
if (pastUserEvents) { if (pastUserEvents) {
NSDate* sevenDaysAgoDate = pastUserEvents = SanitizePastUserEvents(pastUserEvents);
[NSDate dateWithTimeIntervalSinceNow:-kUserActivityTimestampExpiration];
// Clear all timestamps that occur later than 7 days ago.
NSUInteger firstUnexpiredIndex =
[pastUserEvents indexOfObjectPassingTest:^BOOL(
NSDate* date, NSUInteger idx, BOOL* stop) {
return ([date laterDate:sevenDaysAgoDate] == date);
}];
if (firstUnexpiredIndex != NSNotFound && firstUnexpiredIndex > 0) {
[pastUserEvents removeObjectsInRange:NSMakeRange(0, firstUnexpiredIndex)];
}
[pastUserEvents addObject:[NSDate date]]; [pastUserEvents addObject:[NSDate date]];
} else { } else {
pastUserEvents = [NSMutableArray arrayWithObject:[NSDate date]]; pastUserEvents = [NSMutableArray arrayWithObject:[NSDate date]];
...@@ -48,6 +56,17 @@ void LogLikelyInterestedDefaultBrowserUserActivity() { ...@@ -48,6 +56,17 @@ void LogLikelyInterestedDefaultBrowserUserActivity() {
forKey:kLastSignificantUserEvent]; forKey:kLastSignificantUserEvent];
} }
bool HasUserInteractedWithFullscreenPromoBefore() {
return [[NSUserDefaults standardUserDefaults]
boolForKey:kUserHasInteractedWithFullscreenPromo];
}
void LogUserInteractionWithFullscreenPromo() {
[[NSUserDefaults standardUserDefaults]
setBool:YES
forKey:kUserHasInteractedWithFullscreenPromo];
}
bool IsChromeLikelyDefaultBrowser() { bool IsChromeLikelyDefaultBrowser() {
NSDate* lastURLOpen = NSDate* lastURLOpen =
[[NSUserDefaults standardUserDefaults] objectForKey:kLastHTTPURLOpenTime]; [[NSUserDefaults standardUserDefaults] objectForKey:kLastHTTPURLOpenTime];
...@@ -62,3 +81,11 @@ bool IsChromeLikelyDefaultBrowser() { ...@@ -62,3 +81,11 @@ bool IsChromeLikelyDefaultBrowser() {
} }
return true; return true;
} }
bool IsLikelyInterestedDefaultBrowserUser() {
NSMutableArray<NSDate*>* pastUserEvents =
[[[NSUserDefaults standardUserDefaults]
arrayForKey:kLastSignificantUserEvent] mutableCopy];
pastUserEvents = SanitizePastUserEvents(pastUserEvents);
return [pastUserEvents count] > 1;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment