TL;DR: Googlebot must not collect cookies.
The other day Jacob Emerick and I stumbled on an interesting question… “How does googlebot handle cookies?” I setup a test to determine if Googlebot was in fact tracking cookies. It’s a pretty simple script. If there’s a cookie set, a message is echo’ed out. If there’s no cookie set, a new one is created.
Next, I opened up Google Web Master Tools and ran a few “Fetch as Googlebot”. Here are my results:
Test 1: (Initial call should set the cookie);
HTTP/1.1 200 OK Date: Sat, 16 Feb 2013 22:33:05 GMT Server: Apache X-Powered-By: PHP/5.3.19 Set-Cookie: CookieMonster=Chocolate+Chip; expires=Tue, 05-Mar-2013 22:33:05 GMT Vary: Accept-Encoding,User-Agent Content-Encoding: gzip Content-Length: 65 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: text/html No cookie here! Let me bake one up for you...
Test 2: (We’d expect that the cookie was set the last time);
HTTP/1.1 200 OK Date: Sat, 16 Feb 2013 22:33:42 GMT Server: Apache X-Powered-By: PHP/5.3.19 Set-Cookie: CookieMonster=Chocolate+Chip; expires=Tue, 05-Mar-2013 22:33:42 GMT Vary: Accept-Encoding,User-Agent Content-Encoding: gzip Content-Length: 65 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: text/html No cookie here! Let me bake one up for you...
Test 3: (Nothing on the last attempt. This for sure should have the cookie.);
HTTP/1.1 200 OK Date: Sat, 16 Feb 2013 22:34:17 GMT Server: Apache X-Powered-By: PHP/5.3.19 Set-Cookie: CookieMonster=Chocolate+Chip; expires=Tue, 05-Mar-2013 22:34:17 GMT Vary: Accept-Encoding,User-Agent Content-Encoding: gzip Content-Length: 65 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: text/html No cookie here! Let me bake one up for you...
So, according to these results, google does not currently store or use cookies. This is likely due to how crawlers work. Nonetheless, this is something to keep in mind if you are using cookies on your site.
I think you had got a error result.
I had changed your script to:
$cookieName=’CookieMonster’;
$cookieData=’Chocolate Chip’;
if(isset($_COOKIE[$cookieName])){
echo “Yep, cookie found!”;
}else{
setcookie($cookieName,$cookieData,$expire);
header(“Location: http://***.com/this_file“);
exit;
}
?>
then you will find that the googlebot return “Yep, cookie found!”
googlebot certainly not keep cookie for you twice request. but if in once. that is certainly not.
Pingback: Macro Magic For Google Tag Manager - Simo Ahava's blog