Run a Report

Now that we've created a Query, this example will show you how to run that query and get an object back with the results.

The returned object will allow you to display the results in any way you wish, from a simple table to graphs.

 

Request:

 

Code Block Example
$t->runInteraction("Analytics.class.php");
$t->runInteraction("Config.class.php");
//use your collector access key
$collection = Config::$ANALYTICS_COLLECTOR["ACCESS"];

//select the Query ID number you want to use
$queryId = "56de2fr0219b38e071aac27e";

$queryString = array(
   "event" => "Login",
   "gte" => "date:2016-02-01",
   "lte" => "date:2016-03-31",
   "group" => "Inspector"
);

$analytics = new Report(Config::$ANALYTICS_ANALYST);
$response = $analytics->runQuery($queryId, $collection, $queryString);

 

$queryId (string value)

The $queryId is the ID string that you received when you first created the query. You can also find the queries you need by using the List Saved Queries function.

$queryString (array)

The $queryString array allows you to pass dynamic values to the query, to return the results you want. When we created the query, we set variables, or placeholders, for "event", "gte" (greater than or equals), "lte" (less than or equals), and a "group".

In this example we're looking for an event with the name "Login", between 1 Feb 2016, and 31 Mar 2016 (inclusive), for all users in the group "Inspector".

 

Response:

 

The response we get is an array:

 

Response
Array
(
    [0] => Array
        (
            [_id] => 56de2fr0219b38e071aac27e
            [name] => Login
            [tags] => Array
                (
                    [username] => johnsmith
                    [group] => Inspector
                )
            [date] => 2016-03-13T22:57:39.774Z
        )

    [1] => Array
        (
            [_id] => 56ebd3e80a9b38e073ba1428
            [name] => Login
            [tags] => Array
                (
                    [username] => johnsmith
                    [group] => Inspector
                )
            [date] => 2016-03-18T01:03:36.217Z
        )

)

 

Each item in the array is an array containing the information about that particular event.

 

Â