Crazy Egg allows you to customize its tracking behavior in a wide variety of ways using Javascript:
The CE2.click function can be used to send click data to Crazy Egg. This function can be called in a number of ways:
CE2.click(element, x, y)
element: Either a DOM element or a virtual element
x: The x-coordinate of the click, relative to element
y: The y-coordinate of the click, relative to element
CE2.click(element, event)
element: Either a DOM element or a virtual element
event: A mouse event from element or one of its sub-elements; the x
and y coordinates of the click will be derived from the event
object
CE2.click(element)
element: Either a DOM element or a virtual element
(The click will be placed in the center of the element.)
A virtual element is a rectangular region of the page that you define and track as if it were a regular page element.
Virtual elements might be employed to improve the tracking of clicks inside of an interactive Flash clip or <canvas> element. Suppose you had a Flash video clip with play, pause, and rewind buttons. Normally all clicks on that clip would just be identified the same way, no distinction would be made between clicks on the different buttons it contained. If you were to set up an event handler so that, for instance, a click on the play button resulted in a call to CE2.click, Crazy Egg could track clicks on that button as if it were a normal HTML element. Click data specifically for the video control buttons would appear in the overlay and list views.
Virtual element can be defined by passing a Javascript object as the first argument to CE2.click.
var myElement = { // required fields left: 100, top: 120, width: 550, height: 400, // optional fields id: "unique_id", ceid: "unique_id", name: "human-readable name", data: "arbitrary string", parentID: "id_of_containing_element" }
Caution: If you provide a parentID, the top and left properties must be relative to the position of the parent
You can tell Crazy Egg to ignore certain elements with the CSS class -ce-ignore. Simply assign this class to an element and our script will not track clicks on it or its contents:
<p> Neither <em>this</em> paragraph, nor its <a href="a">child</a> <a href="b">elements</a>, will be <a href="c">tracked</a>. </p>
If your element already has a class attribute, you can just add -ce-ignore as an additional CSS class:
<div> ... </div>
You can also mark elements as ignored via Javascript:
function CE_READY() { var el = document.getElementById('ignore-me'); CE2.ignore(el); }
Caution: There is a risk of creating duplicate click data when you are implementing your own tracking behavior. Two clicks could be tracked for each real click from a visitor: one by your custom code and another by the default Crazy Egg click handler.
The Crazy Egg tracking script provides a few utility functions that you can employ to help you implement custom tracking behaviors.
CE2.getBox(element)
element: A DOM element
Returns an object describing the size and absolute position of
element. Example:
{left: 353, top: 1114, width: 426, height: 36}
CE2.listen(target, event, function)
target: A DOM element
event: Name of the event to listen for, e.g. "click", "keyup",
"load", etc.
function: The function to call when the event occurs
This is a very simple method of registering event handlers. Unlike a full-featured Javascript framework, this function passes only native event objects to the hander. Do not expect your event handlers to receive wrapped, normalized event objects. Use a full-featured Javascript framework if you require that feature. This function should suffice, however, if all you want to do is pass the event object to CE2.click.