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 your Piwik URL and Site ID to grails-app/config/Config.groovy:
piwik.analytics.url = "http://example.com/piwik"
piwik.analytics.siteid = 1
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.
<html> <head> .. <piwik:trackPageview /> </head> <body> .. </body> </html>
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
or
piwik.analytics.enabled = false
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.
piwik.analytics.customTrackingCode = "_paq.push(['trackGoal', 1]); _paq.push(['enableLinkTracking']);"
Note that you have the trackPageview manually when using any custom tracking code.
piwik.analytics.customTrackingCode = [ [trackGoal: 1], "enableLinkTracking" ]
<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.
- 0.1
- First official release