Plugin Directory

Changeset 201101


Ignore:
Timestamp:
02/02/2010 03:46:56 PM (16 years ago)
Author:
ShaneF
Message:

updated documentation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • woopra/trunk/js/jquery.tracking.js

    r201072 r201101  
    1212*
    1313* Copyright (c) 2009 Pranshu Arya
    14 * Modifed by Shane <shane@bugssite.org> to work for the WordPress Woopra Plugin
     14* Modified by Shane <shane@bugssite.org> to work for the WordPress Woopra Plugin
    1515*
    16 * Version 1.1
     16* Version 1.2
    1717**
    1818* Licensed under the MIT license:
     
    7070         _load_woopra();
    7171    }
    72 
    73   /**
    74    * Tracks an event using the given parameters.
    75    *
    76    * The woopraEvent method takes as few or as many property pairs as you provide:
    77    * http://www.woopra.com/forums/topic/how-do-i-title-a-custom-event)
    78    *
    79    * Defaults for title, event_name, and skip_internal are specified at the bottom
    80    *
    81    *  title - name of custom event
    82    *  var1, var2, var3, ...
    83    *  event_name - name of the event you want to track
    84    *  skip_internal - optional boolean value. If true then internal links are not tracked.
    85    *
    86    */
    87   $.woopraEvent = function(title, woopra_options) {
     72   
     73    /**
     74     * Process a Woopra Event Manually
     75     */
     76    $.woopraEvent = function(title, woopra_options) {
    8877        if ( woopraTracker == 'undefined' ) {
    8978            debug('FATAL: woopraTracker is not defined'); // blocked by whatever
     
    9180            var w_event = new WoopraEvent(title);
    9281            // For each property pair passed to woopraEvent, add it to w_event
    93             $.each(woopra_options, function(i,val){
    94                 w_event.addProperty(i,val);
     82            $.each(woopra_options, function(i, val){
     83                w_event.addProperty(i, val);
    9584            });
    9685            w_event.fire();
     
    9887    };
    9988   
     89    /**
     90     * Track Event jQuery Hook
     91     *
     92     * Example:
     93     *
     94     *  Trigger event:  When user clicks on a link.
     95     *  Code:           jQuery("a").trackEvent({ title: 'Click on link', label: 'A element.' });
     96     *
     97     * This event is only fired by default, when the event is a 'click'. This can be
     98     * changed by passing a different 'event_name'.
     99     *
     100     * Example:
     101     * 
     102     *  Trigger event:  When user is over a link.   
     103     *  Code:           jQuery("a").trackEvent({ title: 'Hovering over event.', label: 'A element hover.', event_name: 'mouseover' });
     104     *
     105     */
    100106    $.fn.trackEvent = function(woopra_options) {
    101107       
    102         // Add event handler to all matching elements
    103         return this.each(function() {
     108        /**
     109         *
     110         */
     111        return this.each( function() {
    104112            var element = $(this);
    105113            var parent = $(element).parent();
     
    122130                // text, evaluate them if they are functions.
    123131                var options = {};
    124                 $.each(woopra_options, function(i,val){
    125                     options[i] = evaluate(element,val);
     132                $.each(woopra_options, function(i, val){
     133                    options[i] = evaluate(element, val);
    126134                }); 
    127135            }
     
    147155                    var title = evaluate($(parent).children().eq(index), woopra_settings.title);
    148156                    options = {}
    149                     $.each(woopra_options, function(i,val){
     157                    $.each(woopra_options, function(i, val){
    150158                        options[i] = evaluate($(parent).children().eq(index), val);
    151159                    });
     
    159167        });
    160168       
    161        
    162169        /**
    163          * Checks whether a setting value is a string or a function.
    164170         *
    165          * If second parameter is a string: returns the value of the second parameter.
    166          * If the second parameter is a function: passes the element to the function and returns function's return value.
    167171         */
    168172        function evaluate(element, text_or_function) {
     
    173177        };
    174178    };
    175 
     179   
    176180    /**
    177     * Prints to Firebug console, if available. To enable:
    178     *   $.fn.track.trackEvent.debug = true;
    179     */
     181     * Debug Information
     182     */
    180183    function debug(message) {
    181184        if (typeof console != 'undefined' && typeof console.debug != 'undefined' && $.fn.trackEvent.defaults.debug) {
     
    183186        }
    184187    };
    185 
     188   
    186189    /**
    187     * Default (overridable) settings.
    188     */
     190     * Default Settings
     191     */
    189192    $.fn.trackEvent.defaults = {
    190193        title           : function(element) { return (element[0].hostname == location.hostname) ? 'internal' : 'external'; },
     
    193196        debug           : true
    194197    };
     198   
    195199})(jQuery);
Note: See TracChangeset for help on using the changeset viewer.