title: Detect Google Analytics coded in PHP
body: <p>Oright Guys, </p>
  
  <p>Im looking for a way in PHP to detect the presence of Google Analytics within the source code of a page, retreiveing the page source code via: file_get_contents($url) </p>
  
  <p>I knew analytic code used on the page should be in the format UA-xxxxxxxx-x</p>
  
  <p>so far ive tried:</p>
  
  <pre><code>return preg_match("/^ua-\d{4,9}-\d{1,4}$/i", strval($source)) ? true : false;
  
  if(preg_match("/^ua-\d{4,9}-\d{1,4}$/", $source)){
  
  if(strpos($source, "setAccount','UA-")!=''){
  
  if(strpos($source, 'urchin.js')!=''){
  </code></pre>
  
  <p>not the best way to do it, each time it returns false.</p>
  
  <p>any help would be great..</p>
  
  <p>[[ <strong>UPDATE</strong> ]]
  Ok so Ive messed around with preg_match a lot,(very frustrating) and after trying a few things the only thing Ive found which will match is </p>
  
  <pre><code>if ( preg_match("/\bUA-\b/i", $source) ){
      echo "A match was found.";
  } else {
      echo "A match was not found.";
  }
  </code></pre>
  
  <p>this will match the UA- within the Google Analytics code. 
  but in order to match better, 
  I'm thinking it will need a few things added to the expression.</p>
  
  <p>Whats really needed is to match the first section UA- then match a range of numbers
  ie: UA-{range of numbers like 32692708}-{then just 1 number}</p>
  
  <p>if someone can show me a preview of the expression needed that would be great.. :)</p>