<commit_before># Query Events

## How it works

Queries are first-class citizens, complete with parameter getters and setters. In order to run queries, you must be using the full Keen JS SDK (not the tracking only version) and if the library is loaded asynchronously, you need to wrap all querying in the `ready` function.

The `run` method is available on each configured client instance to run one or many analyses on a given project. Read more about running multiple analyses below.

```javascript
var your_analysis = new Keen.Query(analysisType, params);
```

## Example Usage

```javascript
<script type="text/javascript">

  //Configure the client
  var client = new Keen({
      projectId: "your_project_id",
      readKey: "your_read_key"
  });

  Keen.ready(function(){
    // Count the number of times case study pages were viewed
    var count = new Keen.Query("count", {
      eventCollection: "pageviews",
      interval: "daily",
      timeframe: "this_7_days",
      filters: [
        {
          "property_name" : "domain",
          "operator" : "eq",
          "property_value" : "www.mysite.io" // look at one particular domain only
        },
        {
          "property_name":"url.full",
          "operator":"contains",
          "property_value":"casestudy"  // only count views with "casestudy" in the page URL
        }
     ]
    });

    // Send query
    client.run(count, function(err, response){
      // Print the query result to the console
      console.log(response);
    });
  });<commit_msg>Order of callback parameters are inverted.<commit_after># Query Events

## How it works

Queries are first-class citizens, complete with parameter getters and setters. In order to run queries, you must be using the full Keen JS SDK (not the tracking only version) and if the library is loaded asynchronously, you need to wrap all querying in the `ready` function.

The `run` method is available on each configured client instance to run one or many analyses on a given project. Read more about running multiple analyses below.

```javascript
var your_analysis = new Keen.Query(analysisType, params);
```

## Example Usage

```javascript
<script type="text/javascript">

  //Configure the client
  var client = new Keen({
      projectId: "your_project_id",
      readKey: "your_read_key"
  });

  Keen.ready(function(){
    // Count the number of times case study pages were viewed
    var count = new Keen.Query("count", {
      eventCollection: "pageviews",
      interval: "daily",
      timeframe: "this_7_days",
      filters: [
        {
          "property_name" : "domain",
          "operator" : "eq",
          "property_value" : "www.mysite.io" // look at one particular domain only
        },
        {
          "property_name":"url.full",
          "operator":"contains",
          "property_value":"casestudy"  // only count views with "casestudy" in the page URL
        }
     ]
    });

    // Send query
    client.run(count, function(response, err){
      // Print the query result to the console
      console.log(response);
    });
  });
{'fraction_non_alphanumeric': 0.10326966655875688, 'fraction_numerical': 0.0006474587245063128, 'mean_word_length': 2.8385093167701863, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2073612', 'n_tokens_mistral': 867, 'n_tokens_neox': 841, 'n_words': 325}