mirror of
https://github.com/bitwarden/mobile
synced 2025-12-22 11:13:49 +00:00
Added track screen events for pages and controller in extension. UserId refresh on login/logout.
This commit is contained in:
21
src/iOS.Core/Controllers/ExtendedUITableViewController.cs
Normal file
21
src/iOS.Core/Controllers/ExtendedUITableViewController.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Bit.App.Abstractions;
|
||||
using System;
|
||||
using UIKit;
|
||||
using XLabs.Ioc;
|
||||
|
||||
namespace Bit.iOS.Core.Controllers
|
||||
{
|
||||
public class ExtendedUITableViewController : UITableViewController
|
||||
{
|
||||
public ExtendedUITableViewController(IntPtr handle)
|
||||
: base(handle)
|
||||
{ }
|
||||
|
||||
public override void ViewDidAppear(bool animated)
|
||||
{
|
||||
var googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
|
||||
googleAnalyticsService.TrackPage(GetType().Name);
|
||||
base.ViewDidAppear(animated);
|
||||
}
|
||||
}
|
||||
}
|
||||
21
src/iOS.Core/Controllers/ExtendedUIViewController.cs
Normal file
21
src/iOS.Core/Controllers/ExtendedUIViewController.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using UIKit;
|
||||
using Bit.App.Abstractions;
|
||||
using XLabs.Ioc;
|
||||
|
||||
namespace Bit.iOS.Core.Controllers
|
||||
{
|
||||
public class ExtendedUIViewController : UIViewController
|
||||
{
|
||||
public ExtendedUIViewController(IntPtr handle)
|
||||
: base(handle)
|
||||
{ }
|
||||
|
||||
public override void ViewDidAppear(bool animated)
|
||||
{
|
||||
var googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
|
||||
googleAnalyticsService.TrackPage(GetType().Name);
|
||||
base.ViewDidAppear(animated);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ namespace Bit.iOS.Core.Services
|
||||
{
|
||||
private readonly ITracker _tracker;
|
||||
private readonly IAuthService _authService;
|
||||
private bool _setUserId = true;
|
||||
|
||||
public GoogleAnalyticsService(
|
||||
IAppIdService appIdService,
|
||||
@@ -21,15 +22,15 @@ namespace Bit.iOS.Core.Services
|
||||
_tracker.Set(GaiConstants.ClientId, appIdService.AppId);
|
||||
}
|
||||
|
||||
public bool SetUserId { get; set; } = true;
|
||||
public void RefreshUserId()
|
||||
{
|
||||
_tracker.Set(GaiConstants.UserId, null);
|
||||
_setUserId = true;
|
||||
}
|
||||
|
||||
public void TrackEvent(string category, string eventName)
|
||||
{
|
||||
if(SetUserId)
|
||||
{
|
||||
_tracker.Set(GaiConstants.UserId, _authService.UserId);
|
||||
SetUserId = false;
|
||||
}
|
||||
SetUserId();
|
||||
var dict = DictionaryBuilder.CreateEvent(category, eventName, "AppEvent", null).Build();
|
||||
_tracker.Send(dict);
|
||||
Gai.SharedInstance.Dispatch();
|
||||
@@ -37,25 +38,26 @@ namespace Bit.iOS.Core.Services
|
||||
|
||||
public void TrackException(string message, bool fatal)
|
||||
{
|
||||
if(SetUserId)
|
||||
{
|
||||
_tracker.Set(GaiConstants.UserId, _authService.UserId);
|
||||
SetUserId = false;
|
||||
}
|
||||
SetUserId();
|
||||
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;
|
||||
}
|
||||
SetUserId();
|
||||
_tracker.Set(GaiConstants.ScreenName, pageName);
|
||||
var dict = DictionaryBuilder.CreateScreenView().Build();
|
||||
_tracker.Send(dict);
|
||||
}
|
||||
|
||||
private void SetUserId()
|
||||
{
|
||||
if(_setUserId && _authService.IsAuthenticated)
|
||||
{
|
||||
_tracker.Set(GaiConstants.UserId, _authService.UserId);
|
||||
_setUserId = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +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')" />
|
||||
<Import Project="..\..\packages\Xamarin.Build.Download.0.2.2-beta2\build\Xamarin.Build.Download.props" Condition="Exists('..\..\packages\Xamarin.Build.Download.0.2.2-beta2\build\Xamarin.Build.Download.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
@@ -73,12 +73,18 @@
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Xamarin.iOS" />
|
||||
<Reference Include="XLabs.Ioc, Version=2.0.5782.12218, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\XLabs.IoC.2.0.5782\lib\portable-net45+netcore45+wp8+MonoAndroid1+MonoTouch1\XLabs.Ioc.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Resources\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Constants.cs" />
|
||||
<Compile Include="Controllers\ExtendedUITableViewController.cs" />
|
||||
<Compile Include="Controllers\ExtendedUIViewController.cs" />
|
||||
<Compile Include="HockeyAppCrashManagerDelegate.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\KeyChainStorageService.cs" />
|
||||
@@ -111,10 +117,10 @@
|
||||
<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'))" />
|
||||
<Error Condition="!Exists('..\..\packages\Xamarin.Build.Download.0.2.2-beta2\build\Xamarin.Build.Download.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Xamarin.Build.Download.0.2.2-beta2\build\Xamarin.Build.Download.props'))" />
|
||||
<Error Condition="!Exists('..\..\packages\Xamarin.Build.Download.0.2.2-beta2\build\Xamarin.Build.Download.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Xamarin.Build.Download.0.2.2-beta2\build\Xamarin.Build.Download.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')" />
|
||||
<Import Project="..\..\packages\Xamarin.Build.Download.0.2.2-beta2\build\Xamarin.Build.Download.targets" Condition="Exists('..\..\packages\Xamarin.Build.Download.0.2.2-beta2\build\Xamarin.Build.Download.targets')" />
|
||||
</Project>
|
||||
@@ -6,6 +6,7 @@
|
||||
<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.Build.Download" version="0.2.2-beta2" targetFramework="xamarinios10" />
|
||||
<package id="Xamarin.Google.iOS.Analytics" version="3.14.0.7" targetFramework="xamarinios10" />
|
||||
<package id="XLabs.IoC" version="2.0.5782" targetFramework="xamarinios10" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user