public function run()
 {
     $kms = 0;
     $kmq_identify = 0;
     $kmq_other = 0;
     foreach (ScriptHelper::findScripts($this->url) as $script) {
         preg_match_all("/_kmq\\.push\\(.*\\)/", $script, $matches);
         foreach ($matches[0] as $match) {
             if (strstr($match, "identify") !== FALSE) {
                 $kmq_identify++;
             } else {
                 $kmq_other++;
             }
         }
         $kms += preg_match_all("/_kms\\('.*'\\)/", $script);
     }
     switch ($kms) {
         case 0:
             $this->addResult("WARN", "No Kissmetrics tracking installed (No call to _kms found)");
             return $this->result;
         case 2:
             $this->addResult("PASS", "Kissmetrics tracking installed correctly");
             break;
         default:
             $this->addResult("WARN", "Kissmetrics tracking detected, but appears to be improperly installed (There should only be two calls to _kms())");
             break;
     }
     if ($kmq_identify === 0) {
         $this->addResult("WARN", "Kissmetrics has not been set up to identify users (No identify calls found)");
     } else {
         $this->addResult("PASS", "Kissmetrics is set up to identify users in {$kmq_identify} ways");
     }
     if ($kmq_other === 0) {
         $this->addResult("WARN", "No other events appear to be tracked with Kissmetrics");
     } else {
         $this->addResult("PASS", "Kissmetrics is set up to track {$kmq_other} other events");
     }
     return $this->result;
 }
 public function run()
 {
     $ga_setAccount = 0;
     $ga_account = "";
     $ga_trackPageview = 0;
     $ga_other = 0;
     foreach (ScriptHelper::findScripts($this->url) as $script) {
         preg_match_all("/_gaq\\.push\\(.*\\)/", $script, $matches);
         foreach ($matches[0] as $match) {
             if (strstr($match, "_setAccount") !== FALSE) {
                 $ga_setAccount++;
                 $ga_account = substr($match, -16, 13);
             } else {
                 if (strstr($match, "_trackPageview") !== FALSE) {
                     $ga_trackPageview++;
                 } else {
                     $ga_other++;
                 }
             }
         }
         preg_match_all("/ga\\(.*\\)/", $script, $uamatches);
         foreach ($uamatches[0] as $match) {
             if (strstr($match, "'create'") !== FALSE) {
                 $ga_setAccount++;
                 $ga_account = substr($match, strpos($match, 'UA-'), 13);
             } else {
                 if (strstr($match, "'pageview'") !== FALSE) {
                     $ga_trackPageview++;
                 } else {
                     $ga_other++;
                 }
             }
         }
     }
     switch ($ga_setAccount) {
         case 0:
             $this->addResult("FAIL", "No Google Analytics installed (No call to _setAccount found)");
             return $this->result;
         case 1:
             if (count($matches[0]) > 0) {
                 $this->addResult("WARN", "Legacy Google Analytics tracking installed with tracking code {$ga_account} (Consider upgrading to Universal Analytics)");
             } else {
                 $this->addResult("PASS", "Google Analytics installed with tracking code {$ga_account}");
             }
             break;
         default:
             $this->addResult("WARN", "Multiple Google Analytics installations detected");
             break;
     }
     switch ($ga_trackPageview) {
         case 0:
             $this->addResult("WARN", "Google Analytics is not tracking page views");
             break;
         case 1:
             $this->addResult("PASS", "Google Analytics is set up to track page views");
             break;
         default:
             $this->addResult("WARN", "Google Analytics appears to be tracking page views multiple times.");
             break;
     }
     if ($ga_other === 0) {
         $this->addResult("WARN", "No other events appear to be tracked with Google Analytics");
     } else {
         $this->addResult("PASS", "Google Analytics is set up to track {$ga_other} other events");
     }
     return $this->result;
 }