public function log()
    {
        global $wp_query;

        if (!$wp_query->is_search() || max(1, get_query_var('paged')) > 1) {
            return;
        }

        global $wpdb;

        $query = get_search_query();
        $hits = $wp_query->found_posts;
        $siteId = null;
        $loggedIn = is_user_logged_in();


        if (isset($_COOKIE['search_log']) && is_array(unserialize(stripslashes($_COOKIE['search_log']))) && in_array($query, unserialize(stripslashes($_COOKIE['search_log'])))) {
            return;
        }

        if (is_multisite() && function_exists('get_current_blog_id')) {
            $siteId = get_current_blog_id();
        }

        $insertedId = $wpdb->insert(
            \SearchStatistics\App::$dbTable,
            array(
                'query' => $query,
                'results' => $hits,
                'site_id' => $siteId,
                'logged_in' => $loggedIn
            ),
            array(
                '%s',
                '%d',
                '%d',
                '%d'
            )
        );

        $cookie = array();

        if (isset($_COOKIE['search_log']) && is_array($_COOKIE['search_log'])) {
            $cookie = $_COOKIE['search_log'];
        }

        $cookie[] = $query;

        setcookie('search_log', serialize($cookie), time() + (86400 * 1), "/");
    }