trackData.js 2.1 KB

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