Universal Analytics Events and Floatbox

Page: 1

Author Post
Member
Registered: Jan 2015
Posts: 2
I have just implemented Google's Universal Analytics on my site and have been looking at adding event tracking to links on pages.

Typically onClick tags are added to the links such as this

onClick="ga('send', 'event', { eventCategory: 'exit link', eventAction: 'floatbox', eventLabel: 'Cave registry view', eventValue: 1});"

I understand that Floatbox is already using the onClick event so this is not passing through the event to Analytics.

Is there a workaround for this?

A page where I was testing the implementation
Administrator
Registered: Aug 2008
Posts: 3382
A couple of ways to skin this cat:

You could use one of the API callbacks such as afterBoxStart:
data-fb-options="afterBoxStart:`ga('send', 'event', { eventCategory: 'exit link', eventAction: 'floatbox', eventLabel: 'Cave registry view', eventValue: 1 });`"
(note the careful use of back-quotes, double-quotes and single-quotes in that example)

Also, while it's true there can be only one 'onclick' action assigned (DOM0 event), you can have an infinite number of 'click' actions (DOM2 events). You could use the already-present Floatbox library functions or another library such as jquery to assign these.
In Floatbox-ese, we could say (in a script):
fb.addEvent( '#theLinksID', 'click', function () {
ga( 'send', 'event', { eventCategory: 'exit link', eventAction: 'floatbox', eventLabel: 'Cave registry view', eventValue: 1 } );
} );
Member
Registered: Jan 2015
Posts: 2
Many thanks for such a speedy reply.

The first option has worked just great in this case.

Page: 1