XPages Web Analytics custom control on OpenNTF

What a great weekend for open source contributions from me! 🙂 Yesterday I created the XPages SEO custom control – and today I have created a new XPages custom control for the OpenNTF development contest called XPages Web Analytics custom control: the custom control makes it easy to add web analytics to your XPages web site.

In the first release the custom control supports Google Analytics and Woopra Web Analytics.

In order to use the custom control you download it from OpenNTF, unzip the downloaded file and open the included Notes database. In the database you will find a custom control called “WebAnalytics” that you can include in your own XPages application. Once included you just drag the custom control to your XPage and add the custom properties for the specific web analytics providers that you would like to use.

XPages SEO custom control on OpenNTF

I have contributed to the OpenNTF development contest by creating an open source XPages Custom Control for Search Engine Optimization (SEO). The custom control makes it easy to add the following search engine friendly tags to your XPages web site:

  • page title
  • meta description
  • meta robots
  • meta keywords

With these SEO tags bundled in a custom control it also increases your chances of remembering to add these tags to your XPages web pages 🙂

Installation is easy:
Just download the SEO custom control, unzip the downloaded file and open the included Notes database. In the database you will find a custom control called “SEO” that you can include in your own XPages application. Once included you just drag the custom control to your XPage and add the custom properties for the specific XPage (either as static or computed values).

Controlling the HTTP response status code in XPages

This is a follow-up to my post on how to create custom 404 and error pages in XPages.

A very useful improvement to catching controlled errors such as “page not found” errors is to send the related HTTP status code in the response. So for “page not found” errors the HTTP response code 404 should be sent. This helps search engine crawlers understand that the page is not available whereby the search index can be updated accordingly.

The HTTP status code can be controlled with the facesContext response object by using setStatus. The following code example will generate a HTTP status code of 404 when added to the afterRenderResponse event of an error message XPage. The code example assumes that the source XPage sets the requestScope statusCode variable to “404” if the source XPage fails to find a document:

try {
	// The external context gives access to the servlet environment
	var exCon = facesContext.getExternalContext();

	// The servlet's response, check the J2EE documentation what you can do
	var response = exCon.getResponse();

	// Return HTTP status code 404 if necessary
	if (requestScope.statusCode = "404") {
		response.setStatus(404);
	}

	facesContext.responseComplete();
} catch(e) {
	_dump(e);
}