added google analytics support to plugin backend

This commit is contained in:
Sebastian Sdorra
2011-11-13 18:05:33 +01:00
parent 3e5fb38120
commit 124cae18d7
5 changed files with 62 additions and 10 deletions

View File

@@ -116,6 +116,17 @@ public class BackendConfiguration
return scannInterval;
}
/**
* Method description
*
*
* @return
*/
public String getTrackingCode()
{
return trackingCode;
}
/**
* Method description
*
@@ -195,6 +206,17 @@ public class BackendConfiguration
this.scannInterval = scannInterval;
}
/**
* Method description
*
*
* @param trackingCode
*/
public void setTrackingCode(String trackingCode)
{
this.trackingCode = trackingCode;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
@@ -211,7 +233,7 @@ public class BackendConfiguration
private boolean multithreaded = true;
/** Field description */
@XmlElement(name= "news-url")
@XmlElement(name = "news-url")
private URL newsUrl;
/** Field description */
@@ -223,4 +245,8 @@ public class BackendConfiguration
@XmlElement(name = "scann-interval")
@XmlJavaTypeAdapter(XmlIntervalAdapter.class)
private Long scannInterval;
/** Field description */
@XmlElement(name = "tracking-code")
private String trackingCode;
}

View File

@@ -37,6 +37,7 @@ package sonia.scm.plugin.rest;
import com.google.inject.Inject;
import sonia.scm.plugin.BackendConfiguration;
import sonia.scm.plugin.PluginBackend;
import sonia.scm.plugin.PluginInformation;
import sonia.scm.plugin.PluginUtil;
@@ -74,11 +75,13 @@ public class DetailResource extends ViewableResource
*
* @param context
* @param backend
* @param configuration
*/
@Inject
public DetailResource(ServletContext context, PluginBackend backend)
public DetailResource(ServletContext context, PluginBackend backend,
BackendConfiguration configuration)
{
super(context);
super(context, configuration);
this.backend = backend;
}
@@ -100,10 +103,10 @@ public class DetailResource extends ViewableResource
@DefaultValue("false")
@QueryParam("snapshot") boolean snapshot)
{
List<PluginInformation> pluginVersions = PluginUtil.getFilteredPluginVersions(
backend, groupId, artifactId);
if (Util.isEmpty(pluginVersions))
List<PluginInformation> pluginVersions =
PluginUtil.getFilteredPluginVersions(backend, groupId, artifactId);
if (Util.isEmpty(pluginVersions))
{
throw new WebApplicationException(Status.NOT_FOUND);
}

View File

@@ -37,6 +37,7 @@ package sonia.scm.plugin.rest;
import com.google.inject.Inject;
import sonia.scm.plugin.BackendConfiguration;
import sonia.scm.plugin.Category;
import sonia.scm.plugin.CategoryNameComaparator;
import sonia.scm.plugin.PluginBackend;
@@ -78,11 +79,13 @@ public class OverviewResource extends ViewableResource
*
* @param context
* @param backend
* @param configuration
*/
@Inject
public OverviewResource(ServletContext context, PluginBackend backend)
public OverviewResource(ServletContext context, PluginBackend backend,
BackendConfiguration configuration)
{
super(context);
super(context, configuration);
this.backend = backend;
}

View File

@@ -39,6 +39,7 @@ import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletContext;
import sonia.scm.plugin.BackendConfiguration;
/**
*
@@ -53,10 +54,13 @@ public class ViewableResource
*
* @param context
*/
public ViewableResource(ServletContext context)
public ViewableResource(ServletContext context, BackendConfiguration configuration)
{
this.contextPath = context.getContextPath();
this.configuration = configuration;
}
private BackendConfiguration configuration;
//~--- methods --------------------------------------------------------------
@@ -73,6 +77,7 @@ public class ViewableResource
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("contextPath", contextPath);
vars.put("configuration", configuration);
vars.put("title", title);
return vars;

View File

@@ -48,6 +48,21 @@
<script src="${contextPath}template/js/html5.js"></script>
<![endif]-->
<base href="${contextPath}" />
<#if configuration.trackingConde??>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '${configuration.trackingCode}']);
_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>
</#if>
</head>
<body class="home page page-id-8 page-template-default logged-in admin-bar layout-2cr">
<div id="wrapper">