From 5b3f0bdffef6b56c98c44107cd248362301e926a Mon Sep 17 00:00:00 2001 From: "kay.one" <kay.one@gmail.com> Date: Thu, 27 Oct 2011 22:13:56 -0700 Subject: [PATCH] Added google analytics. (only enabled in production) --- NzbDrone.6.0.ReSharper | 2 +- NzbDrone.Common/EnviromentProvider.cs | 29 +++++++++++++++--------- NzbDrone.Web/NzbDrone.Web.csproj | 4 ++++ NzbDrone.Web/Views/Shared/_Layout.cshtml | 19 ++++++++++++++-- 4 files changed, 40 insertions(+), 14 deletions(-) diff --git a/NzbDrone.6.0.ReSharper b/NzbDrone.6.0.ReSharper index c4e417d31..04c374209 100644 --- a/NzbDrone.6.0.ReSharper +++ b/NzbDrone.6.0.ReSharper @@ -97,7 +97,7 @@ <Naming2> <EventHandlerPatternLong>$object$_On$event$</EventHandlerPatternLong> <EventHandlerPatternShort>$event$Handler</EventHandlerPatternShort> - <PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="PrivateStaticReadonly" /> + <PredefinedRule Inspect="True" Prefix="" Suffix="" Style="aaBb" ElementKind="PrivateStaticReadonly" /> <PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="TypesAndNamespaces" /> <PredefinedRule Inspect="True" Prefix="I" Suffix="" Style="AaBb" ElementKind="Interfaces" /> <PredefinedRule Inspect="True" Prefix="T" Suffix="" Style="AaBb" ElementKind="TypeParameters" /> diff --git a/NzbDrone.Common/EnviromentProvider.cs b/NzbDrone.Common/EnviromentProvider.cs index 60dd21a52..f06208e8e 100644 --- a/NzbDrone.Common/EnviromentProvider.cs +++ b/NzbDrone.Common/EnviromentProvider.cs @@ -7,23 +7,20 @@ namespace NzbDrone.Common { public class EnviromentProvider { - public virtual String LogPath - { - get { return Environment.CurrentDirectory; } - } - public virtual bool IsUserInteractive - { - get { return Environment.UserInteractive; } - } +#if DEBUG + private static readonly bool isInDebug = true; +#else + private static readonly bool isInDebug = false; +#endif + + private static readonly string processName = Process.GetCurrentProcess().ProcessName.ToLower(); public static bool IsProduction { get { - if (Debugger.IsAttached) return false; - - var processName = Process.GetCurrentProcess().ProcessName.ToLower(); + if (isInDebug || Debugger.IsAttached) return false; Console.WriteLine(processName); if (processName.Contains("nunit")) return false; @@ -34,6 +31,16 @@ namespace NzbDrone.Common } } + public virtual String LogPath + { + get { return Environment.CurrentDirectory; } + } + + public virtual bool IsUserInteractive + { + get { return Environment.UserInteractive; } + } + public virtual string ApplicationPath { get diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index 810f1e238..d5dddc9ea 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -733,6 +733,10 @@ <Folder Include="App_Data\" /> </ItemGroup> <ItemGroup> + <ProjectReference Include="..\NzbDrone.Common\NzbDrone.Common.csproj"> + <Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project> + <Name>NzbDrone.Common</Name> + </ProjectReference> <ProjectReference Include="..\NzbDrone.Core\NzbDrone.Core.csproj"> <Project>{FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}</Project> <Name>NzbDrone.Core</Name> diff --git a/NzbDrone.Web/Views/Shared/_Layout.cshtml b/NzbDrone.Web/Views/Shared/_Layout.cshtml index 029e1a298..ddffb4ded 100644 --- a/NzbDrone.Web/Views/Shared/_Layout.cshtml +++ b/NzbDrone.Web/Views/Shared/_Layout.cshtml @@ -1,5 +1,6 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> @using Helpers; +@using NzbDrone.Common <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <link rel="SHORTCUT ICON" href="../../favicon.ico" /> @@ -16,7 +17,6 @@ <link type="text/css" rel="stylesheet" href="/Content/overrides.css" /> <link type="text/css" rel="stylesheet" href="/Content/Menu.css" /> <link type="text/css" rel="stylesheet" href="/Content/Slider.css" /> - <script type="text/javascript" src="/Scripts/Plugins/jquery-1.6.3.min.js"></script> <script type="text/javascript" src="/Scripts/Plugins/jquery-ui-1.8.16.min.js"></script> <script type="text/javascript" src="/Scripts/Plugins/MicrosoftAjax.js"></script> @@ -30,7 +30,6 @@ <script type="text/javascript" src="/Scripts/autocomplete.js"></script> <script type="text/javascript" src="/Scripts/addSeries.js"></script> <script type="text/javascript" src="/Scripts/slider.js"></script> - @MvcMiniProfiler.MiniProfiler.RenderIncludes() @RenderSection("HeaderContent", required: false) </head> @@ -72,5 +71,21 @@ @(Html.Telerik().ScriptRegistrar().jQuery(false)) @RenderSection("Scripts", required: false) <script type="text/javascript" src="/Scripts/Notification.js"></script> + @if (EnviromentProvider.IsProduction) + { + <script type="text/javascript"> + var _gaq = _gaq || []; + _gaq.push(['_setAccount', 'UA-8318723-7']); + _gaq.push(['_setDomainName', 'none']); + _gaq.push(['_setAllowLinker', true]); + _gaq.push(['_trackPageview']); + + (function () { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); + </script> + } </body> </html>