1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-22 11:13:49 +00:00

Added google analytics service implementation for iOS and android

This commit is contained in:
Kyle Spearrin
2016-08-03 21:25:01 -04:00
parent b5dfe2d336
commit 41deae60f5
9 changed files with 3431 additions and 2926 deletions

View 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);
}
}
}

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<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>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -33,6 +34,10 @@
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<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">
<HintPath>..\..\packages\HockeySDK.Xamarin.4.1.0-beta3\lib\Xamarin.iOS10\HockeySDK.dll</HintPath>
<Private>True</Private>
@@ -79,6 +84,7 @@
<Compile Include="Services\KeyChainStorageService.cs" />
<Compile Include="Services\CommonCryptoKeyDerivationService.cs" />
<Compile Include="Services\Settings.cs" />
<Compile Include="Services\GoogleAnalyticsService.cs" />
<Compile Include="Services\SqlService.cs" />
<Compile Include="Utilities\Dialogs.cs" />
<Compile Include="Views\ISelectable.cs" />
@@ -101,4 +107,14 @@
</ProjectReference>
</ItemGroup>
<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>

View File

@@ -6,4 +6,6 @@
<package id="SQLitePCL.bundle_green" 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="Xamarin.Build.Download" version="0.2.1" targetFramework="xamarinios10" />
<package id="Xamarin.Google.iOS.Analytics" version="3.14.0.7" targetFramework="xamarinios10" />
</packages>