diff --git a/search_api_stats.module b/search_api_stats.module
index 0771519..a93b1de 100644
--- a/search_api_stats.module
+++ b/search_api_stats.module
@@ -25,6 +25,9 @@ function search_api_stats_search_api_results_alter(ResultSetInterface &$results)
   }
 
   $originalKeys = $query->getOriginalKeys();
+  if ($originalKeys == null) {
+      $originalKeys = '';
+  }
   $lowerOriginalKeys = mb_strtolower($originalKeys);
   $keywords = trim($lowerOriginalKeys);
   // To avoid to insert empty keywords value into database.
