The Mixpanel module is an API module, which provides (among other things) a PHP function mixpanel_track() and a Javascript function mixpanel.track() for sending events to Mixpanel.

If you want Mixpanel tracking but you aren't a developer and can't write your own Drupal module, you can also send custom events using Rules.

PHP

Most of the time, you'll want to send an event to Mixpanel in response to a hook.

For example, if you want to send an event every time a new node is created, you could implement hook_node_insert like this in your .module file:

/**
 * Implements hook_node_insert().
 */
function MYMODULE_node_insert($node) {
  mixpanel_track('node-created', array(
    'node-title' => $node->title,
    'node-id' => $node->nid,
    'node-type' => $node->type,
  );
}

... where you replace MYMODULE with the name of your module.

The properties that you pass will be merged with the default properties from mixpanel_get_defaults() which you can modify by implementing hook_mixpanel_defaults_alter().

See the full API documentation for mixpanel_track() in mixpanel.module and the hook documentation in the mixpanel.api.php file.

Full example

See the Mixpanel defaults module included with the main Mixpanel module for a full example of how to send events via PHP.

Javascript

Most of the time you'll want to send events to Mixpanel in response to DOM events.

For example, if you want to send an event when any the div's with the class "awesome" is clicked, you could create the following Javscript file in your module:

(function ($) {
  Drupal.behaviors.MYMODULE = {
    attach: function (context, settings) {
      $('div.awesome', context).click(function () {
        mixpanel.track('awesome-event', {property1: 'value1'});
      });
    }
  };
})(jQuery);

... where MYMODULE is the name of your module.

(NOTE: the above uses Drupal 7 behaviors, which is the recommended way to attach to events. See the Behaviors section in Managing JavasScript in Drupal 7 for more information.)

To load your Javascript file on every page, add it to your module's .info file, for example:

scripts[] = somescript.js

Click here to view the full Mixpanel Javascript API!