1

I am trying to create a mini analytics, and identifying where the visitors came from.

I am using $_SERVER['HTTP_REFERER'] to find out where each visitor came from, but I am struggling to find out if they came from Google Adwords or Organic.

Is there some trick to this? Is $_SERVER['HTTP_REFERER'] even the correct way to go about this?

Also if anyone knows how to do the same for yahoo and bing, then that sure would be handy too.

currarpickt
  • 2,290
  • 4
  • 24
  • 39
Source
  • 1,026
  • 4
  • 11
  • 23

1 Answers1

1

It's not possible to do it only with the HTTP's refereral, because the HTTPS protocol and Google deletes the URL parameters. Also, not so easy as you think, because there is a lot of variations to take in consideration (for example new.google.com, or Google.com)

Google Analytics mixes the referer pages and the UTM_parameters (Gclid is also included). I recomend you take a look of this document for more information https://support.google.com/analytics/answer/6205762?hl=en

But, I leave you a mini script that can help you, but it works only to detect the Google.

<?php
function detectCampaing()
{
   $ret = false;
   if(isset($_GET["gclid"])){ $ret = true;}
   if(isset($_GET["utm_source"])){ $ret = true;}
   if(isset($_GET["utm_medium"])){ $ret = true;}
   if(isset($_GET["utm_campaign"])){ $ret = true;}
    return $ret;
}


if(detectCampaing() == true ||strpos($_SERVER["HTTP_REFERER"], 'google') !== false){echo  "is campaign";}else{echo "is not a campaign";}
?>
Kemen Paulos Plaza
  • 1,560
  • 9
  • 18