mirror of
https://github.com/bitwarden/mobile
synced 2025-12-25 20:53:25 +00:00
Added google analytics service implementation for iOS and android
This commit is contained in:
@@ -35,7 +35,7 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AndroidUseSharedRuntime>True</AndroidUseSharedRuntime>
|
||||
<AndroidLinkMode>Full</AndroidLinkMode>
|
||||
<AndroidLinkMode>None</AndroidLinkMode>
|
||||
<AndroidLinkSkip>Xamarin.GooglePlayServices.Gcm;</AndroidLinkSkip>
|
||||
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
|
||||
<BundleAssemblies>False</BundleAssemblies>
|
||||
@@ -261,6 +261,10 @@
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.0.107\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.GooglePlayServices.Analytics, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xamarin.GooglePlayServices.Analytics.29.0.0.2\lib\MonoAndroid41\Xamarin.GooglePlayServices.Analytics.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.GooglePlayServices.Base, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xamarin.GooglePlayServices.Base.29.0.0.2\lib\MonoAndroid41\Xamarin.GooglePlayServices.Base.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
@@ -297,6 +301,7 @@
|
||||
<Compile Include="Controls\ExtendedEntryRenderer.cs" />
|
||||
<Compile Include="MainApplication.cs" />
|
||||
<Compile Include="Resources\Resource.Designer.cs" />
|
||||
<Compile Include="Services\GoogleAnalyticsService.cs" />
|
||||
<Compile Include="Services\AppInfoService.cs" />
|
||||
<Compile Include="Services\ClipboardService.cs" />
|
||||
<Compile Include="Services\BouncyCastleKeyDerivationService.cs" />
|
||||
|
||||
6186
src/Android/Resources/Resource.Designer.cs
generated
6186
src/Android/Resources/Resource.Designer.cs
generated
File diff suppressed because it is too large
Load Diff
74
src/Android/Services/GoogleAnalyticsService.cs
Normal file
74
src/Android/Services/GoogleAnalyticsService.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using Bit.App.Abstractions;
|
||||
using Android.Gms.Analytics;
|
||||
using Android.Content;
|
||||
|
||||
namespace Bit.Android.Services
|
||||
{
|
||||
public class GoogleAnalyticsService : IGoogleAnalyticsService
|
||||
{
|
||||
private const string UserId = "&uid";
|
||||
|
||||
private readonly IAuthService _authService;
|
||||
private readonly Tracker _tracker;
|
||||
|
||||
public GoogleAnalyticsService(
|
||||
Context appContext,
|
||||
IAppIdService appIdService,
|
||||
IAuthService authService)
|
||||
{
|
||||
_authService = authService;
|
||||
|
||||
var instance = GoogleAnalytics.GetInstance(appContext.ApplicationContext);
|
||||
instance.SetLocalDispatchPeriod(10);
|
||||
|
||||
_tracker = instance.NewTracker("UA-81915606-2");
|
||||
_tracker.EnableExceptionReporting(true);
|
||||
_tracker.EnableAdvertisingIdCollection(true);
|
||||
_tracker.EnableAutoActivityTracking(true);
|
||||
_tracker.SetClientId(appIdService.AppId);
|
||||
}
|
||||
|
||||
public bool SetUserId { get; set; } = true;
|
||||
|
||||
public void TrackEvent(string category, string eventName)
|
||||
{
|
||||
var builder = new HitBuilders.EventBuilder();
|
||||
builder.SetCategory(category);
|
||||
builder.SetAction(eventName);
|
||||
builder.SetLabel("AppEvent");
|
||||
|
||||
if(SetUserId)
|
||||
{
|
||||
_tracker.Set(UserId, _authService.UserId);
|
||||
SetUserId = false;
|
||||
}
|
||||
_tracker.Send(builder.Build());
|
||||
}
|
||||
|
||||
public void TrackException(string message, bool fatal)
|
||||
{
|
||||
var builder = new HitBuilders.ExceptionBuilder();
|
||||
builder.SetDescription(message);
|
||||
builder.SetFatal(fatal);
|
||||
|
||||
if(SetUserId)
|
||||
{
|
||||
_tracker.Set(UserId, _authService.UserId);
|
||||
SetUserId = false;
|
||||
}
|
||||
_tracker.Send(builder.Build());
|
||||
}
|
||||
|
||||
public void TrackPage(string pageName)
|
||||
{
|
||||
if(SetUserId)
|
||||
{
|
||||
_tracker.Set(UserId, _authService.UserId);
|
||||
SetUserId = false;
|
||||
}
|
||||
_tracker.SetScreenName(pageName);
|
||||
_tracker.Send(new HitBuilders.ScreenViewBuilder().Build());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@
|
||||
<package id="Xamarin.Android.Support.v7.RecyclerView" version="23.3.0" targetFramework="monoandroid60" />
|
||||
<package id="Xamarin.Android.Support.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" />
|
||||
<package id="Xamarin.Forms" version="2.3.0.107" targetFramework="monoandroid60" />
|
||||
<package id="Xamarin.GooglePlayServices.Analytics" version="29.0.0.2" targetFramework="monoandroid60" />
|
||||
<package id="Xamarin.GooglePlayServices.Base" version="29.0.0.2" targetFramework="monoandroid60" />
|
||||
<package id="Xamarin.GooglePlayServices.Basement" version="29.0.0.2" targetFramework="monoandroid60" />
|
||||
<package id="Xamarin.GooglePlayServices.Gcm" version="29.0.0.2" targetFramework="monoandroid60" />
|
||||
|
||||
Reference in New Issue
Block a user