0

I know it's possible to get the previous url of the visitor with

$ _SERVER ['HTTP_REFERER'];

but how do I get the source/medium that the visitor was before accessing the site?

For example if the visitor came from: Google/Organic, Google/CPC (paid), Bing/Organic, Bing/CPC, Direct/none, facebook/referral, youtube/referral, otherSites.com/referral, etc.

Thanks

Gislef
  • 1,555
  • 3
  • 14
  • 37
  • 1
    Possible duplicate of [Is there a reliable way to get the referring url without relying on $\_SERVER?](https://stackoverflow.com/questions/26721402/is-there-a-reliable-way-to-get-the-referring-url-without-relying-on-server) – Alister Bulman Oct 24 '17 at 22:15
  • @AlisterBulman Thanks for replying, I visited the possible duplicate question link, but the question you suggested does not answer my doubt – Gislef Oct 24 '17 at 22:18
  • There's no standard way of getting the "medium" (a term invented by Google Analytics). You have to read the referrer and deviate the medium from it. – Reeno Oct 24 '17 at 22:31
  • @Reeno thank you very much I found the solution, see my answer – Gislef Oct 24 '17 at 23:22

1 Answers1

0

I found the solution on GitHub: Google Analytics Cookie Parser PHP

Basically I must parse some Google Analytics cookies, for example utma and umtz, and access the information I need

For utma

$utma->time_of_first_visit; // DateTime
$utma->time_of_last_visit; // DateTime
$utma->time_of_current_visit; // DateTime
$utma->session_count // Integer

For utmz

$utmz->timestamp; // DateTime
$utmz->session_count // Integer
$utmz->campaign_number // Integer
$utmz->source // string
$utmz->medium // string
$utmz->campaign // string
$utmz->term // string
$utmz->content // string
Gislef
  • 1,555
  • 3
  • 14
  • 37