I’ve recently been looking at how I can use Google Analytics to track website usage of content based on the category it has been assigned. We are using META tags in the page headings to store the category name and title of the content.
Google have just rolled out a bunch of excessively handy features allowing custom variables in their most recent update to the analytics package, unfortunetly my Analytics account hasn’t yet been updated to include them. As a fall back I’ve used the Event Tracking functionality instead.
At the bottom of each page which I want to track the category of, added the following code;
-
-
<script type="text/javascript">
-
var pageTracker = _gat._getTracker("<%= googleAnalyticsId %>");
-
-
function getMeta(name) {
-
var metas = document.getElementsByTagName(‘META’);
-
for (var i = 0; i < metas.length; i++){
-
if (metas[i].getAttribute(‘NAME’) == name){
-
return metas[i].getAttribute(‘CONTENT’);
-
}
-
}
-
return "null";
-
}
-
-
try {
-
var cat = getMeta("CATEGORY");
-
var title = getMeta("ARTICLE_NAME");
-
-
if(cat != "null" && title != "null"){
-
pageTracker._trackEvent(‘Category’,cat,title);
-
}
-
}catch(ex){
-
/* do nothing */
-
}
-
pageTracker._trackPageview();
-
</script>
-
Using this codes means that I can put these meta tags into the headings of any page;
-
-
<meta name="CATEGORY" content="Analytics" />
-
<meta name="ARTICLE_NAME" content="Custom Variables" />
-
And Google Analytics will track the my each of my articles based on the category they have been tagged with.
I’m currently developing ten tonne of portlets using the Spring Portlet MVC framework. It’s been a frustrating but rewarding experience. I’ve been struggling with general documentation and examples for a while, and I wanted to make a quick post about a problem I’ve been having. Mainly because I found lots of people with similar issues, but no help at a resolution.
I’ve been using the AbstractWizardFormController, and over-riding the
-
-
public ModelAndView showForm
(RenderRequest request, RenderResponse response,
BindException errors
) throws Exception
-
method to display my view and the
protected Object formBackingObject(PortletRequest request) throws Exception
method to populate my command bean.
My XML looked like this;
-
-
<bean id="menuSpotlightController" class="uk.co.smileham.cms.controller.edit.SpotlightController">
-
<property name="viewName" value="spotlightMenu" />
-
<property name="commandName" value="preferenceCommand" />
-
<property name="commandClass" value="uk.co.smileham.cms.model.PreferenceCommand" />
-
</bean>
-
This all seemed fine to me, however whenever I then tried to use the porlet I’d have a huge exception that went something along the lines of;
-
-
2009-10-21 14:04:28,765 ERROR [http-8080-Processor19] org.springframework.web.servlet.tags.form.SelectTag – Neither BindingResult nor plain target object for bean name ‘preferenceCommand’ available as request attribute
-
java.
lang.
IllegalStateException: Neither BindingResult nor plain target object
for bean name
‘preferenceCommand’ available as request attribute
-
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
-
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:172)
-
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:192)
-
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:158)
-
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:121)
-
at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:379)
-
at org.springframework.web.servlet.tags.form.SelectTag.writeTagContent(SelectTag.java:198)
-
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:90)
-
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:77)
-
at org.apache.jsp.WEB_002dINF.jsp.spotlightMenu_jsp._jspService(spotlightMenu_jsp.java:658)
-
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
-
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
-
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
-
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
-
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
-
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
-
After much frustration I discovered that the problem was that the “preferenceCommand” was being set in the model, but then being overridden by a new model in my showForm() method.
The solution was to read the documentation (funny that) and eventually found that when using the AbstractFormController you should not directly create a new ModelAndView object to return but instead get the current model from the “BindException errors” variable that has been passed in and then “return super.showForm(request, errors, viewName);”
So my final showForm method went from;
-
-
public ModelAndView showForm
(RenderRequest request, RenderResponse response,
BindException errors
) throws Exception {
-
ModelAndView mav = new ModelAndView(viewName);
-
return mav;
-
}
-
to
-
-
public ModelAndView showForm
(RenderRequest request, RenderResponse response,
BindException errors
) throws Exception {
-
Map<String,Object> model = errors.getModel();
-
return super.showForm(request, errors, viewName);
-
}
-
That may all seem like giberish, but hopefully it’ll mean that someone else seeing the same problem might figure out what’s going on sooner! (That and I shouldn’t fall into this problem again any time soon now.)

RedLaser
Over the weekend I was sitting in a cafe with a friend of mine who works at a supermarket. He mentioned that he’d heard of a program on the iPhone which could read barcodes, RedLaser. I grabbed a copy, and we played around for a moment scanning the shopping we’d just bought.
Then sitting at home this morning, my eyes wandered to my DVD collection, and cogs began to whirr. A few moments later and I started the task of scanning each DVD, with the aim of e-mailing the list of results to myself, thus cataloguing my collection. Next I start on the CDs and books. So yeah, I had a nerdgasm, but only a little one.
I went on a trip to London last Monday. Taking my mum and sister out for an awesome journey around our nation’s capitol.
We began with some light brunch as Leicester Square, then onto the Tate Modern for the Pop Life exhibit. I think we all enjoyed the Andy Warhol element, but when the hard core pornography was cracked out, my mother needed to leave the room for a breath of fresh air!
The day ended with a little shopping along Oxford street before heading homeward bound just before rush hour.