Skip to content

BeeMee/grails-plugin-piwik-analytics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

grails-plugin-piwik-analytics

A simple grails plugin to include piwik tracking code

Summary

Installation

grails install-plugin piwik-analytics

Description

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

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

About

A simple grails plugin to include piwik tracking code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages