get_distinct_id(); } // Add session context and plugin specific properties $properties = array_merge( $properties, [ 'page_url' => isset($_SERVER['REQUEST_URI']) ? esc_url( $_SERVER['REQUEST_URI'] ) : '', 'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ) : '', 'plugin' => 'WP VR', 'plugin_version' => defined('WPVR_VERSION') ? WPVR_VERSION : 'unknown', 'wp_version' => get_bloginfo( 'version' ), 'site_url' => get_site_url(), ]); try { PostHog::init( self::POSTHOG_API_KEY, [ 'host' => self::POSTHOG_HOST, ] ); $response = \PostHog\PostHog::capture([ 'distinctId' => $distinct_id, 'event' => $event_name, 'properties' => $properties, ]); return $response; } catch (Exception $e) { return false; } } /** * Get distinct ID for PostHog tracking. * * @since 8.5.37 * * @return string Distinct ID */ private function get_distinct_id(): string { if ( is_user_logged_in() ) { $current_user = wp_get_current_user(); return $current_user->user_email; } return 'anonymous_' . uniqid( '', true ); // Generate a unique ID for anonymous users } }