I want to add a cookie so that I can exclude my interaction with my website from google analytics (I don't have access to put files on server as is third party application)
Is it possible to set a cookie with javascript by executing code in the address bar of the browser?
I want to add a cookie so that I can exclude my interaction with my website from google analytics (I don't have access to put files on server as is third party application)
Is it possible to set a cookie with javascript by executing code in the address bar of the browser?
Share Improve this question edited Nov 8, 2010 at 13:05 Craig Angus asked Oct 8, 2009 at 15:53 Craig AngusCraig Angus 23.2k18 gold badges57 silver badges64 bronze badges 2- 2 I believe you can also exclude your own IP address in the Google Analytics interface. – ceejayoz Commented Oct 8, 2009 at 16:01
- 1 This Analytics help page shows you how to filter out your own IP from the reports: google.com/support/analytics/bin/… – Shawn Chin Commented Nov 4, 2010 at 9:13
5 Answers
Reset to default 9javascript:document.cookie="name=value"
I think, what you mean is:
javascript:void(document.cookie="cookiename=value");
Hope this could help you.
Update:
For new browser version you have to also enable javascript to be executed in the address bar.
another way is to use firebug on explorer or the js console in ie8. just type document.cookie="XDEBUG_SESSION_START=netbeans-xdebug";
then you can verify it was set by typing document.cookie
I don't know if pure JavaScript can do that but i use simple PHP code to do that :
if (isset($request->get['tracking']) && !isset($request->cookie['tracking'])) {
setcookie('tracking', $request->get['tracking'], time() + 3600 * 24 * 1000, '/');
}
put it in your index.php to save cookie when page loads - if i get your purpose correctly .
*because you want addressee bar , it is better to use PHP and Get request .
Hope it help .
Yes its possible to change cookie values, or to create new cookies from the address bar. I am not so good with javascript, but this should help you change cookie values:
javascript:alert(window.c=function a(n,v,nv) {c=document.cookie;c=c.substring(c.indexOf(n) +n.length,c.length);c= c.substring(1,((c.indexOf(";")>-1) ? c.indexOf(";") : c.length)); nc=unescape(c).replace(v,nv); document.cookie= n+"="+escape(nc);return unescape(document.cookie);}); alert(c(prompt("cookie name:",""), prompt("replace this value:",""), prompt("with::","")));
And this, to create new cookies
javascript:document.cookie = cookieName + '=; expires=3600;' +"path=/; domain=" +
window.location.hostname;