Fixes #8 Disable Google Analytics (#55)

* Opt-out of Google Analytics

* Move OptOut to Other in Settings

* Change OptOut Order and Resource key
This commit is contained in:
Shan 2017-03-31 03:52:14 +05:30 committed by Kyle Spearrin
parent a45773e1ca
commit fb35b9b10a
7 changed files with 59 additions and 2 deletions

View file

@ -1,5 +1,7 @@
using System; using System;
using Bit.App;
using Bit.App.Abstractions; using Bit.App.Abstractions;
using Plugin.Settings.Abstractions;
using Android.Gms.Analytics; using Android.Gms.Analytics;
using Android.Content; using Android.Content;
@ -17,7 +19,8 @@ namespace Bit.Android.Services
public GoogleAnalyticsService( public GoogleAnalyticsService(
Context appContext, Context appContext,
IAppIdService appIdService, IAppIdService appIdService,
IAuthService authService) IAuthService authService,
ISettings settings)
{ {
_authService = authService; _authService = authService;
@ -29,6 +32,9 @@ namespace Bit.Android.Services
_tracker.EnableAdvertisingIdCollection(true); _tracker.EnableAdvertisingIdCollection(true);
_tracker.EnableAutoActivityTracking(true); _tracker.EnableAutoActivityTracking(true);
_tracker.SetClientId(appIdService.AnonymousAppId); _tracker.SetClientId(appIdService.AnonymousAppId);
var gaOptOut = settings.GetValueOrDefault(Constants.SettingGAOptOut, false);
SetAppOptOut(gaOptOut);
} }
public void RefreshUserId() public void RefreshUserId()
@ -92,5 +98,10 @@ namespace Bit.Android.Services
_instance.DispatchLocalHits(); _instance.DispatchLocalHits();
completionHandler?.Invoke(); completionHandler?.Invoke();
} }
public void SetAppOptOut(bool optOut)
{
_instance.AppOptOut = optOut;
}
} }
} }

View file

@ -11,5 +11,6 @@ namespace Bit.App.Abstractions
void TrackEvent(string category, string eventName, string label = null); void TrackEvent(string category, string eventName, string label = null);
void TrackException(string message, bool fatal); void TrackException(string message, bool fatal);
void Dispatch(Action completionHandler = null); void Dispatch(Action completionHandler = null);
void SetAppOptOut(bool optOut);
} }
} }

View file

@ -7,6 +7,7 @@
public const string SettingFingerprintUnlockOn = "setting:fingerprintUnlockOn"; public const string SettingFingerprintUnlockOn = "setting:fingerprintUnlockOn";
public const string SettingPinUnlockOn = "setting:pinUnlockOn"; public const string SettingPinUnlockOn = "setting:pinUnlockOn";
public const string SettingLockSeconds = "setting:lockSeconds"; public const string SettingLockSeconds = "setting:lockSeconds";
public const string SettingGAOptOut = "setting:googleAnalyticsOptOut";
public const string PasswordGeneratorLength = "pwGenerator:length"; public const string PasswordGeneratorLength = "pwGenerator:length";
public const string PasswordGeneratorUppercase = "pwGenerator:uppercase"; public const string PasswordGeneratorUppercase = "pwGenerator:uppercase";

View file

