Merge pull request #119 from NzbDrone/piwik-web
New: added self hosted analytics to help improve nzbdrone.
This commit is contained in:
commit
e3efd9a84c
|
@ -10,7 +10,8 @@ namespace NzbDrone.Api.Config
|
||||||
public Int32 SslPort { get; set; }
|
public Int32 SslPort { get; set; }
|
||||||
public Boolean EnableSsl { get; set; }
|
public Boolean EnableSsl { get; set; }
|
||||||
public Boolean LaunchBrowser { 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 Username { get; set; }
|
||||||
public String Password { get; set; }
|
public String Password { get; set; }
|
||||||
public String LogLevel { get; set; }
|
public String LogLevel { get; set; }
|
||||||
|
|
|
@ -6,6 +6,7 @@ using Nancy;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.Disk;
|
using NzbDrone.Common.Disk;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
using NzbDrone.Core.Analytics;
|
||||||
using NzbDrone.Core.Configuration;
|
using NzbDrone.Core.Configuration;
|
||||||
|
|
||||||
namespace NzbDrone.Api.Frontend.Mappers
|
namespace NzbDrone.Api.Frontend.Mappers
|
||||||
|
@ -13,6 +14,8 @@ namespace NzbDrone.Api.Frontend.Mappers
|
||||||
public class IndexHtmlMapper : StaticResourceMapperBase
|
public class IndexHtmlMapper : StaticResourceMapperBase
|
||||||
{
|
{
|
||||||
private readonly IDiskProvider _diskProvider;
|
private readonly IDiskProvider _diskProvider;
|
||||||
|
private readonly IConfigFileProvider _configFileProvider;
|
||||||
|
private readonly IAnalyticsService _analyticsService;
|
||||||
private readonly Func<ICacheBreakerProvider> _cacheBreakProviderFactory;
|
private readonly Func<ICacheBreakerProvider> _cacheBreakProviderFactory;
|
||||||
private readonly string _indexPath;
|
private readonly string _indexPath;
|
||||||
private static readonly Regex ReplaceRegex = new Regex("(?<=(?:href|src|data-main)=\").*?(?=\")", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
private static readonly Regex ReplaceRegex = new Regex("(?<=(?:href|src|data-main)=\").*?(?=\")", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||||
|
@ -25,11 +28,14 @@ namespace NzbDrone.Api.Frontend.Mappers
|
||||||
public IndexHtmlMapper(IAppFolderInfo appFolderInfo,
|
public IndexHtmlMapper(IAppFolderInfo appFolderInfo,
|
||||||
IDiskProvider diskProvider,
|
IDiskProvider diskProvider,
|
||||||
IConfigFileProvider configFileProvider,
|
IConfigFileProvider configFileProvider,
|
||||||
|
IAnalyticsService analyticsService,
|
||||||
Func<ICacheBreakerProvider> cacheBreakProviderFactory,
|
Func<ICacheBreakerProvider> cacheBreakProviderFactory,
|
||||||
Logger logger)
|
Logger logger)
|
||||||
: base(diskProvider, logger)
|
: base(diskProvider, logger)
|
||||||
{
|
{
|
||||||
_diskProvider = diskProvider;
|
_diskProvider = diskProvider;
|
||||||
|
_configFileProvider = configFileProvider;
|
||||||
|
_analyticsService = analyticsService;
|
||||||
_cacheBreakProviderFactory = cacheBreakProviderFactory;
|
_cacheBreakProviderFactory = cacheBreakProviderFactory;
|
||||||
_indexPath = Path.Combine(appFolderInfo.StartUpFolder, "UI", "index.html");
|
_indexPath = Path.Combine(appFolderInfo.StartUpFolder, "UI", "index.html");
|
||||||
|
|
||||||
|
@ -88,6 +94,8 @@ namespace NzbDrone.Api.Frontend.Mappers
|
||||||
text = text.Replace("API_KEY", API_KEY);
|
text = text.Replace("API_KEY", API_KEY);
|
||||||
text = text.Replace("APP_VERSION", BuildInfo.Version.ToString());
|
text = text.Replace("APP_VERSION", BuildInfo.Version.ToString());
|
||||||
|
|
||||||
|
text = text.Replace("APP_ANALYTICS", _analyticsService.IsEnabled.ToString().ToLowerInvariant());
|
||||||
|
|
||||||
_generatedContent = text;
|
_generatedContent = text;
|
||||||
|
|
||||||
return _generatedContent;
|
return _generatedContent;
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
using NzbDrone.Core.Configuration;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Analytics
|
||||||
|
{
|
||||||
|
public interface IAnalyticsService
|
||||||
|
{
|
||||||
|
bool IsEnabled { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AnalyticsService : IAnalyticsService
|
||||||
|
{
|
||||||
|
private readonly IConfigFileProvider _configFileProvider;
|
||||||
|
|
||||||
|
public AnalyticsService(IConfigFileProvider configFileProvider)
|
||||||
|
{
|
||||||
|
_configFileProvider = configFileProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsEnabled
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _configFileProvider.AnalyticsEnabled && RuntimeInfoBase.IsProduction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,6 +27,7 @@ namespace NzbDrone.Core.Configuration
|
||||||
bool EnableSsl { get; }
|
bool EnableSsl { get; }
|
||||||
bool LaunchBrowser { get; }
|
bool LaunchBrowser { get; }
|
||||||
bool AuthenticationEnabled { get; }
|
bool AuthenticationEnabled { get; }
|
||||||
|
bool AnalyticsEnabled { get; }
|
||||||
string Username { get; }
|
string Username { get; }
|
||||||
string Password { get; }
|
string Password { get; }
|
||||||
string LogLevel { get; }
|
string LogLevel { get; }
|
||||||
|
@ -139,6 +140,14 @@ namespace NzbDrone.Core.Configuration
|
||||||
get { return GetValueBoolean("AuthenticationEnabled", false); }
|
get { return GetValueBoolean("AuthenticationEnabled", false); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool AnalyticsEnabled
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return GetValueBoolean("AnalyticsEnabled", true, persist: false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string Branch
|
public string Branch
|
||||||
{
|
{
|
||||||
get { return GetValue("Branch", "master").ToLowerInvariant(); }
|
get { return GetValue("Branch", "master").ToLowerInvariant(); }
|
||||||
|
|
|
@ -109,6 +109,7 @@
|
||||||
<Compile Include="..\NzbDrone.Common\Properties\SharedAssemblyInfo.cs">
|
<Compile Include="..\NzbDrone.Common\Properties\SharedAssemblyInfo.cs">
|
||||||
<Link>Properties\SharedAssemblyInfo.cs</Link>
|
<Link>Properties\SharedAssemblyInfo.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Analytics\AnalyticsService.cs" />
|
||||||
<Compile Include="Annotations\FieldDefinitionAttribute.cs" />
|
<Compile Include="Annotations\FieldDefinitionAttribute.cs" />
|
||||||
<Compile Include="Backup\Backup.cs" />
|
<Compile Include="Backup\Backup.cs" />
|
||||||
<Compile Include="Backup\BackupCommand.cs" />
|
<Compile Include="Backup\BackupCommand.cs" />
|
||||||
|
|
|
@ -173,9 +173,33 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<legend>Analytics</legend>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-3 control-label">Enable</label>
|
||||||
|
|
||||||
|
<div class="col-sm-8">
|
||||||
|
<div class="input-group">
|
||||||
|
<label class="checkbox toggle well">
|
||||||
|
<input type="checkbox" name="analyticsEnabled" class="form-control"/>
|
||||||
|
<p>
|
||||||
|
<span>Yes</span>
|
||||||
|
<span>No</span>
|
||||||
|
</p>
|
||||||
|
<div class="btn btn-primary slide-button"/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<span class="help-inline-checkbox">
|
||||||
|
<i class="icon-nd-form-info" title="Send anonymous information about your browser and which parts of the web interface you use to NzbDrone servers. We use this information to prioritize features and browser support. We will NEVER include any personal information or any information that could identify you."/>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
<fieldset class="advanced-setting">
|
<fieldset class="advanced-setting">
|
||||||
<legend>Updating</legend>
|
<legend>Updates</legend>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-sm-3 control-label">Branch</label>
|
<label class="col-sm-3 control-label">Branch</label>
|
||||||
|
|
|
@ -25,6 +25,19 @@ define(
|
||||||
else {
|
else {
|
||||||
document.title = title + ' - nzbdrone';
|
document.title = title + ' - nzbdrone';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(window.NzbDrone.Analytics && 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 () {
|
_onServerUpdated: function () {
|
||||||
|
|
|
@ -75,10 +75,12 @@
|
||||||
window.NzbDrone = {
|
window.NzbDrone = {
|
||||||
ApiRoot: 'API_ROOT',
|
ApiRoot: 'API_ROOT',
|
||||||
ApiKey : 'API_KEY',
|
ApiKey : 'API_KEY',
|
||||||
Version: 'APP_VERSION'
|
Version: 'APP_VERSION',
|
||||||
|
Analytics: APP_ANALYTICS
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script src="/piwik.js"></script>
|
||||||
<script src="/polyfills.js"></script>
|
<script src="/polyfills.js"></script>
|
||||||
<script src="/JsLibraries/handlebars.runtime.js"></script>
|
<script src="/JsLibraries/handlebars.runtime.js"></script>
|
||||||
<script data-main="/main" src="/JsLibraries/require.js"></script>
|
<script data-main="/main" src="/JsLibraries/require.js"></script>
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
'use strict';
|
||||||
|
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);
|
||||||
|
}
|
Loading…
Reference in New Issue