From 561c972c965dd33fbcb821f3fe333a0c30361716 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 4 Aug 2016 00:25:10 -0400 Subject: [PATCH] Instrumented key events in extension --- src/Android/Services/GoogleAnalyticsService.cs | 17 +++++++++++++++-- .../Services/IGoogleAnalyticsService.cs | 4 +++- src/iOS.Core/Services/GoogleAnalyticsService.cs | 14 ++++++++++++-- src/iOS.Extension/LoadingViewController.cs | 4 ++++ .../PasswordGeneratorViewController.cs | 3 +++ src/iOS.Extension/SiteAddViewController.cs | 3 +++ 6 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/Android/Services/GoogleAnalyticsService.cs b/src/Android/Services/GoogleAnalyticsService.cs index a10332b86..b18066ce9 100644 --- a/src/Android/Services/GoogleAnalyticsService.cs +++ b/src/Android/Services/GoogleAnalyticsService.cs @@ -36,12 +36,25 @@ namespace Bit.Android.Services _setUserId = true; } - public void TrackEvent(string category, string eventName) + public void TrackAppEvent(string eventName, string label = null) + { + TrackEvent("App", eventName, label); + } + + public void TrackExtensionEvent(string eventName, string label = null) + { + throw new NotSupportedException(); + } + + public void TrackEvent(string category, string eventName, string label = null) { var builder = new HitBuilders.EventBuilder(); builder.SetCategory(category); builder.SetAction(eventName); - builder.SetLabel("AppEvent"); + if(label != null) + { + builder.SetLabel(label); + } SetUserId(); _tracker.Send(builder.Build()); diff --git a/src/App/Abstractions/Services/IGoogleAnalyticsService.cs b/src/App/Abstractions/Services/IGoogleAnalyticsService.cs index 8ceaacfc3..a66fa5158 100644 --- a/src/App/Abstractions/Services/IGoogleAnalyticsService.cs +++ b/src/App/Abstractions/Services/IGoogleAnalyticsService.cs @@ -4,7 +4,9 @@ { void RefreshUserId(); void TrackPage(string pageName); - void TrackEvent(string category, string eventName); + void TrackAppEvent(string eventName, string label = null); + void TrackExtensionEvent(string eventName, string label = null); + void TrackEvent(string category, string eventName, string label = null); void TrackException(string message, bool fatal); } } diff --git a/src/iOS.Core/Services/GoogleAnalyticsService.cs b/src/iOS.Core/Services/GoogleAnalyticsService.cs index e3ad7fb0f..9faf78fc3 100644 --- a/src/iOS.Core/Services/GoogleAnalyticsService.cs +++ b/src/iOS.Core/Services/GoogleAnalyticsService.cs @@ -28,10 +28,20 @@ namespace Bit.iOS.Core.Services _setUserId = true; } - public void TrackEvent(string category, string eventName) + public void TrackAppEvent(string eventName, string label = null) + { + TrackEvent("App", eventName, label); + } + + public void TrackExtensionEvent(string eventName, string label = null) + { + TrackEvent("Extension", eventName, label); + } + + public void TrackEvent(string category, string eventName, string label = null) { SetUserId(); - var dict = DictionaryBuilder.CreateEvent(category, eventName, "AppEvent", null).Build(); + var dict = DictionaryBuilder.CreateEvent(category, eventName, label, null).Build(); _tracker.Send(dict); Gai.SharedInstance.Dispatch(); } diff --git a/src/iOS.Extension/LoadingViewController.cs b/src/iOS.Extension/LoadingViewController.cs index 20aaccace..f12c45cf9 100644 --- a/src/iOS.Extension/LoadingViewController.cs +++ b/src/iOS.Extension/LoadingViewController.cs @@ -29,6 +29,7 @@ namespace Bit.iOS.Extension private bool _setupHockeyApp = false; private readonly JsonSerializerSettings _jsonSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + private IGoogleAnalyticsService _googleAnalyticsService; public LoadingViewController(IntPtr handle) : base(handle) { } @@ -36,6 +37,7 @@ namespace Bit.iOS.Extension public override void ViewDidLoad() { base.ViewDidLoad(); + _googleAnalyticsService = Resolver.Resolve(); View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f); _context.ExtContext = ExtensionContext; @@ -293,6 +295,8 @@ namespace Bit.iOS.Extension var dict = list as NSDictionary; action(dict); + _googleAnalyticsService.TrackExtensionEvent("ProviderType", type); + Debug.WriteLine("BW LOG, ProviderType: " + _context.ProviderType); Debug.WriteLine("BW LOG, Url: " + _context.Url); Debug.WriteLine("BW LOG, Title: " + _context.SiteTitle); diff --git a/src/iOS.Extension/PasswordGeneratorViewController.cs b/src/iOS.Extension/PasswordGeneratorViewController.cs index 4d5a5f753..300e47469 100644 --- a/src/iOS.Extension/PasswordGeneratorViewController.cs +++ b/src/iOS.Extension/PasswordGeneratorViewController.cs @@ -18,6 +18,7 @@ namespace Bit.iOS.Extension { private IPasswordGenerationService _passwordGenerationService; private ISettings _settings; + private IGoogleAnalyticsService _googleAnalyticsService; public PasswordGeneratorViewController(IntPtr handle) : base(handle) { } @@ -44,6 +45,7 @@ namespace Bit.iOS.Extension { _passwordGenerationService = Resolver.Resolve(); _settings = Resolver.Resolve(); + _googleAnalyticsService = Resolver.Resolve(); View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f); @@ -171,6 +173,7 @@ namespace Bit.iOS.Extension private void GeneratePassword() { + _googleAnalyticsService.TrackExtensionEvent("GeneratePassword"); PasswordLabel.Text = _passwordGenerationService.GeneratePassword( length: LengthCell.Value, uppercase: UppercaseCell.Switch.On, diff --git a/src/iOS.Extension/SiteAddViewController.cs b/src/iOS.Extension/SiteAddViewController.cs index 59c1b6c71..fb77569e5 100644 --- a/src/iOS.Extension/SiteAddViewController.cs +++ b/src/iOS.Extension/SiteAddViewController.cs @@ -23,6 +23,7 @@ namespace Bit.iOS.Extension private IFolderService _folderService; private IConnectivity _connectivity; private IEnumerable _folders; + private IGoogleAnalyticsService _googleAnalyticsService; public SiteAddViewController(IntPtr handle) : base(handle) { } @@ -51,6 +52,7 @@ namespace Bit.iOS.Extension _siteService = Resolver.Resolve(); _connectivity = Resolver.Resolve(); _folderService = Resolver.Resolve(); + _googleAnalyticsService = Resolver.Resolve(); View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f); @@ -164,6 +166,7 @@ namespace Bit.iOS.Extension if(saveTask.Result.Succeeded) { + _googleAnalyticsService.TrackExtensionEvent("SiteCreated"); if(SiteListController != null) { SiteListController.DismissModal();