janalytics.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2008 Massimiliano Balestrieri
  3. *
  4. * $Date: 2009/10/01 18:09:25 $
  5. * $Rev: 53 $
  6. * @requires jQuery v1.2.6
  7. *
  8. * Copyright (c) 2008 Massimiliano Balestrieri
  9. * Examples and docs at: http://maxb.net/blog/
  10. * Licensed GPL licenses:
  11. * http://www.gnu.org/licenses/gpl.html
  12. *
  13. * MODIFIED
  14. * 04/03/2008
  15. */
  16. (function() {
  17. var _gaJsHost = (("https:" == document.location.protocol) ? "https://ssl.": "http://www.");
  18. var _url = _gaJsHost + "google-analytics.com/ga.js";
  19. jQuery.getScript(_url);
  20. })();
  21. (function($){
  22. function janalytics(){
  23. var _that = this;
  24. var _analytics = _that.attr("class").split(" ").shift();
  25. //console.log(_analytics);
  26. var _metadata = $.metadata;
  27. var _host = false;
  28. var _debug = false;
  29. var _last = false;
  30. if(_metadata){
  31. _m1 = _that.metadata();
  32. if(_m1.host)
  33. _host = _m1.host;
  34. if(_m1.debug)
  35. _debug = _m1.debug;
  36. }
  37. //alert(_debug);
  38. if (_host && location.toString().indexOf(_host) === -1){
  39. return;
  40. }
  41. if (_analytics) {
  42. var _i = false;
  43. var _c = function() {
  44. //alert(_gat);
  45. if(_debug)
  46. alert("tracking");
  47. var pageTracker = _gat._getTracker(_analytics);
  48. pageTracker._trackPageview();
  49. $("a.tracking").each(function(){
  50. if (_metadata){
  51. var _options = jQuery(this).metadata();
  52. }else{
  53. var _options = {label: this.href}; //console.log(_options);
  54. }
  55. $(this).click(function() {
  56. //evito che vengano mandati due click consecutivi.
  57. //history da questo problema. ad ogni click ho due invocazioni.
  58. if(_last != _options.label){
  59. _last = _options.label;
  60. //console.log(this);
  61. if(_debug)
  62. alert("tracking");
  63. if (_options.label) {
  64. pageTracker._trackPageview(_options.label);
  65. }
  66. }
  67. });
  68. });
  69. };
  70. var _m = function(){
  71. if(_gat) {
  72. clearInterval(_i);
  73. _c();
  74. }
  75. };
  76. _i = setInterval(_m, 300);
  77. }
  78. }
  79. $.fn.janalytics = janalytics;
  80. })(jQuery);
  81. jQuery(window).bind("load",function() {
  82. jQuery("#analytics").janalytics();
  83. });