bunu js yerinde php ile en üste bir kontrol fonksiyonu yazabilirsiniz daha basit ve kullanışlı olacaktır
ob_start();
if (!isset($_COOKIE['location'])) {
    setcookie("location",true,time()+(3600*24));
    header('Location: https://www.google.com.tr/');
}