Piwik Plugin

  • Tags: web analytics
  • Latest: 0.1
  • Last Updated: 20 July 2013
  • Grails version: 2.0 > *
0 vote
Dependency:
compile ":piwik:0.1"

 Documentation  Source  Issues

Summary

A simple grails plugin to include piwik tracking code

Installation

grails install-plugin piwik-analytics

Description

Piwik plugin

This plugin can be used to integrate Piwik (http://piwik.org) open source web analytics in Grails application.

The plugin is written in Groovy/Grails without any dependencies on external libraries.

Current version

Current version is 0.1

Compatible with Piwik version 1.12

This version is developed and tested with Grails 2.1.1

Author

Email: be.mee@me.com

Usage

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.

<html>
    <head>
        ..
        <piwik:trackPageview />
    </head>
    <body>
        ..
    </body>
</html>

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

or

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],
    "enableLinkTracking"
]

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