diff --git a/src/Android/Services/GoogleAnalyticsService.cs b/src/Android/Services/GoogleAnalyticsService.cs index 35cab0b91..2cb94f97f 100644 --- a/src/Android/Services/GoogleAnalyticsService.cs +++ b/src/Android/Services/GoogleAnalyticsService.cs @@ -28,7 +28,7 @@ namespace Bit.Android.Services _tracker.EnableExceptionReporting(true); _tracker.EnableAdvertisingIdCollection(true); _tracker.EnableAutoActivityTracking(true); - _tracker.SetClientId(appIdService.AppId); + _tracker.SetClientId(appIdService.AnonymousAppId); } public void RefreshUserId() diff --git a/src/App/Abstractions/Services/IAppIdService.cs b/src/App/Abstractions/Services/IAppIdService.cs index 1ea728037..78ca084f0 100644 --- a/src/App/Abstractions/Services/IAppIdService.cs +++ b/src/App/Abstractions/Services/IAppIdService.cs @@ -3,5 +3,6 @@ public interface IAppIdService { string AppId { get; } + string AnonymousAppId { get; } } } diff --git a/src/App/Services/AppIdService.cs b/src/App/Services/AppIdService.cs index 8ae0218eb..d648437db 100644 --- a/src/App/Services/AppIdService.cs +++ b/src/App/Services/AppIdService.cs @@ -6,34 +6,36 @@ namespace Bit.App.Services public class AppIdService : IAppIdService { private const string AppIdKey = "appId"; + private const string AnonymousAppIdKey = "anonymousAppId"; private readonly ISecureStorageService _secureStorageService; private Guid? _appId; + private Guid? _anonymousAppId; public AppIdService(ISecureStorageService secureStorageService) { _secureStorageService = secureStorageService; } - public string AppId + public string AppId => GetAppId(AppIdKey, ref _appId); + public string AnonymousAppId => GetAppId(AnonymousAppIdKey, ref _anonymousAppId); + + private string GetAppId(string key, ref Guid? appId) { - get + if(appId.HasValue) { - if(_appId.HasValue) - { - return _appId.Value.ToString(); - } - - var appIdBytes = _secureStorageService.Retrieve(AppIdKey); - if(appIdBytes != null) - { - _appId = new Guid(appIdBytes); - return _appId.Value.ToString(); - } - - _appId = Guid.NewGuid(); - _secureStorageService.Store(AppIdKey, _appId.Value.ToByteArray()); - return _appId.Value.ToString(); + return appId.Value.ToString(); } + + var appIdBytes = _secureStorageService.Retrieve(key); + if(appIdBytes != null) + { + appId = new Guid(appIdBytes); + return appId.Value.ToString(); + } + + appId = Guid.NewGuid(); + _secureStorageService.Store(key, appId.Value.ToByteArray()); + return appId.Value.ToString(); } } } diff --git a/src/iOS.Core/Services/GoogleAnalyticsService.cs b/src/iOS.Core/Services/GoogleAnalyticsService.cs index c4706299f..d8acf424e 100644 --- a/src/iOS.Core/Services/GoogleAnalyticsService.cs +++ b/src/iOS.Core/Services/GoogleAnalyticsService.cs @@ -20,7 +20,7 @@ namespace Bit.iOS.Core.Services Gai.SharedInstance.TrackUncaughtExceptions = true; _tracker = Gai.SharedInstance.GetTracker("UA-81915606-1"); _tracker.SetAllowIdfaCollection(true); - _tracker.Set(GaiConstants.ClientId, appIdService.AppId); + _tracker.Set(GaiConstants.ClientId, appIdService.AnonymousAppId); } public void RefreshUserId()