Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MINOR: fixing various merge conflicts
- Loading branch information
Showing
8 changed files
with
220 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Google Analytics Module | ||
|
||
## Features | ||
|
||
### Event Tracking API | ||
|
||
Included in the module is a simple jQuery plugin which wraps Google Analytics Event | ||
based tracking and provides several shortcuts to including event tracking in your | ||
project. | ||
|
||
To enable event tracking, first you will need to enable the Google Logger then include | ||
`GoogleLogger::set_event_tracking_enabled(true)` in your mysite/_config.php file: | ||
|
||
GoogleLogger::activate('UA-XXXX-XX'); | ||
GoogleLogger::set_event_tracking_enabled(true); | ||
|
||
After including the event tracking API you can call `analyticsTrackEvent(1)` from your | ||
own code whenever you need to track an interaction event. | ||
|
||
#### analyticsTrackEvent(1) | ||
|
||
`analyticsTrackEvent` takes an object with a number of properties. You can define | ||
which ever properties you need to, otherwise the plugin will revert to some common | ||
default values. Each of the provided properties in the object can either be a literal | ||
value or a function which returns a literal value. This allows you to build complex | ||
event labels and categories based on the entire DOM of a page and not just limited to | ||
a single event object. | ||
|
||
$(this).analyticsTrackEvent({ | ||
category: .. | ||
label: .. | ||
action: ... | ||
value: .. | ||
}) | ||
|
||
|
||
Property | Default Value | Optional? | ||
------------- | --------------- | ----- | ||
Category | window.location | No | ||
Action | 'click' | No | ||
Label | $(this).text() | No | ||
Value | NULL | Yes | ||
|
||
|
||
#### Examples | ||
|
||
Tracks any link with a class of *track*. Takes the default options of `analyticsTrackEvent(1)` | ||
as shown in the table above | ||
|
||
$("a.track").click(function() { | ||
$(this).analyticsTrackEvent(); | ||
}); | ||
|
||
Tracks users focusing into a given text box. Sends a custom label and action label. | ||
|
||
$("input.track").focus(function() { | ||
$(this).trackEvent({ | ||
label: 'Entered Text into box', | ||
action: 'focus' | ||
}); | ||
}); | ||
|
||
Tracks when a user leaves an input box, what was the value that they entered into | ||
the box. Demonstrates how you can use a function to return a dynamic value for any | ||
of the properties. | ||
|
||
$("input.track").blur(function() { | ||
$(this).trackEvent({ | ||
category: function(elem) { return $(elem).parents("form").attr("name"); }, | ||
label: function(elem) { return $(elem).val(); }, | ||
action: 'leave text field' | ||
}) | ||
}); | ||
|
||
## FAQ | ||
|
||
### I'm not seeing any event information | ||
|
||
Google takes up to 48 hours to process event tracking information in many cases, | ||
so you may have to wait several hours to see your results. | ||
|
||
If you still don't see any information appearing, try using the official | ||
`ga_debug.js` extension to Google Chrome. | ||
|
||
http://code.google.com/apis/analytics/docs/tracking/gaTrackingTroubleshooting.html#gaDebug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
;(function($) { | ||
/** | ||
* A simple helper function for wrapping Google Analytic event tracking | ||
* into sites through jQuery and HTML5 data attributes. | ||
* | ||
* See the provided documentation folder for instructions and examples | ||
* on how to add event tracking. | ||
*/ | ||
$.fn.analyticsTrackEvent = function(args) { | ||
_gaq = _gaq || []; | ||
|
||
/** | ||
* Evaluates an argument. If a non terminal (i.e a function) return | ||
* the result of that function. Otherwise returns the terminal value. | ||
*/ | ||
var e = function(f) { | ||
if($.isFunction(f)) return f(self); return f; | ||
}; | ||
|
||
var category, action, label, value, self = $(this[0]); | ||
|
||
var args = $.extend({ | ||
category: function(ele) { | ||
category = $(ele).data('category'); | ||
if(!category) category = window.location.toString(); | ||
|
||
return category; | ||
}, | ||
action: function(ele) { | ||
action = $(ele).data('action'); | ||
if(!action) action = 'click'; | ||
|
||
return action; | ||
}, | ||
label: function(ele) { | ||
// optional but recommened field | ||
label = $(ele).data('label'); | ||
if(!label) label = $(ele).text(); | ||
|
||
return label; | ||
}, | ||
value: function(ele) { | ||
return $(ele).data('value'); | ||
}, | ||
}, args); | ||
|
||
|
||
var track = ['_trackEvent', e(args.category), e(args.action)]; | ||
|
||
label = e(args.label); | ||
value = parseInt(e(args.value)); | ||
|
||
if(label) track.push(label); | ||
if(value) track.push(value); | ||
|
||
try { | ||
_gaq.push(track); | ||
} catch(err) { | ||
if(window.console != undefined) { | ||
window.console.log(err); | ||
} | ||
} | ||
} | ||
})(jQuery); |
Oops, something went wrong.