$clean_url, 'scheme' => $scheme, 'host' => $host, 'path' => $path, 'query_string' => $query, 'query_params' => \wp_json_encode( $query_params ), 'page_type' => $page_type, 'page_id' => $page_id, ); } /** * Determines the current page type. * * @return string The page type. * * @since 4.9.0 */ private static function get_page_type(): string { if ( \is_front_page() ) { return 'front_page'; } if ( \is_home() ) { return 'blog_home'; } if ( \is_single() ) { return 'single_post'; } if ( \is_page() ) { return 'page'; } if ( \is_category() ) { return 'category'; } if ( \is_tag() ) { return 'tag'; } if ( \is_tax() ) { return 'taxonomy'; } if ( \is_author() ) { return 'author'; } if ( \is_date() ) { return 'date_archive'; } if ( \is_archive() ) { return 'archive'; } if ( \is_search() ) { return 'search'; } if ( \is_404() ) { return '404'; } if ( \is_attachment() ) { return 'attachment'; } return 'other'; } /** * Gets the current page/post ID if applicable. * * @return int The page ID or 0. * * @since 4.9.0 */ private static function get_page_id(): int { $queried_object = \get_queried_object(); if ( $queried_object && isset( $queried_object->ID ) ) { return (int) $queried_object->ID; } if ( \in_array( self::get_page_type(), array( 'category', 'tag', 'taxonomy', 'attachment' ) ) && isset( $queried_object->cat_ID ) ) { return (int) $queried_object->cat_ID; } return 0; } /** * Gets trackable URL statistics. * * @return array Statistics about tracked URLs. * @since 4.9.0 */ public static function get_statistics(): array { $stats = Urls_Log_Entity::get_row( 'SELECT COUNT(*) as total_urls, SUM(visit_count) as total_visits, MAX(visit_count) as max_visits, AVG(visit_count) as avg_visits' ); return array( 'total_urls' => (int) ( $stats['total_urls'] ?? 0 ), 'total_visits' => (int) ( $stats['total_visits'] ?? 0 ), 'max_visits' => (int) ( $stats['max_visits'] ?? 0 ), 'avg_visits' => (float) ( $stats['avg_visits'] ?? 0 ), ); } } }