When you open your
project you start writing about it everywhere, including in the
Habré .
Statistics services like Google Analytics will give you a general estimate of traffic, namely how many visitors came from which resource. You can set goals (goals) and track registration or purchase, but this is often not enough.
And what if you need statistics about where more active users come from or the users who created the most topics on the forum for a certain period of time, or made the most purchases in your online store. There may be a lot of options, and such data analytics services can no longer be given.
')
To solve this problem, we just need to save the data on the resource where the user came from during registration.
This data can be obtained, for example, from __utmz Google Analytics Cooks and recorded in some field in the database.
A __utmz cookie value usually looks something like this.
264345247.1261843448.2.3.utmcsr = habrahabr.ru | utmccn = (referral) | utmcmd = referral | utmcct = / blogs / i_am_advertising / 63791 /
static function parseGoogleAnalyticsCookies(){
$returnMap = array();
$cookieVal = $_COOKIE["__utmz"];
//now split cookie value by |
$arrPairs = explode('|', $cookieVal);
foreach($arrPairs as $pair){
$pair = explode('=', $pair);
if (sizeof($pair) == 2){
$key = $pair[0];//look for "."
if (strpos($key, ".")){
$key = substr($key, strrpos($key, ".")+1 );
}
$returnMap[$key] = $pair[1];
}
}
return $returnMap;
}
This code will split the value of __utmz cookies into pairs and write to an associative array.
Now when registering a user, you can get this data and record it with the new user.
$newUser = $model->create();
//..... /
$sourceCookiesData = GoogleAnalyticsCookies::parseGoogleAnalyticsCookies();//GoogleAnalyticsCookies
if (isset($sourceCookiesData['utmcsr'])){
$newUser->source = $sourceCookiesData['utmcsr'];
}
if (isset($sourceCookiesData['utmcct'])){
$newUser->sourceUrl = $sourceCookiesData['utmcct'];
}
$newUser->save();
We took utmcsr and utmcct which store the host and url of the referring page (there can be more than one page, so we write it down separately).
Now all data is stored in the database and any statistics can be collected using simple SQL queries.
In such a simple way, you can find out where the more targeted traffic is coming from and where to direct your efforts when moving.