No commit activity in last 3 years
No release in over 3 years
Adds Google Analytics to Blacklight Rails application including event tracking.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

Blacklight Google Analytics

A gem plugin which adds support for Google Analytics and event tracking to a Blacklight Rails application.

Installation

  1. Install Blacklight using the Quickstart guide.
  2. Add gem 'blacklight_google_analytics' to your Gemfile
  3. Run the generator: rails g blacklight_google_analytics. This adds an initializer (see next step) and adds a couple lines to app/assets/javascripts/application.js.
  4. Edit config/initializers/blacklight_google_analytics.rb to include your own Google Web id. You will need a Google Analytics account and profile. You will not need to copy in the async snippet. You will need to verify your profile.

Usage

Google Analytics tracking code is only turned on in production. Both page tracking and Blacklight-specific event tracking is turned on.

In development Google Analytics tracking is turned off. Tracking parameters are sent to the browser's console to allow you to see what parameters will be sent to Google Analytics for various actions.

Here's an example of event tracking. This is the output to the browser console when clicking on the Format facet, selecting the "Book" facet value, and then removing it:

["facets", "collapse_expand", "Format"]
["facets", "Format", "Book"]
["facets", "Format", "[remove]"]

These parameters are the category, action, and label according to the Google Analytics event tracking documentation. This event tracking information shows up in Google Analytics under Content > Events.

Customizing Blacklight for event tracking

You can add other links (e.g. a elements) to the page and they will be tracked automatically. If you give your link an id attribute, that will be used for the category. Otherwise, the id of the first parent element with an id attribute will be used as the category.

You may also add your own jQuery click handlers to add more event tracking. Look at the current handlers to see how to set up a tracking event and enable console.log in development.

Author

Jason Ronallo

Based on code from Brian Cray.

Copyright

Copyright © 2012 North Carolina State University. See MIT-LICENSE for details.