Skip to content

Commit

Permalink
Merge branch 'google-analytics'
Browse files Browse the repository at this point in the history
Conflicts:
	Hearthstone Deck Tracker/Core.cs
	Hearthstone Deck Tracker/Hearthstone Deck Tracker.csproj
  • Loading branch information
Epix37 committed Oct 22, 2015
2 parents d2f4b7a + 2ef2905 commit dd4cfe0
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 42 deletions.
6 changes: 5 additions & 1 deletion Hearthstone Deck Tracker/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
using System.Linq;
using System.Windows;
using System.Windows.Threading;
using Garlic;
using Hearthstone_Deck_Tracker.Controls.Error;
using Hearthstone_Deck_Tracker.Utility;

#endregion

Expand Down Expand Up @@ -36,6 +38,8 @@ private void App_DispatcherUnhandledException(object sender, DispatcherUnhandled
return;
}
}

Analytics.Analytics.TrackEvent("UnhandledException", e.Exception.GetType().ToString().Split('.').Last(), e.Exception.TargetSite.ToString());
#if (!DEBUG)
var date = DateTime.Now;
var fileName = "Crash Reports\\"
Expand Down Expand Up @@ -64,6 +68,6 @@ private void App_OnStartup(object sender, StartupEventArgs e)
{
ShutdownMode = ShutdownMode.OnExplicitShutdown;
Core.Initialize();
}
}
}
}
13 changes: 8 additions & 5 deletions Hearthstone Deck Tracker/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Config

private static Config _config;

public readonly string AppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
public static readonly string AppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
+ @"\HearthstoneDeckTracker";

[DefaultValue("Blue")]
Expand Down Expand Up @@ -262,6 +262,9 @@ public class Config
//move this to some data file
public int[] GoldProgressTotal = { 0, 0, 0, 0, 0 };

[DefaultValue(true)]
public bool GoogleAnalytics = true;

[DefaultValue(null)]
public bool? HearthStatsAutoDeleteDecks = null;

Expand Down Expand Up @@ -935,9 +938,9 @@ public static void Load()
_config = XmlManager<Config>.Load("config.xml");
foundConfig = true;
}
else if(File.Exists(Instance.AppDataPath + @"\config.xml"))
else if(File.Exists(AppDataPath + @"\config.xml"))
{
_config = XmlManager<Config>.Load(Instance.AppDataPath + @"\config.xml");
_config = XmlManager<Config>.Load(AppDataPath + @"\config.xml");
foundConfig = true;
}
else if(!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)))
Expand Down Expand Up @@ -970,10 +973,10 @@ public static void Load()
Logger.WriteLine("Moved config to appdata", "Config");
}
}
else if(File.Exists(Instance.AppDataPath + @"\config.xml"))
else if(File.Exists(AppDataPath + @"\config.xml"))
{
SaveBackup(true); //backup in case the file already exists
File.Move(Instance.AppDataPath + @"\config.xml", Instance.ConfigPath);
File.Move(AppDataPath + @"\config.xml", Instance.ConfigPath);
Logger.WriteLine("Moved config to local", "Config");
}
}
Expand Down
16 changes: 13 additions & 3 deletions Hearthstone Deck Tracker/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using Hearthstone_Deck_Tracker.Enums;
using Hearthstone_Deck_Tracker.Hearthstone;
using Hearthstone_Deck_Tracker.HearthStats.API;
using Hearthstone_Deck_Tracker.LogReader;
Expand Down Expand Up @@ -41,26 +42,32 @@ public static OverlayWindow Overlay
public static void Initialize()
{
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
var newUser = !Directory.Exists(Config.AppDataPath);
Config.Load();
ConfigManager.Run();
Logger.Initialzie();
Helper.UpdateAppTheme();
var splashScreenWindow = new SplashScreenWindow();
splashScreenWindow.ShowConditional();
Game = new GameV2();
if (!HearthStatsAPI.LoadCredentials() && Config.Instance.ShowLoginDialog)
Game = new GameV2();
LoginType loginType;
var loggedIn = HearthStatsAPI.LoadCredentials();
if (!loggedIn && Config.Instance.ShowLoginDialog)
{
var loginWindow = new LoginWindow();
splashScreenWindow.Close();
loginWindow.ShowDialog();
if (!loginWindow.LoginResult)
if (loginWindow.LoginResult == LoginType.None)
{
Application.Current.Shutdown();
return;
}
loginType = loginWindow.LoginResult;
splashScreenWindow = new SplashScreenWindow();
splashScreenWindow.ShowConditional();
}
else
loginType = loggedIn ? LoginType.AutoLogin : LoginType.AutoGuest;
MainWindow = new MainWindow();
MainWindow.LoadConfigSettings();
MainWindow.Show();
Expand Down Expand Up @@ -109,6 +116,9 @@ public static void Initialize()
HotKeyManager.Load();
Initialized = true;

Analytics.Analytics.TrackPageView(
string.Format("/app/v{0}/{1}{2}", Helper.GetCurrentVersion().ToVersionString(),
loginType.ToString().ToLower(), newUser ? "/new" : ""), "");
}

