gfranko / jquery.tocify.js

A jQuery Table of Contents plugin that can be themed with Twitter Bootstrap or jQueryUI.
http://gregfranko.com/jquery.tocify.js/
MIT License
928 stars 216 forks source link

Google Analytics Tracking on a Tocify item click #52

Closed peter-brady closed 10 years ago

peter-brady commented 10 years ago

Hi,

I've been trying to get each click in the Tocify TOC to register as an event in Google Analytics but to no avail.

I've tried adding:

_gaq.push(['_setAllowAnchor', true]);

to the GA script block but it doesn't seem to make any difference.

I wonder if anybody knows how to do this.

Many thanks, Pete.

gfranko commented 10 years ago

Each TOC item has a tocify-item classname associated with it, so you could just use the following jQuery:

$('.tocify-item').on('click', function() {
  _gaq.push(['_setAllowAnchor', true]);
});
peter-brady commented 10 years ago

Hi Greg,

Great. I'll give that a go.

Many thanks, Peter.