/
jquery.analytics.js
49 lines (41 loc) · 1.12 KB
/
jquery.analytics.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* Panmind Analytics JS API
*
* TODO: Documentation
*/
(function ($) {
$.pmTrackAjaxView = function () {
if (typeof (_gaq) == 'undefined') return;
try {
_gaq.push (['_trackPageview', $.location.getPathForTracking ()]);
} catch (e) { }
};
$.pmTrackEvent = function (category, action) {
if (typeof (_gaq) != 'undefined')
try {
_gaq.push (['_trackEvent', category, action]);
} catch (e) { }
};
var trackClick = function (elem, fn) {
if (typeof (_gaq) != 'undefined')
$(elem).click (function () {
try { fn.apply (this); } catch (e) { }
});
return elem;
};
$.fn.pmTrackPageView = function () {
return trackClick (this, function () {
_gaq.push (['_trackPageview', $(this).attr ('href')]);
});
};
$.fn.pmTrackDownload = function () {
return trackClick (this, function () {
_gaq.push (['_trackEvent', 'download', $(this).attr ('href')]);
});
};
$.fn.pmTrackOutboundLink = function () {
return trackClick (this, function () {
_gaq.push (['_trackEvent', 'outbound', $(this).attr ('href')]);
});
};
}) (jQuery);