A simple grails plugin to include piwik tracking code
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



A simple grails plugin to include piwik tracking code



grails install-plugin piwik-analytics


This plugin provides a simple taglib to embed Piwik Analytics pageview tracking to your Grails application.


Add Piwik URL and Site ID to Configuration

Add your Piwik URL and Site ID to grails-app/config/Config.groovy:

piwik.analytics.url = "http://example.com/piwik"
piwik.analytics.siteid = 1

Include Piwik Analytics tracking code to your page

Add the <piwik:trackPageview /> tag to your view(s). If you want all your pages to include the tracking code, just add it to the main.gsp layout. As recommended by Piwik place this as last script in the <head> section.

<piwik:trackPageview />

Sensible Defaults

The plugin uses sensible defaults. By default, when adding <piwik:trackPageview /> to your views/layouts, only running in production will output the tracking code. Thus not in development and test.

This behaviour can be overridden by explicitly enabling/disabling Piwik Analytics in Config.groovy.

piwik.analytics.enabled = true


piwik.analytics.enabled = false

Tracking Customizations

If you want to customize the tracking code you can either provide the customization in grails-app/config/Config.groovy or in the tag itself. The customization can be a String of javascript code or a smart List with tracking code. The examples below speak for themselves.

Simple String configuration in Config.groovy

piwik.analytics.customTrackingCode = "_paq.push(['trackGoal', 1]); _paq.push(['enableLinkTracking']);"

Note that you have the trackPageview manually when using any custom tracking code.

List configuration in Config.groovy

piwik.analytics.customTrackingCode = [
    [trackGoal: 1],

Custom code directly in tag

<piwik:trackPageview customTrackingCode="_paq.push(['trackGoal', 1]); _paq.push(['enableLinkTracking']);" />

Note that you can also provide a similar List to the tag itself as in the other example.

Version History

  • 0.1
    • First official release