public function getOptimisedMetrics(StatsQueryInterface $query): array
    {
        $response = $this->getMetrics($query, 'js');
        // If no analytics data returned for a given criteria just return.
        if (empty($response['stats'])) {
            return $response;
        }
        if (null !== $query->getTimeUnit()) {
            $originalTimeUnits = $response['TimeUnit'];
            $response['TimeUnit'] = $this->fillGapsInTimeUnitsData(
                $query->getTimeRange(),
                $query->getTimeUnit(),
                $query->getTsAscending()
            );
            $this->fillGapsInMetricsData(
                $query->getTsAscending(),
                $response['TimeUnit'],
                $originalTimeUnits,
                $response['stats']['data']
            );
        }

        return $response;
    }