function percent_mobile_track($site_id, $url = "")
{
    global $percent_mobile_u, $percent_mobile_v;
    if ($url == "") {
        $url = percent_mobile_self_url();
    }
    //construct the image URL, all values are submitted via URL parameters, urls are urlencoded
    //if iphone submit the image via a dynamic image and determine if we got an 3gs with a fast performance test that consumes 20ms
    if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/\\(iPhone/", $_SERVER['HTTP_USER_AGENT'])) {
        $image_url = (isset($_SERVER['HTTPS']) && $_SERVER["HTTPS"] == "on" ? "https" : "http") . "://tracking.percentmobile.com/pixel/" . $site_id . "/" . rand(0, 0xffff) . ".gif?v=" . PERCENT_MOBILE_VERSION . "&us=" . $percent_mobile_u . "&vi=" . $percent_mobile_v . "&url=" . urlencode($url) . "&referer=" . urlencode($_SERVER['HTTP_REFERER']);
        echo <<<EOT
\t<script type="text/javascript">
\t<!--
\t//percentmobile tracking
\t{

\t\tvar percentmobile_t=new Date().getTime();\t
\t\tvar percentmobile_s=0;
\t\twhile(new Date().getTime()-percentmobile_t<20)
\t\t{
\t\t\tMath.random();
\t\t\tpercentmobile_s++;
\t\t}
\t
\t\tvar percentmobile_i=new Image();
\t\tpercentmobile_i.src="{$image_url}&m="+((percentmobile_s>1000)?"3gs":"2g3g");
\t}
\t-->
\t</script>
EOT;
    } else {
        $image_url = (isset($_SERVER['HTTPS']) && $_SERVER["HTTPS"] == "on" ? "https" : "http") . "://tracking.percentmobile.com/pixel/" . $site_id . "/" . rand(0, 0xffff) . ".gif?v=" . PERCENT_MOBILE_VERSION . "&amp;us=" . $percent_mobile_u . "&amp;vi=" . $percent_mobile_v . "&amp;url=" . urlencode($url) . "&amp;referer=" . urlencode($_SERVER['HTTP_REFERER']);
        echo '<img src="' . $image_url . '" width="2" height="2" alt="" />';
    }
}
function percent_mobile_track($site_id, $url = "")
{
    global $percent_mobile_u, $percent_mobile_v;
    if ($url == "") {
        $url = percent_mobile_self_url();
    }
    //construct the image URL, all values are submitted via URL parameters, urls are urlencoded
    //if iphone submit the image via a dynamic image and determine if we got an 3gs with a fast performance test that consumes 20ms
    if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/\\(iPhone/", $_SERVER['HTTP_USER_AGENT'])) {
        $image_url = (isset($_SERVER['HTTPS']) && $_SERVER["HTTPS"] == "on" ? "https" : "http") . "://tracking.percentmobile.com/pixel/" . $site_id . "/" . rand(0, 0xffff) . ".gif?v=" . PERCENT_MOBILE_VERSION . "&us=" . $percent_mobile_u . "&vi=" . $percent_mobile_v . "&url=" . urlencode($url) . "&referer=" . urlencode($_SERVER['HTTP_REFERER']);
        echo <<<EOT
\t<script type="text/javascript">
    {
\tvar m="";var s=document.createElement('style');var d=document.createElement('div');d.id="pm_IS_{$site_id}";
        s.innerText='@media (-webkit-min-device-pixel-ratio:2) {#'+d.id+'{display:none !important;}}';
        document.documentElement.appendChild(s).appendChild(d);
        var r=getComputedStyle(d,null).getPropertyValue('display')=='none';
        s.parentNode.removeChild(s);d.parentNode.removeChild(d);
\t\tif(r){m="&m=4";}else{r=new Date().getTime();for(var s=0;new Date().getTime()-r<20;s++){Math.random();}m = "&m="+((s>1000)?"3":"2");}
        new Image().src='{$image_url}'+m;
    }\t
\t</script>
EOT;
    } else {
        $image_url = (isset($_SERVER['HTTPS']) && $_SERVER["HTTPS"] == "on" ? "https" : "http") . "://tracking.percentmobile.com/pixel/" . $site_id . "/" . rand(0, 0xffff) . ".gif?v=" . PERCENT_MOBILE_VERSION . "&amp;us=" . $percent_mobile_u . "&amp;vi=" . $percent_mobile_v . "&amp;url=" . urlencode($url) . "&amp;referer=" . urlencode($_SERVER['HTTP_REFERER']);
        echo '<img src="' . $image_url . '" width="2" height="2" alt="" />';
    }
}