feat(DataCollection) Added opt-in data collection
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using Blazor.Analytics;
|
||||
using Blazored.LocalStorage;
|
||||
using Model.Feedback;
|
||||
|
||||
namespace Services.Website;
|
||||
|
||||
public class DataCollectionKeys
|
||||
{
|
||||
// Inputs people are using in the build calculator
|
||||
public static string BuildCalcInput = "buildcalc-input";
|
||||
public static string PageInitialized = "page-initialized";
|
||||
public static string FirstPage = "first-page";
|
||||
}
|
||||
|
||||
public class DataCollectionService : IDataCollectionService, IDisposable
|
||||
{
|
||||
private readonly IStorageService _storageService;
|
||||
|
||||
private bool _isEnabled = false;
|
||||
private readonly IAnalytics _globalTracking;
|
||||
|
||||
public DataCollectionService(IAnalytics globalTracking,
|
||||
IStorageService storageService)
|
||||
{
|
||||
_globalTracking = globalTracking;
|
||||
_storageService = storageService;
|
||||
|
||||
_storageService.Subscribe(Refresh);
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
_storageService.Unsubscribe(Refresh);
|
||||
}
|
||||
|
||||
private void Refresh()
|
||||
{
|
||||
_isEnabled = _storageService.GetValue<bool>(StorageKeys.EnabledDataCollection);
|
||||
}
|
||||
|
||||
public void SendEvent<T>(string eventName, T eventData)
|
||||
{
|
||||
if (_isEnabled)
|
||||
{
|
||||
_globalTracking.TrackEvent(eventName, eventData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using Model.Entity.Data;
|
||||
using Model.Website;
|
||||
|
||||
namespace Services.Website;
|
||||
|
||||
public class DialogContents
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public string Message { get; set; }
|
||||
public string ConfirmButtonLabel { get; set; }
|
||||
public EventCallback<EventArgs> OnConfirm { get; set; }
|
||||
public EventCallback<EventArgs> OnCancel { get; set; }
|
||||
}
|
||||
|
||||
public class DialogService : IDialogService
|
||||
{
|
||||
private DialogContents _dialogContents;
|
||||
|
||||
public DialogService()
|
||||
{
|
||||
}
|
||||
|
||||
public bool IsVisible { get; set; }
|
||||
|
||||
public void Subscribe(Action action)
|
||||
{
|
||||
OnChange += action;
|
||||
}
|
||||
|
||||
public void Unsubscribe(Action action)
|
||||
{
|
||||
OnChange += action;
|
||||
}
|
||||
|
||||
public void Show(DialogContents dialogContents)
|
||||
{
|
||||
_dialogContents = dialogContents;
|
||||
IsVisible = true;
|
||||
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
public DialogContents GetDialogContents()
|
||||
{
|
||||
return _dialogContents;
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
IsVisible = false;
|
||||
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
private event Action OnChange = null!;
|
||||
|
||||
private void NotifyDataChanged()
|
||||
{
|
||||
OnChange();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Services.Website;
|
||||
|
||||
public class PermissionService : IPermissionService
|
||||
public class PermissionService : IPermissionService, IDisposable
|
||||
{
|
||||
private IJSRuntime _jsRuntime;
|
||||
private readonly IStorageService _storageService;
|
||||
@@ -15,6 +15,13 @@ public class PermissionService : IPermissionService
|
||||
_jsRuntime = jsRuntime;
|
||||
_toastService = toastService;
|
||||
_storageService = storageService;
|
||||
|
||||
_storageService.Subscribe(NotifyDataChanged);
|
||||
}
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
_storageService.Unsubscribe(NotifyDataChanged);
|
||||
}
|
||||
|
||||
public void Subscribe(Action action)
|
||||
@@ -47,11 +54,6 @@ public class PermissionService : IPermissionService
|
||||
_storageService.SetValue(StorageKeys.EnabledDataCollection, isEnabled);
|
||||
}
|
||||
|
||||
public Task Load()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private event Action OnChange = null!;
|
||||
|
||||
private void NotifyDataChanged()
|
||||
|
||||
@@ -54,28 +54,12 @@ public class StorageService : IStorageService
|
||||
{
|
||||
_localStorageService.SetItem(key, value);
|
||||
NotifyDataChanged();
|
||||
|
||||
_toastService.AddToast(new ToastModel
|
||||
{
|
||||
Title = "Test 1",
|
||||
SeverityType = SeverityType.Error,
|
||||
Message = "Storage must be enabled before Storage can be used."
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (key.Equals(StorageKeys.EnabledStorage))
|
||||
{
|
||||
_localStorageService.Clear();
|
||||
|
||||
_toastService.AddToast(new ToastModel
|
||||
{
|
||||
Title = "Test 2",
|
||||
SeverityType = SeverityType.Error,
|
||||
Message = "Storage must be enabled before Storage can be used."
|
||||
});
|
||||
|
||||
NotifyDataChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user