@ -40,6 +40,7 @@ namespace Bit.App.Pages
private ExtendedTextCell TwoStepCell { get; set; } private ExtendedTextCell TwoStepCell { get; set; }
private ExtendedTextCell ChangeMasterPasswordCell { get; set; } private ExtendedTextCell ChangeMasterPasswordCell { get; set; }
private ExtendedTextCell ChangeEmailCell { get; set; } private ExtendedTextCell ChangeEmailCell { get; set; }
private ExtendedSwitchCell AnalyticsCell { get; set; }
private ExtendedTextCell FoldersCell { get; set; } private ExtendedTextCell FoldersCell { get; set; }
private ExtendedTextCell SyncCell { get; set; } private ExtendedTextCell SyncCell { get; set; }
private ExtendedTextCell LockCell { get; set; } private ExtendedTextCell LockCell { get; set; }
@ -103,6 +104,12 @@ namespace Bit.App.Pages
ShowDisclousure = true ShowDisclousure = true
}; };
AnalyticsCell = new ExtendedSwitchCell
{
Text = AppResources.DisableGA,
On = _settings.GetValueOrDefault(Constants.SettingGAOptOut, false)
};
FoldersCell = new ExtendedTextCell FoldersCell = new ExtendedTextCell
{ {
Text = AppResources.Folders, Text = AppResources.Folders,
@ -139,6 +146,7 @@ namespace Bit.App.Pages
var otherSection = new TableSection(AppResources.Other) var otherSection = new TableSection(AppResources.Other)
{ {
AnalyticsCell,
AboutCell, AboutCell,
HelpCell HelpCell
}; };
@ -193,6 +201,7 @@ namespace Bit.App.Pages
base.OnAppearing(); base.OnAppearing();
PinCell.OnChanged += PinCell_Changed; PinCell.OnChanged += PinCell_Changed;
AnalyticsCell.OnChanged += AnalyticsCell_Changed;
LockOptionsCell.Tapped += LockOptionsCell_Tapped; LockOptionsCell.Tapped += LockOptionsCell_Tapped;
TwoStepCell.Tapped += TwoStepCell_Tapped; TwoStepCell.Tapped += TwoStepCell_Tapped;
ChangeMasterPasswordCell.Tapped += ChangeMasterPasswordCell_Tapped; ChangeMasterPasswordCell.Tapped += ChangeMasterPasswordCell_Tapped;
@ -226,6 +235,7 @@ namespace Bit.App.Pages
base.OnDisappearing(); base.OnDisappearing();
PinCell.OnChanged -= PinCell_Changed; PinCell.OnChanged -= PinCell_Changed;
AnalyticsCell.OnChanged -= AnalyticsCell_Changed;
LockOptionsCell.Tapped -= LockOptionsCell_Tapped; LockOptionsCell.Tapped -= LockOptionsCell_Tapped;
TwoStepCell.Tapped -= TwoStepCell_Tapped; TwoStepCell.Tapped -= TwoStepCell_Tapped;
ChangeMasterPasswordCell.Tapped -= ChangeMasterPasswordCell_Tapped; ChangeMasterPasswordCell.Tapped -= ChangeMasterPasswordCell_Tapped;
@ -411,6 +421,18 @@ namespace Bit.App.Pages
} }
} }
private void AnalyticsCell_Changed(object sender, ToggledEventArgs e)
{
var cell = sender as ExtendedSwitchCell;
if (cell == null)
{
return;
}
_settings.AddOrUpdateValue(Constants.SettingGAOptOut, cell.On);
_googleAnalyticsService.SetAppOptOut(cell.On);
}
private void PinEntered(SettingsPinPage page) private void PinEntered(SettingsPinPage page)
{ {
page.PinControl.Entry.Unfocus(); page.PinControl.Entry.Unfocus();

View file

@ -520,6 +520,15 @@ namespace Bit.App.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to Disable Google Analytics.
/// </summary>
public static string DisableGA {
get {
return ResourceManager.GetString("DisableGA", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Do you really want to delete? This cannot be undone.. /// Looks up a localized string similar to Do you really want to delete? This cannot be undone..
/// </summary> /// </summary>

View file

@ -302,6 +302,9 @@
<value>Ok</value> <value>Ok</value>
<comment>Acknowledgement.</comment> <comment>Acknowledgement.</comment>
</data> </data>
<data name="DisableGA" xml:space="preserve">
<value>Disable Google Analytics</value>
</data>
<data name="Password" xml:space="preserve"> <data name="Password" xml:space="preserve">
<value>Password</value> <value>Password</value>
<comment>Label for a password.</comment> <comment>Label for a password.</comment>

View file

@ -1,6 +1,7 @@
using System; using System;
using Bit.App.Abstractions; using Bit.App.Abstractions;
using Google.Analytics; using Google.Analytics;
using Plugin.Settings.Abstractions;
namespace Bit.iOS.Core.Services namespace Bit.iOS.Core.Services
{ {
@ -12,7 +13,8 @@ namespace Bit.iOS.Core.Services
public GoogleAnalyticsService( public GoogleAnalyticsService(
IAppIdService appIdService, IAppIdService appIdService,
IAuthService authService) IAuthService authService,
ISettings settings)
{ {
_authService = authService; _authService = authService;
@ -21,6 +23,9 @@ namespace Bit.iOS.Core.Services
_tracker = Gai.SharedInstance.GetTracker("UA-81915606-1"); _tracker = Gai.SharedInstance.GetTracker("UA-81915606-1");
_tracker.SetAllowIdfaCollection(true); _tracker.SetAllowIdfaCollection(true);
_tracker.Set(GaiConstants.ClientId, appIdService.AnonymousAppId); _tracker.Set(GaiConstants.ClientId, appIdService.AnonymousAppId);
var gaOptOut = settings.GetValueOrDefault(App.Constants.SettingGAOptOut, false);
SetAppOptOut(gaOptOut);
} }
public void RefreshUserId() public void RefreshUserId()
@ -78,5 +83,10 @@ namespace Bit.iOS.Core.Services
_setUserId = false; _setUserId = false;
} }
} }
public void SetAppOptOut(bool optOut)
{
Gai.SharedInstance.OptOut = optOut;
}
} }
} }