The Crazy Egg tracking script provides a few utility functions that you can employ to help you implement custom tracking behaviors.
Utility Functions
window.CE_READY is now replaced with window.CE_API
As soon as Crazy Egg is initialized, it calls the Javascript function CE_API, if it has been defined. Like the above examples, you should define a function named CE_API and put your custom Crazy Egg code inside. This ensures that your code does not try to use the CE2 object before it has been defined, which would cause errors that would prevent your custom variables from being tracked.
(window.CE_API || (window.CE_API = [])).push(function(){ console.log('Crazy Egg tracking script loaded'); };
CE2.getBox(element)
element: A DOM element
Returns an object describing the size and absolute position of the element. Example:
> CE2.getBox(element); { 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
CE2.listen(bodyElement, 'mousemove', function (event) { console.log('mouse movement');});
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.
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 the element
y: The y-coordinate of the click, relative to the element
CE2.click(element, event)
element: Either a DOM element or a virtual element
event: A mouse event from the 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.)