-1

Hello I have a php code crawler to detect a website if it has a Asynchronous Google Code. here's the snippet to detect the the asynch google Code:

$async_ga_string = "ga.async";

if(!strpos($str, $async_ga_string))$async_ga = '';
            else $async_ga = 'yes';

It works fine. But what I exactly needed is for me to able to get the asynch UA code in this google code snippet:

     var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-2595901-1']);
  _gaq.push(['_trackPageview']);

I need to get the 'UA-2595901-1'

Ayush
  • 41,754
  • 51
  • 164
  • 239
jalf
  • 555
  • 4
  • 10
  • 20
  • really don't have idea what to do know. Still figuring out myself. Thank you for your quick response @xbonez – jalf Apr 16 '12 at 01:07

1 Answers1

0

It's an imperfect solution, but the Google Analytics Account ID is almost unique enough to find it using a simple Regular Expression:

<?php
$gaRegExp = '/UA-\d+-\d+/';

$testText = "var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-2595901-1']);
  _gaq.push(['_trackPageview']);"

preg_match( $gaRegExp , $testText , $matches )

// Returns, within the $matches variable, the following
// array (
//  0 => 'UA-2595901-1',
// )
Luke Stevenson
  • 10,357
  • 2
  • 26
  • 41