private static async void UpdateOverlayAsync()
Expand Down
2 changes: 1 addition & 1 deletion Hearthstone Deck Tracker/DeckList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ internal static void SetupDeckListFile()
{
if(Config.Instance.SaveDataInAppData == null)
return;
var appDataPath = Config.Instance.AppDataPath + @"\PlayerDecks.xml";
var appDataPath = Config.AppDataPath + @"\PlayerDecks.xml";
var dataDirPath = Config.Instance.DataDirPath + @"\PlayerDecks.xml";
if(Config.Instance.SaveDataInAppData.Value)
{
Expand Down
18 changes: 18 additions & 0 deletions Hearthstone Deck Tracker/Enums/LoginType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hearthstone_Deck_Tracker.Enums
{
public enum LoginType
{
None,
AutoLogin,
AutoGuest,
Login,
Guest,
Register
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
<GroupBox Header="Settings">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel>
<GroupBox Header="Google Analytics">
<StackPanel>
<CheckBox Name="CheckBoxAnalytics" Content="Submit anonymous data" Checked="CheckBoxAnalytics_OnChecked" Unchecked="CheckBoxAnalytics_OnUnchecked"/>
<TextBlock
Text="This only tracks two things: App starts, where the version number and login mode is submitted, as well as information about crashes."
TextWrapping="Wrap" />
</StackPanel>
</GroupBox>
<DockPanel Margin="10,5,10,0">
<Label Content="Key on game start:" HorizontalAlignment="Right"
VerticalAlignment="Top" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void Load()
CheckBoxShowLoginDialog.IsChecked = Config.Instance.ShowLoginDialog;
CheckBoxShowSplashScreen.IsChecked = Config.Instance.ShowSplashScreen;
CheckboxStartWithWindows.IsChecked = Config.Instance.StartWithWindows;
CheckBoxAnalytics.IsChecked = Config.Instance.GoogleAnalytics;

if(!Helper.EventKeys.Contains(Config.Instance.KeyPressOnGameStart))
Config.Instance.KeyPressOnGameStart = "None";
Expand Down Expand Up @@ -277,7 +278,7 @@ private async void SelectSaveDataPath_Click(object sender, RoutedEventArgs e)

private void ButtonOpenAppData_OnClick(object sender, RoutedEventArgs e)
{
Process.Start(Config.Instance.AppDataPath);
Process.Start(Config.AppDataPath);
}

private void CheckboxStartWithWindows_Checked(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -355,5 +356,20 @@ private void ButtonRestart_OnClick(object sender, RoutedEventArgs e)
Core.MainWindow.Restart();
}

private void CheckBoxAnalytics_OnChecked(object sender, RoutedEventArgs e)
{
if(!_initialized)
return;
Config.Instance.GoogleAnalytics = true;
Config.Save();
}

private void CheckBoxAnalytics_OnUnchecked(object sender, RoutedEventArgs e)
{
if(!_initialized)
return;
Config.Instance.GoogleAnalytics = false;
Config.Save();
}
}
}
6 changes: 6 additions & 0 deletions Hearthstone Deck Tracker/Hearthstone Deck Tracker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
<PropertyGroup />
<ItemGroup>
<Reference Include="Accessibility" />
<Reference Include="Garlic">
<HintPath>..\packages\Garlic.2.1.0.0\lib\net35\Garlic.dll</HintPath>
</Reference>
<Reference Include="HtmlAgilityPack">
<HintPath>..\packages\HtmlAgilityPack.1.4.6\lib\Net45\HtmlAgilityPack.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -148,6 +151,7 @@
<Compile Include="Enums\DeckLayout.cs" />
<Compile Include="Enums\Hearthstone\TAG_CLASS.cs" />
<Compile Include="Enums\IconStyle.cs" />
<Compile Include="Enums\LoginType.cs" />
<Compile Include="Errors\ErrorItem.xaml.cs">
<DependentUpon>ErrorItem.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -277,6 +281,7 @@
<Compile Include="Protocol\JsonDeck.cs" />
<Compile Include="Protocol\JsonDecksWrapper.cs" />
<Compile Include="Replay\TurnViewItem.cs" />
<Compile Include="Utility\Analytics.cs" />
<Compile Include="Utility\HotKeys\HotKey.cs" />
<Compile Include="Utility\HotKeys\PredefinedHotKeyActionAttribute.cs" />
<Compile Include="Utility\HotKeys\HotKeyConfig.cs" />
Expand Down Expand Up @@ -3760,6 +3765,7 @@
xcopy /Y "HDTHelper.exe" "..\Hearthstone Deck Tracker"
xcopy /Y "HDTUpdate.exe" "..\Hearthstone Deck Tracker"
xcopy /Y "HDTUninstaller.exe" "..\Hearthstone Deck Tracker"
xcopy /Y "Garlic.dll" "..\Hearthstone Deck Tracker"
xcopy /Y "HtmlAgilityPack.dll" "..\Hearthstone Deck Tracker"
xcopy /Y "MahApps.Metro.dll" "..\Hearthstone Deck Tracker"
xcopy /Y "Newtonsoft.Json.dll" "..\Hearthstone Deck Tracker"
Expand Down
4 changes: 2 additions & 2 deletions Hearthstone Deck Tracker/Stats/DeckStatsList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ internal static void SetupDeckStatsFile()
{
if(Config.Instance.SaveDataInAppData == null)
return;
var appDataPath = Config.Instance.AppDataPath + @"\DeckStats.xml";
var appDataGamesDirPath = Config.Instance.AppDataPath + @"\Games";
var appDataPath = Config.AppDataPath + @"\DeckStats.xml";
var appDataGamesDirPath = Config.AppDataPath + @"\Games";
var dataDirPath = Config.Instance.DataDirPath + @"\DeckStats.xml";
var dataGamesDirPath = Config.Instance.DataDirPath + @"\Games";
if(Config.Instance.SaveDataInAppData.Value)
Expand Down
2 changes: 1 addition & 1 deletion Hearthstone Deck Tracker/Stats/DefaultDeckStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ internal static void SetupDefaultDeckStatsFile()
{
if(Config.Instance.SaveDataInAppData == null)
return;
var appDataPath = Config.Instance.AppDataPath + @"\DefaultDeckStats.xml";
var appDataPath = Config.AppDataPath + @"\DefaultDeckStats.xml";
var dataDirPath = Config.Instance.DataDirPath + @"\DefaultDeckStats.xml";
if(Config.Instance.SaveDataInAppData.Value)
{
Expand Down
33 changes: 33 additions & 0 deletions Hearthstone Deck Tracker/Utility/Analytics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using Garlic;

//using Garlic;

namespace Hearthstone_Deck_Tracker.Analytics
{
internal class Analytics
{
private const string Domain = "app.hsdecktracker.net";
private const string GACode = "UA-68659282-3";
private static readonly AnalyticsSession Session = new AnalyticsSession(Domain, GACode);
private static IAnalyticsPageViewRequest _pageViewRequest;

public static void TrackEvent(string category, string action, string label = "", string value = "")
{
if(!Config.Instance.GoogleAnalytics)
return;
if(_pageViewRequest == null)
return;
_pageViewRequest.SendEvent(category, action, label, value);
}

public static void TrackPageView(string page, string title)
{
if(!Config.Instance.GoogleAnalytics)
return;
_pageViewRequest = Session.CreatePageViewRequest(page, title);
_pageViewRequest.Send();
}
}
}
2 changes: 1 addition & 1 deletion Hearthstone Deck Tracker/Utility/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ public static void CopyReplayFiles()
{
if(Config.Instance.SaveDataInAppData == null)
return;
var appDataReplayDirPath = Config.Instance.AppDataPath + @"\Replays";
var appDataReplayDirPath = Config.AppDataPath + @"\Replays";
var dataReplayDirPath = Config.Instance.DataDirPath + @"\Replays";
if(Config.Instance.SaveDataInAppData.Value)
{
Expand Down
39 changes: 12 additions & 27 deletions Hearthstone Deck Tracker/Windows/LoginWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
using System.Windows;
using System.Windows.Navigation;
using Hearthstone_Deck_Tracker.Annotations;
using Hearthstone_Deck_Tracker.Enums;
using Hearthstone_Deck_Tracker.Hearthstone;
using Hearthstone_Deck_Tracker.HearthStats.API;
using Hearthstone_Deck_Tracker.Utility;
using MahApps.Metro.Controls.Dialogs;

#endregion
Expand All @@ -26,19 +28,17 @@ public partial class LoginWindow : INotifyPropertyChanged
private readonly bool _initialized;
private ProgressDialogController _controller;
private Visibility _loginRegisterVisibility;
public bool LoginResult { get; private set; }
private LoginType _loginResult = LoginType.None;

public LoginType LoginResult
{
get { return _loginResult; }
private set { _loginResult = value; }
}

public LoginWindow()
{
//Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
//Config.Load();
//Logger.Initialzie();
//_game = new GameV2();
//Card.SetGame(_game);
//API.Core.Game = _game;
InitializeComponent();
//if(HearthStatsAPI.LoadCredentials() || !Config.Instance.ShowLoginDialog)
// StartMainApp();
CheckBoxRememberLogin.IsChecked = Config.Instance.RememberHearthStatsLogin;
_initialized = true;
}
Expand Down Expand Up @@ -71,21 +71,6 @@ private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e
Process.Start(e.Uri.AbsoluteUri);
}

/*private void StartMainApp()
{
IsEnabled = false;
var mainWindow = new MainWindow(_game);
try
{
mainWindow.Show();
}
catch(Exception ex)
{
Logger.WriteLine("Error showing main window: " + ex, "LoginWindow");
}
Close();
}*/

private async void BtnLogin_Click(object sender, RoutedEventArgs e)
{
var email = TextBoxEmail.Text;
Expand All @@ -105,7 +90,7 @@ private async void BtnLogin_Click(object sender, RoutedEventArgs e)
TextBoxPassword.Clear();
if (result.Success)
{
LoginResult = true;
LoginResult = LoginType.Login;
Close();
}
else if(result.Message.Contains("401"))
Expand Down Expand Up @@ -201,7 +186,7 @@ private async void BtnRegister_Click(object sender, RoutedEventArgs e)
TextBoxRegisterPasswordConfirm.Clear();
if(result.Success)
{
LoginResult = true;
LoginResult = LoginType.Register;
Close();
}
}
Expand Down Expand Up @@ -231,7 +216,7 @@ private void ButtonBack_OnClick(object sender, RoutedEventArgs e)
private void Button_ContinueAnyway(object sender, RoutedEventArgs e)
{
Logger.WriteLine("Continuing as guest...");
LoginResult = true;
LoginResult = LoginType.Guest;
Close();
}

Expand Down
1 change: 1 addition & 0 deletions Hearthstone Deck Tracker/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Garlic" version="2.1.0.0" targetFramework="net45" />
<package id="MahApps.Metro" version="1.1.2.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
</packages>
Loading

0 comments on commit dd4cfe0

Please sign in to comment.