trackData.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. (function() {
  2. String.prototype.trim=function(){
  3. return this.replace(/(^\s*)|(\s*$)/g, "");
  4. }
  5. var _tkd = "_tkd";
  6. function Tracker() {
  7. var oThis = this;
  8. oThis.p = {
  9. push: function () {
  10. oThis.handleEvent.apply(oThis, arguments);
  11. }
  12. };
  13. oThis.handle();
  14. }
  15. Tracker.prototype = {
  16. handle:function (){
  17. var oThis = this;
  18. try{
  19. _tracker_ : {
  20. var tkd = window[_tkd],isArray = false;
  21. if(tkd) {
  22. isArray = Object.prototype["toString"].call(Object(tkd)) == "[object Array]";
  23. if(!isArray){
  24. break _tracker_;
  25. }
  26. //handle event
  27. for (var x = 0; x < tkd.length; x++) {
  28. oThis.handleEvent(tkd[x]);
  29. }
  30. }
  31. window[_tkd] = oThis.p;
  32. }
  33. }catch(exception){
  34. }
  35. },
  36. handleEvent : function(args){
  37. switch (args[0]) {
  38. case "_trackSearch":
  39. send("search", args[1]);
  40. break;
  41. case "_trackPageView":
  42. send("pageView", args[1]);
  43. break;
  44. case "_trackEvent":
  45. send("event", args[1]);
  46. break;
  47. }
  48. }
  49. }
  50. //send get request
  51. function send(logType, params) {
  52. var win = window;
  53. var n = '_job_img_' + (+new Date()) + '.r' + Math.floor(Math.random() * 1000),
  54. img = win[n] = new Image();
  55. img.onload = img.onerror = function () {
  56. win[n] = null;
  57. };
  58. var q = "https:" == document.location.protocol ? "https:" : "http:";
  59. img.src = q + params + "&vt=" + new Date().getTime() + "&logType=" + logType;
  60. }
  61. new Tracker;
  62. })();