mirror of
https://github.com/bitwarden/android.git
synced 2024-12-24 18:08:26 +03:00
Added google analytics service implementation for iOS and android
This commit is contained in:
parent
b5dfe2d336
commit
41deae60f5
9 changed files with 3431 additions and 2926 deletions
|
@ -35,7 +35,7 @@
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<AndroidUseSharedRuntime>True</AndroidUseSharedRuntime>
|
<AndroidUseSharedRuntime>True</AndroidUseSharedRuntime>
|
||||||
<AndroidLinkMode>Full</AndroidLinkMode>
|
<AndroidLinkMode>None</AndroidLinkMode>
|
||||||
<AndroidLinkSkip>Xamarin.GooglePlayServices.Gcm;</AndroidLinkSkip>
|
<AndroidLinkSkip>Xamarin.GooglePlayServices.Gcm;</AndroidLinkSkip>
|
||||||
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
|
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
|
||||||
<BundleAssemblies>False</BundleAssemblies>
|
<BundleAssemblies>False</BundleAssemblies>
|
||||||
|
@ -261,6 +261,10 @@
|
||||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.0.107\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll</HintPath>
|
<HintPath>..\..\packages\Xamarin.Forms.2.3.0.107\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</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">
|
<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>
|
<HintPath>..\..\packages\Xamarin.GooglePlayServices.Base.29.0.0.2\lib\MonoAndroid41\Xamarin.GooglePlayServices.Base.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
|
@ -297,6 +301,7 @@
|
||||||
<Compile Include="Controls\ExtendedEntryRenderer.cs" />
|
<Compile Include="Controls\ExtendedEntryRenderer.cs" />
|
||||||
<Compile Include="MainApplication.cs" />
|
<Compile Include="MainApplication.cs" />
|
||||||
<Compile Include="Resources\Resource.Designer.cs" />
|
<Compile Include="Resources\Resource.Designer.cs" />
|
||||||
|
<Compile Include="Services\GoogleAnalyticsService.cs" />
|
||||||
<Compile Include="Services\AppInfoService.cs" />
|
<Compile Include="Services\AppInfoService.cs" />
|
||||||
<Compile Include="Services\ClipboardService.cs" />
|
<Compile Include="Services\ClipboardService.cs" />
|
||||||
<Compile Include="Services\BouncyCastleKeyDerivationService.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.v7.RecyclerView" version="23.3.0" targetFramework="monoandroid60" />
|
||||||
<package id="Xamarin.Android.Support.Vector.Drawable" 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.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.Base" version="29.0.0.2" targetFramework="monoandroid60" />
|
||||||
<package id="Xamarin.GooglePlayServices.Basement" 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" />
|
<package id="Xamarin.GooglePlayServices.Gcm" version="29.0.0.2" targetFramework="monoandroid60" />
|
||||||
|
|
9
src/App/Abstractions/Services/IGoogleAnalyticsService.cs
Normal file
9
src/App/Abstractions/Services/IGoogleAnalyticsService.cs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
namespace Bit.App.Abstractions
|
||||||
|
{
|
||||||
|
public interface IGoogleAnalyticsService
|
||||||
|
{
|
||||||
|
void TrackPage(string pageName);
|
||||||
|
void TrackEvent(string category, string eventName);
|
||||||
|
void TrackException(string message, bool fatal);
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,6 +37,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Abstractions\Repositories\IAccountsApiRepository.cs" />
|
<Compile Include="Abstractions\Repositories\IAccountsApiRepository.cs" />
|
||||||
<Compile Include="Abstractions\Repositories\IDeviceApiRepository.cs" />
|
<Compile Include="Abstractions\Repositories\IDeviceApiRepository.cs" />
|
||||||
|
<Compile Include="Abstractions\Services\IGoogleAnalyticsService.cs" />
|
||||||
<Compile Include="Abstractions\Services\IAppInfoService.cs" />
|
<Compile Include="Abstractions\Services\IAppInfoService.cs" />
|
||||||
<Compile Include="Abstractions\Services\IAppIdService.cs" />
|
<Compile Include="Abstractions\Services\IAppIdService.cs" />
|
||||||
<Compile Include="Abstractions\Services\IAuthService.cs" />
|
<Compile Include="Abstractions\Services\IAuthService.cs" />
|
||||||
|
|
61
src/iOS.Core/Services/GoogleAnalyticsService.cs
Normal file
61
src/iOS.Core/Services/GoogleAnalyticsService.cs
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
using System;
|
||||||
|
using Bit.App.Abstractions;
|
||||||
|
using Google.Analytics;
|
||||||
|
|
||||||
|
namespace Bit.iOS.Core.Services
|
||||||
|
{
|
||||||
|
public class GoogleAnalyticsService : IGoogleAnalyticsService
|
||||||
|
{
|
||||||
|
private readonly ITracker _tracker;
|
||||||
|
private readonly IAuthService _authService;
|
||||||
|
|
||||||
|
public GoogleAnalyticsService(
|
||||||
|
IAppIdService appIdService,
|
||||||
|
IAuthService authService)
|
||||||
|
{
|
||||||
|
_authService = authService;
|
||||||
|
|
||||||
|
Gai.SharedInstance.DispatchInterval = 10;
|
||||||
|
Gai.SharedInstance.TrackUncaughtExceptions = true;
|
||||||
|
_tracker = Gai.SharedInstance.GetTracker("UA-81915606-1");
|
||||||
|
_tracker.Set(GaiConstants.ClientId, appIdService.AppId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SetUserId { get; set; } = true;
|
||||||
|
|
||||||
|
public void TrackEvent(string category, string eventName)
|
||||||
|
{
|
||||||
|
if(SetUserId)
|
||||||
|
{
|
||||||
|
_tracker.Set(GaiConstants.UserId, _authService.UserId);
|
||||||
|
SetUserId = false;
|
||||||
|
}
|
||||||
|
var dict = DictionaryBuilder.CreateEvent(category, eventName, "AppEvent", null).Build();
|
||||||
|
_tracker.Send(dict);
|
||||||
|
Gai.SharedInstance.Dispatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TrackException(string message, bool fatal)
|
||||||
|
{
|
||||||
|
if(SetUserId)
|
||||||
|
{
|
||||||
|
_tracker.Set(GaiConstants.UserId, _authService.UserId);
|
||||||
|
SetUserId = false;
|
||||||
|
}
|
||||||
|
var dict = DictionaryBuilder.CreateException(message, fatal).Build();
|
||||||
|
_tracker.Send(dict);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TrackPage(string pageName)
|
||||||
|
{
|
||||||
|
if(SetUserId)
|
||||||
|
{
|
||||||
|
_tracker.Set(GaiConstants.UserId, _authService.UserId);
|
||||||
|
SetUserId = false;
|
||||||
|
}
|
||||||
|
_tracker.Set(GaiConstants.ScreenName, pageName);
|
||||||
|
var dict = DictionaryBuilder.CreateScreenView().Build();
|
||||||
|
_tracker.Send(dict);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="..\..\packages\Xamarin.Build.Download.0.2.1\build\Xamarin.Build.Download.props" Condition="Exists('..\..\packages\Xamarin.Build.Download.0.2.1\build\Xamarin.Build.Download.props')" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
@ -33,6 +34,10 @@
|
||||||
<ConsolePause>false</ConsolePause>
|
<ConsolePause>false</ConsolePause>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Google.Analytics, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\..\packages\Xamarin.Google.iOS.Analytics.3.14.0.7\lib\Xamarin.iOS10\Google.Analytics.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
<Reference Include="HockeySDK, Version=1.0.6018.21546, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="HockeySDK, Version=1.0.6018.21546, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\HockeySDK.Xamarin.4.1.0-beta3\lib\Xamarin.iOS10\HockeySDK.dll</HintPath>
|
<HintPath>..\..\packages\HockeySDK.Xamarin.4.1.0-beta3\lib\Xamarin.iOS10\HockeySDK.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
|
@ -79,6 +84,7 @@
|
||||||
<Compile Include="Services\KeyChainStorageService.cs" />
|
<Compile Include="Services\KeyChainStorageService.cs" />
|
||||||
<Compile Include="Services\CommonCryptoKeyDerivationService.cs" />
|
<Compile Include="Services\CommonCryptoKeyDerivationService.cs" />
|
||||||
<Compile Include="Services\Settings.cs" />
|
<Compile Include="Services\Settings.cs" />
|
||||||
|
<Compile Include="Services\GoogleAnalyticsService.cs" />
|
||||||
<Compile Include="Services\SqlService.cs" />
|
<Compile Include="Services\SqlService.cs" />
|
||||||
<Compile Include="Utilities\Dialogs.cs" />
|
<Compile Include="Utilities\Dialogs.cs" />
|
||||||
<Compile Include="Views\ISelectable.cs" />
|
<Compile Include="Views\ISelectable.cs" />
|
||||||
|
@ -101,4 +107,14 @@
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
|
||||||
|
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||||
|
<PropertyGroup>
|
||||||
|
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Error Condition="!Exists('..\..\packages\Xamarin.Build.Download.0.2.1\build\Xamarin.Build.Download.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Xamarin.Build.Download.0.2.1\build\Xamarin.Build.Download.props'))" />
|
||||||
|
<Error Condition="!Exists('..\..\packages\Xamarin.Build.Download.0.2.1\build\Xamarin.Build.Download.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Xamarin.Build.Download.0.2.1\build\Xamarin.Build.Download.targets'))" />
|
||||||
|
<Error Condition="!Exists('..\..\packages\Xamarin.Google.iOS.Analytics.3.14.0.7\build\Xamarin.Google.iOS.Analytics.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Xamarin.Google.iOS.Analytics.3.14.0.7\build\Xamarin.Google.iOS.Analytics.targets'))" />
|
||||||
|
</Target>
|
||||||
|
<Import Project="..\..\packages\Xamarin.Build.Download.0.2.1\build\Xamarin.Build.Download.targets" Condition="Exists('..\..\packages\Xamarin.Build.Download.0.2.1\build\Xamarin.Build.Download.targets')" />
|
||||||
|
<Import Project="..\..\packages\Xamarin.Google.iOS.Analytics.3.14.0.7\build\Xamarin.Google.iOS.Analytics.targets" Condition="Exists('..\..\packages\Xamarin.Google.iOS.Analytics.3.14.0.7\build\Xamarin.Google.iOS.Analytics.targets')" />
|
||||||
</Project>
|
</Project>
|
|
@ -6,4 +6,6 @@
|
||||||
<package id="SQLitePCL.bundle_green" version="0.9.3" targetFramework="xamarinios10" />
|
<package id="SQLitePCL.bundle_green" version="0.9.3" targetFramework="xamarinios10" />
|
||||||
<package id="SQLitePCL.raw" version="0.9.3" targetFramework="xamarinios10" />
|
<package id="SQLitePCL.raw" version="0.9.3" targetFramework="xamarinios10" />
|
||||||
<package id="Xam.Plugins.Settings" version="2.1.0" targetFramework="xamarinios10" />
|
<package id="Xam.Plugins.Settings" version="2.1.0" targetFramework="xamarinios10" />
|
||||||
|
<package id="Xamarin.Build.Download" version="0.2.1" targetFramework="xamarinios10" />
|
||||||
|
<package id="Xamarin.Google.iOS.Analytics" version="3.14.0.7" targetFramework="xamarinios10" />
|
||||||
</packages>
|
</packages>
|
Loading…
Reference in a new issue