Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

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.

Example:

 

Code Block Example
/* --- Method 1: Find the QueryID in the return array after saving a query --- */
//save query, returns object with unique Query ID
$res = $query->save($name, $type, $params);

//find the queryID
$queryId = $res["_id"];


/* --- Method 2: query all saved queries and choose the appropriate QueryID --- */
//Alternately, you can use $query->get() to return all saved queries
$res = $query->get();
           
//find the QueryID
$queryId = $res[0]["_id"];

$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.

 

 

  • No labels