diff --git a/src/NzbDrone.Api/Config/HostConfigResource.cs b/src/NzbDrone.Api/Config/HostConfigResource.cs index cc52c01c4..f8dde71a7 100644 --- a/src/NzbDrone.Api/Config/HostConfigResource.cs +++ b/src/NzbDrone.Api/Config/HostConfigResource.cs @@ -10,7 +10,8 @@ namespace NzbDrone.Api.Config public Int32 SslPort { get; set; } public Boolean EnableSsl { get; set; } public Boolean LaunchBrowser { get; set; } - public Boolean AuthenticationEnabled { get; set; } + public bool AuthenticationEnabled { get; set; } + public Boolean AnalyticsEnabled { get; set; } public String Username { get; set; } public String Password { get; set; } public String LogLevel { get; set; } diff --git a/src/NzbDrone.Api/Frontend/Mappers/IndexHtmlMapper.cs b/src/NzbDrone.Api/Frontend/Mappers/IndexHtmlMapper.cs index e59fd0e44..3b2b30cb9 100644 --- a/src/NzbDrone.Api/Frontend/Mappers/IndexHtmlMapper.cs +++ b/src/NzbDrone.Api/Frontend/Mappers/IndexHtmlMapper.cs @@ -13,6 +13,7 @@ namespace NzbDrone.Api.Frontend.Mappers public class IndexHtmlMapper : StaticResourceMapperBase { private readonly IDiskProvider _diskProvider; + private readonly IConfigFileProvider _configFileProvider; private readonly Func _cacheBreakProviderFactory; private readonly string _indexPath; private static readonly Regex ReplaceRegex = new Regex("(?<=(?:href|src|data-main)=\").*?(?=\")", RegexOptions.Compiled | RegexOptions.IgnoreCase); @@ -30,6 +31,7 @@ namespace NzbDrone.Api.Frontend.Mappers : base(diskProvider, logger) { _diskProvider = diskProvider; + _configFileProvider = configFileProvider; _cacheBreakProviderFactory = cacheBreakProviderFactory; _indexPath = Path.Combine(appFolderInfo.StartUpFolder, "UI", "index.html"); @@ -87,6 +89,7 @@ namespace NzbDrone.Api.Frontend.Mappers text = text.Replace("API_ROOT", URL_BASE + "/api"); text = text.Replace("API_KEY", API_KEY); text = text.Replace("APP_VERSION", BuildInfo.Version.ToString()); + text = text.Replace("APP_ANALYTICS", _configFileProvider.AnalyticsEnabled.ToString().ToLowerInvariant()); _generatedContent = text; diff --git a/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs b/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs index ecb23d0a2..1240529f8 100644 --- a/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs +++ b/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs @@ -27,6 +27,7 @@ namespace NzbDrone.Core.Configuration bool EnableSsl { get; } bool LaunchBrowser { get; } bool AuthenticationEnabled { get; } + bool AnalyticsEnabled { get; } string Username { get; } string Password { get; } string LogLevel { get; } @@ -139,6 +140,14 @@ namespace NzbDrone.Core.Configuration get { return GetValueBoolean("AuthenticationEnabled", false); } } + public bool AnalyticsEnabled + { + get + { + return GetValueBoolean("AnalyticsEnabled", true, persist: false); + } + } + public string Branch { get { return GetValue("Branch", "master").ToLowerInvariant(); } diff --git a/src/UI/Settings/General/GeneralViewTemplate.hbs b/src/UI/Settings/General/GeneralViewTemplate.hbs index 60e42c462..69c452aac 100644 --- a/src/UI/Settings/General/GeneralViewTemplate.hbs +++ b/src/UI/Settings/General/GeneralViewTemplate.hbs @@ -173,9 +173,33 @@ +
+ Analytics + +
+ + +
+
+
+
+
- Updating + Updates
diff --git a/src/UI/Shared/NzbDroneController.js b/src/UI/Shared/NzbDroneController.js index c08e14bea..f0d52a9ba 100644 --- a/src/UI/Shared/NzbDroneController.js +++ b/src/UI/Shared/NzbDroneController.js @@ -25,6 +25,19 @@ define( else { document.title = title + ' - nzbdrone'; } + + if(window.Piwik){ + try { + var piwik = window.Piwik.getTracker('http://piwik.nzbdrone.com/piwik.php', 1); + piwik.setReferrerUrl(''); + piwik.setCustomUrl('http://local' + window.location.pathname); + piwik.setCustomVariable(1, 'version', window.NzbDrone.version, 'page'); + piwik.trackPageView(title); + } + catch (e){ + console.error(e); + } + } }, _onServerUpdated: function () { diff --git a/src/UI/index.html b/src/UI/index.html index 9477f7adf..3f2f5a199 100644 --- a/src/UI/index.html +++ b/src/UI/index.html @@ -75,10 +75,12 @@ window.NzbDrone = { ApiRoot: 'API_ROOT', ApiKey : 'API_KEY', - Version: 'APP_VERSION' + Version: 'APP_VERSION', + Analytics: APP_ANALYTICS }; + diff --git a/src/UI/piwik.js b/src/UI/piwik.js new file mode 100644 index 000000000..f56b4af31 --- /dev/null +++ b/src/UI/piwik.js @@ -0,0 +1,14 @@ +'use strict'; + +(function () { +if(window.NzbDrone.Analytics) { + var d = document; + var g = d.createElement('script'); + var s = d.getElementsByTagName('script')[0]; + g.type = 'text/javascript'; + g.async = true; + g.defer = true; + g.src = 'http://piwik.nzbdrone.com/piwik.js'; + s.parentNode.insertBefore(g, s); +} +})(); \ No newline at end of file