Mobile app version of vmapp.org
Login or Join
Ravi8258870

: How to read user unique code from _ga cookie? Currently I am facing the problem that have been discussed already here: How to keep track of a unique and an existing visitor (keep track about

@Ravi8258870

Posted in: #Cookie #GoogleAnalytics #Php #Users

Currently I am facing the problem that have been discussed already here: How to keep track of a unique and an existing visitor (keep track about unique user without registration etc.). The most suitable answer was: "Try _ga cookie". So my questestion is how can I do that on my PHP website?

I want something like this:


User came to my website and performs some action
I "look into his _ga cookie" and take some "identification code"
I log about this action to the database
When user will come again and he will want to perform action again, then I look into my log and I will realize that this is same user


My question is:

How to read user identification from _ga ?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Ravi8258870

1 Comments

Sorted by latest first Latest Oldest Best

 

@Turnbaugh106

Just get _ga cookie - it is a string with dot separated values. You are looking for third value...

public static function getGaCode() {

// Check fo cookie
$name = "_ga";
if (!isset($_COOKIE[$name])) {
return null;
}

// Parse cookie _ga='<something>.<something>.<clientid>.<timestamp>';
return explode(".", $_COOKIE[$name])[2];
}

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme