Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Unified Diff: ios/chrome/browser/desktop_promotion/desktop_promotion_sync_observer.mm

Issue 2643723004: Add Desktop iOS promotion logging to chrome ios app. (Closed)
Patch Set: add histogram Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/desktop_promotion/desktop_promotion_sync_observer.mm
diff --git a/ios/chrome/browser/desktop_promotion/desktop_promotion_sync_observer.mm b/ios/chrome/browser/desktop_promotion/desktop_promotion_sync_observer.mm
new file mode 100644
index 0000000000000000000000000000000000000000..434b5c44b7ef9968e12634bd0c8d340e15350fbb
--- /dev/null
+++ b/ios/chrome/browser/desktop_promotion/desktop_promotion_sync_observer.mm
@@ -0,0 +1,83 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/desktop_promotion/desktop_promotion_sync_observer.h"
+
+#include <memory>
+
+#include "base/metrics/histogram.h"
+#include "base/strings/stringprintf.h"
+#include "base/time/time.h"
+#include "components/browser_sync/profile_sync_service.h"
+#include "components/prefs/pref_service.h"
+#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
+#include "ios/chrome/browser/desktop_promotion/desktop_promotion_prefs.h"
+#include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h"
+
+namespace {
+
+// Needed by UMA_HISTOGRAM_ENUM as the max value that shouldn't be exceeded.
+const int kMaxEntryPoints = 5;
+const char* kDesktopIOSPromotionEntrypointHistogramPrefix[] = {
+ "SavePasswordsNewBubble", "BookmarksNewBubble", "BookmarksExistingBubble",
+ "HistoryPage"};
+const char kSMSSentIOSSigninReasonHistogram[] =
+ "DesktopIOSPromotion.SMSSent.IOSSigninReason";
+const char kNoSMSIOSSigninReasonHistogram[] =
+ "DesktopIOSPromotion.NoSMS.IOSSigninReason";
+}
+
+DesktopPromotionSyncObserver::DesktopPromotionSyncObserver(
+ ios::ChromeBrowserState* browser_state)
+ : browser_state_(browser_state) {
+ browser_sync::ProfileSyncService* sync_service =
+ IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_);
+ sync_service->AddObserver(this);
+}
+
+DesktopPromotionSyncObserver::~DesktopPromotionSyncObserver() {
+ browser_sync::ProfileSyncService* sync_service =
+ IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_);
+ sync_service->RemoveObserver(this);
+}
+
+void DesktopPromotionSyncObserver::OnStateChanged() {
+ browser_sync::ProfileSyncService* sync_service =
+ IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_);
+ if (!desktop_metrics_logger_initiated_ &&
+ sync_service->GetActiveDataTypes().Has(syncer::PRIORITY_PREFERENCES)) {
+ desktop_metrics_logger_initiated_ = true;
+ PrefService* prefs = browser_state_->GetPrefs();
+ bool done_logging = prefs->GetBoolean(prefs::kDesktopIOSPromotionDone);
+ double last_impression =
+ prefs->GetDouble(prefs::kDesktopIOSPromotionLastImpression);
+ base::TimeDelta delta =
+ base::Time::Now() - base::Time::FromDoubleT(last_impression);
+ if (!done_logging && delta.InDays() < 7) {
+ // This user have seen the promotion in the last 7 days so it may be a
+ // reason of the installation.
+ int sms_entrypoint =
+ prefs->GetInteger(prefs::kDesktopIOSPromotionSMSEntryPoint);
+ int targeted_entrypoints =
+ prefs->GetInteger(prefs::kDesktopIOSPromotionTargetedEntryPoints);
+ // Entry points are represented on the preference by integers [1..4].
+ for (int i = 1; i < kMaxEntryPoints; i++) {
+ if (sms_entrypoint == i) {
+ UMA_HISTOGRAM_ENUMERATION(kSMSSentIOSSigninReasonHistogram, i,
+ kMaxEntryPoints);
+ UMA_HISTOGRAM_COUNTS(
+ base::StringPrintf(
+ "DesktopIOSPromotion.%s.CompletionTime",
+ kDesktopIOSPromotionEntrypointHistogramPrefix[i - 1]),
+ delta.InHours());
+ } else {
+ if ((1 << i) & targeted_entrypoints)
+ UMA_HISTOGRAM_ENUMERATION(kNoSMSIOSSigninReasonHistogram, i,
+ kMaxEntryPoints);
+ }
+ }
+ prefs->SetBoolean(prefs::kDesktopIOSPromotionDone, true);
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698