click method

Future click (
  1. Map<String, int> objects,
  2. {bool isSuggestionClick: false,
  3. String queryId}
)
inherited

use this methods to record a search click event

Implementation

Future click(Map<String, int> objects,
    {bool isSuggestionClick = false, String queryId}) async {
  String queryID = queryId;
  if (queryId == null || queryId == "") {
    queryID = this.queryId;
  }
  if (this.appbaseConfig != null &&
      this.appbaseConfig.recordAnalytics == true &&
      queryID != null &&
      queryID != "") {
    try {
      final Map requestBody = {
        'click_on': objects,
        'click_type': isSuggestionClick ? 'suggestion' : 'result',
        'query_id': queryID,
      };
      final String url = "${this.url}/${this..index}/_analytics/click";
      final res = await http.put(
        url,
        headers: this.headers,
        body: jsonEncode(requestBody),
      );
      return Future.value(res);
    } catch (e) {
      return Future.error(e);
    }
  }
  return Future.error("Query ID not found. Make sure analytics is enabled");
}