Guest User

Untitled

a guest
Nov 17th, 2018
1,259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Arrowtracker
  3.  *
  4.  * @copyright (c) 2010 ArrowMedia <arwm.ru>
  5.  * @version   0.6 <06.10.2010>
  6.  */
  7. var arrowtracker = {
  8.         gc:            null,
  9.         ga_source:     null,
  10.         ga_campaign:   null,
  11.         ga_medium:     null,
  12.         ga_term:       null,
  13.         ga_content:    null,
  14.         ga_gclid:      null,      
  15.         referrers:     [],          // Custom referers
  16.         sources:       [],        // Custom sources
  17.         token:         null,
  18.         error:         false,
  19.         useInterval:   false,
  20.         intervalTime:  100,
  21.         intervalObj:   null,
  22.         language:      'ru',
  23.         onload:        null,
  24.         translations: {
  25.                 ru: {
  26.                         YD: 'Вы пришли к нам из Яндекс.Директа.',
  27.                         YO: 'Вы пришли к нам с Яндекса.',
  28.                         GA: 'Вы пришли к нам по объявлению в Google AdWords.',
  29.                         GO: 'Вы пришли к нам с Гугла.',
  30.                         MO: 'Вы пришли к нам с Mail.ru.',
  31.                         RO: 'Вы пришли к нам с Рамблера.',
  32.                         BG: 'Вы пришли к нам из контекстной сети Бегуна.',
  33.                         BN: 'Вы пришли к нам из контекстной сети Бегуна.',
  34.                         OO: 'Вы пришли к нам с поисковика.',
  35.                         OT: 'Вы пришли к нам по ссылке с другого сайта.',
  36.                         TI: 'Вы набрали адрес нашего сайта прямо в адресной строке браузера или пришли с закладок.'
  37.                 }
  38.         },        
  39.         /**
  40.          * Initialization
  41.          *
  42.          * @return void
  43.          */
  44.         init: function(){
  45.                 if (true == this.useInterval) {
  46.                         /**
  47.                          * @todo Replace object name
  48.                          */
  49.                         this.intervalObj = setInterval("arrowtracker.process()", this.intervalTime);
  50.                         return;
  51.                 }                
  52.                 this.process();
  53.         },        
  54.         /**
  55.          * Parse GA cookies
  56.          *
  57.          * @return void
  58.          */
  59.         process: function() {
  60.                 if (null != this.intervalObj) {
  61.                         clearInterval(this.intervalObj);
  62.                 }                
  63.                 var z = this._uGC(document.cookie, '__utmz=', ';');
  64.                 this.ga_gclid    = this._uGC(z, 'utmgclid=', '|');
  65.                 this.ga_source   = this._uGC(z, 'utmcsr=', '|');
  66.                 this.ga_campaign = this._uGC(z, 'utmccn=', '|');
  67.                 this.ga_medium   = this._uGC(z, 'utmcmd=', '|');
  68.                 this.ga_term     = this._uGC(z, 'utmctr=', '|');
  69.                 this.ga_content  = this._uGC(z, 'utmcct=', '|');                
  70.                 if (this.ga_gclid != "-") {
  71.                         this.ga_source = 'google';
  72.                         this.ga_medium = 'cpc';
  73.                 }                
  74.                 // Custom sources
  75.                 for(i=0;i<this.sources.length;++i) {
  76.                         if (this.sources[i][0] == this.ga_source) {
  77.                                 this.setToken(this.sources[i][1]);
  78.                                 this.addTranslate(this.sources[i][1],
  79.                                 this.sources[i][2]);
  80.                                 this.log(this.getTranslate());
  81.                                 return;
  82.                         }
  83.                 }                
  84.                 switch (this.ga_medium) {
  85.                         case 'organic':
  86.                                 switch (this.ga_source) {
  87.                                         case 'google':
  88.                                         case 'google.ru':
  89.                                         case 'google.com':
  90.                                                 this.setToken('GO');
  91.                                                 break;
  92.                                         case 'yandex':
  93.                                         case 'yandex.ru':
  94.                                                 this.setToken('YO');
  95.                                                 break;
  96.                                         case 'rambler':
  97.                                         case 'rambler.ru':
  98.                                                 this.setToken('RO');
  99.                                                 break;
  100.                                         case 'mail':
  101.                                         case 'mail.ru':
  102.                                                 this.setToken('MO');
  103.                                                 break;
  104.                                         default:
  105.                                                 this.setToken('OO');
  106.                                                 break;
  107.                                 }
  108.                                 break;
  109.                         case 'cpc':
  110.                                 switch (this.ga_source) {
  111.                                         case 'YD':
  112.                                                 this.setToken('YD');
  113.                                                 break;
  114.                                         case 'GA':
  115.                                         case 'GD':
  116.                                         case 'GС':
  117.                                         case 'google':
  118.                                                 this.setToken('GA');
  119.                                                 break;
  120.                                         case 'begun':
  121.                                         case 'BG':
  122.                                                 this.setToken('BG');
  123.                                         case 'BN':
  124.                                                 this.setToken('BN');
  125.                                                 break;
  126.                                 }
  127.                                 break;
  128.                         case 'referral':
  129.                                 for(i=0;i<this.referrers.length;++i) {
  130.                                         if (this.referrers[i][0] == this.ga_source) {
  131.                                                 this.setToken(this.referrers[i][1]);
  132.                                                 this.addTranslate(this.referrers[i][1],
  133.                                                 this.referrers[i][2]);
  134.                                         }
  135.                                 }                                
  136.                                 if (!this.hasToken()) {
  137.                                         this.setToken('OT');
  138.                                 }
  139.                                 break;
  140.                         case '(not set)':
  141.                                 if ("-" != this.ga_gclid) {
  142.                                         this.token = 'GA';
  143.                                 }
  144.                                 break;
  145.                         case '(none)':
  146.                                 this.setToken('TI');
  147.                                 break;
  148.                         default:
  149.                                 this.logError("ga_medium");
  150.                                 break;
  151.                 }                
  152.                 this.log(this.getTranslate());                
  153.                 if (this.onload)
  154.                         this.onload(this.getToken(), this.getTranslate());
  155.         },        
  156.         /*
  157.          * TOKEN
  158.          */
  159.         getToken: function() {
  160.                 return this.token;
  161.         },        
  162.         setToken: function(token) {
  163.                 this.token = token;
  164.                 return this;
  165.         },        
  166.         hasToken: function() {
  167.                 return (null == this.token) ? false : true;
  168.         },        
  169.         /*
  170.          * LANGUAGE
  171.          */
  172.         getLanguage: function() {
  173.                 return this.language;
  174.         },        
  175.         setLanguage: function(lang) {
  176.                 this.language = lang;
  177.                 return this;
  178.         },        
  179.         /*
  180.          * TRANSLATE
  181.          */
  182.         addTranslate: function(code, translate) {
  183.                 this.translations.ru[code] = translate;                
  184.                 return this;
  185.         },        
  186.         getTranslate: function() {
  187.                 if (this.hasToken() && !this.hasError()) {
  188.                         return this.translations[this.language][this.getToken()];
  189.                 }                
  190.                 return null;
  191.         },        
  192.         /*
  193.          * ERRORS & LOGS
  194.          */
  195.         log: function(string) {
  196.                 try{
  197.                         console.log(string);
  198.                 }catch(e){}                
  199.                 return this;
  200.         },        
  201.         logError: function(string) {
  202.                 this.error = true;                
  203.                 return this.log(string);
  204.         },        
  205.         hasError: function() {
  206.                 return this.error;
  207.         },        
  208.         /*
  209.          * PARSER
  210.          */
  211.         _uGC:function(l,n,s){
  212.                 if (!l || l=="" || !n || n=="" || !s || s=="") return "-";
  213.                 var i,i2,i3,c="-";
  214.                 i=l.indexOf(n);
  215.                  i3=n.indexOf("=")+1;
  216.                 if (i > -1) {
  217.                 i2=l.indexOf(s,i); if (i2 < 0) { i2=l.length; }
  218.                 c=l.substring((i+i3),i2);
  219.                 }
  220.                 return c;
  221.         }
  222. };
Add Comment
Please, Sign In to add comment