Grails Google Analytics Plugin
Dependency :
compile ":google-analytics:2.0"
Summary
Include google analyics script
Installation
grails install-plugin google-analytics
Description
Introduction
This plugin provides a simple taglib to embed Google Analytics pageview tracking to your Grails application.Usage
Add Web Property ID to Configuration
Add your Web Property ID to grails-app/config/Config.groovy:google.analytics.webPropertyID = "UA-xxxxxx-x"Include Google Analytics tracking code to your page
Add the <ga: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 Google place this as last script in the <head> section.<html>
<head>
..
<ga:trackPageview />
</head>
<body>
..
</body>
</html>Sensible Defaults
The plugin uses sensible defaults. By default, when adding <ga: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 Google Analytics in Config.groovy.google.analytics.enabled = truegoogle.analytics.enabled = falseAsynchronous vs. Traditional tracking code
Since version 1.0 of this plugin asynchronous tracking code is used by default when using <ga:trackPageview />. If you want to use the old traditional tracking code code instead add this to grails-app/config/Config.groovy:google.analytics.traditional = true<html>
<head>
..
</head>
<body>
..
<ga:trackPageview />
</body>
</html>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
google.analytics.customTrackingCode = "_gaq.push(['_setDetectFlash', false]); _gaq.push(['_trackPageview']); _gaq.push(['_trackPageLoadTime']);"List configuration in Config.groovy
google.analytics.customTrackingCode = [
[_setDetectFlash: false],
[_setCampaignCookieTimeout: 31536000000],
"_trackPageview",
"_trackPageLoadTime"
]Custom code directly in tag
<ga:trackPageview customTrackingCode="_gaq.push(['_setDetectFlash', false]); _gaq.push(['_trackPageview']); _gaq.push(['_trackPageLoadTime']);" />Version History
- 2.0
- Remove log.warn of deprecated ConfigurationHolder
- Upgraded to Grails 2.0.x
- 1.0
- Added support for customized tracking code
- Asynch tracking code is now used instead of traditional code
- Upgraded to Grails 1.3.x
- 0.3
- Now supports Grails version 1.1.1 > *
- 0.2
- Added Asynchronous Tracking support
- 0.1
- First official release