Skip to content
This repository has been archived by the owner. It is now read-only.
KISSmetrics Grails Plugin
Groovy Shell Gosu
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

KISSmetrics Grails Plugin

Build Status


The KISSmetrics Plugin allows you to integrate KISSmetrics in your Grails application.

It provides the following Grails artefacts:


Declare the plugin dependency in the BuildConfig.groovvy file, as shown here:

grails.project.dependency.resolution = {
		inherits("global") { }
		log "info"
		repositories {
				//your repositories
		dependencies {
				//your dependencies
		plugins {
				//here go your plugin dependencies
				runtime ':kissmetrics:0.2.0'


Create a KISSmetrics account, in order to get your own apiKey.

Add your KISSmetrics site apiKey to your grails-app/conf/Config.groovy:

grails.plugin.kissmetrics.apiKey = {API_KEY}

By default the KISSmetrics will only be enabled for Production environments. If you need it to be enabled for other environments, make sure that it is explicitly enabled in your configs.

grails.plugin.kissmetrics.enabled = true



You can inject kissmetricsService in any of your Grails artefacts (controllers, services...) in order to call KISSmetrics APIs.

def kissmetricsService

// Record an event
kissmetricsService.recordEvent('', 'Signed up')

// Record an event and set properties
kissmetricsService.recordEvent('', 'Signed up', [plan: 'Pro', amount: 99.95])

// Record a past event and set properties
kissmetricsService.recordEvent('', 'Signed up', [plan: 'Pro', amount: 99.95], (new Date() - 10).time)

// Set properties
kissmetricsService.setProperties('', [gender: 'male'])

// Alias identity
kissmetricsService.alias('', 'bob')

An async version is available for each methods (to delegate call to a thread pool and execute it asynchronously) for better performances.

// Alias identity
kissmetricsService.aliasAsync('bob', '')

// Record an event
kissmetricsService.recordEventAsync('', 'Signed up')

// Set properties
kissmetricsService.setPropertiesAsync('', [gender: 'male'])

HTTP client is based on HTTPBuilder. You might want to surround service method calls in try/catch blocks to catch HttpResponseException.


try {
    // Record an event
    kissmetricsService.recordEvent('', 'Signed up')
} catch (HttpResponseException exception) {
    // default failure handler throws an exception:
    println "Unexpected response error: ${exception.statusCode}"


To use KISSmetrics Javascript Library, you must first initialize it in page header (most probably in you layout GSP).

JS Lib initialization

<!DOCTYPE html>

Identification and event recording

Once initialized, you can use KISSmetrics Javascript Library in your GSP views.

<!-- Identity current user -->
<kissmetrics:identify id=""/>

<!-- Record an event -->
<kissmetrics:record event="Signed Up"/>

<!-- Record an event and set properties -->
<kissmetrics:record event="Signed Up" properties="${[plan: 'Pro', amount: 99.95]}"/>

<!-- Set properties -->
<kissmetrics:set properties="${[gender: 'male']}"/>

<!-- Alias identity -->
<kissmetrics:alias id="" to="bob"/>

It will generate the corresponding javascript code that will be automatically deferred to page footer thanks to Grails Resources framework.

Latest releases

  • 2013-01-09 V0.2.0 : minor bug fix in taglib (check apiKey) + Grails upgraded to 2.2.0
  • 2012-11-15 V0.1.2 : minor bug fix in setPropertiesAsync (it was not executed asynchronously)
  • 2012-11-13 V0.1.1 : minor bug fix in config loader
  • 2012-11-12 V0.1.0 : initial release


To report any bug, please use the project Issues section on GitHub.

Beta status

This is a beta release.

You can’t perform that action at this time.