Once you have created a query, you can run a report to return the query result.
...
Code Block | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
//Include the analytics class and the configuration class $t->runInteraction("Analytics.class.php"); $t->runInteraction("Config.class.php"); //Create our query object $query = new Query(Config::$ANALYTICS_ANALYST); //check if the query exists $res = $query->get(); //find the QueryID $queryId = $res[0]["_id"]; //You need to run the query on the collector key $collection = Config::$ANALYTICS_COLLECTOR["ACCESS"]; //build query string to replace placeholders $queryString = array( "event" => "Login", "gte" => "date:2016-03-21", "lt" => "date:2030-04-30", "group" => "Inspector" ); //authenticate and create a new report, returns report object $analytics = new Report(Config::$ANALYTICS_ANALYST); //run the query, returns an array $response = $analytics->runQuery($queryId, $collection, $queryString); |
Explanation:
The first two "runInteraction" lines will simply "include" the class files you already uploaded. Make sure your have used the correct interaction names. You will need to put both of these lines on any page, or interaction, that you will be calling the class.
//Create our query object
$query = new Query(Config::$ANALYTICS_ANALYST);
This line will simply create the $query object, using the analyst credentials from the the Config.class.php file.
//Read all saved queries
$res = $query->get();
This line will will read all saved queries (there are no search options available).
//find the queryID
$queryId = $res[0]["_id"];
Each query has a unique id, you need this ID to run the query and return data.
//You need to run the query on the collector key
$collection = Config::$ANALYTICS_COLLECTOR["ACCESS"];
When gathering saved data, you need to do so using the Collector key.
//authenticate and create a new report, returns report object
$analytics = new Report(Config::$ANALYTICS_ANALYST);
Using the Analyst key, set up a new Report.
//run the query, returns an array
$response = $analytics->runQuery($queryId, $collection, $queryString);
...
Code Block | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
//save query, returns object with unique Query ID $res = $query->save($name, $type, $params); //find the queryID $queryId = $res["_id"]; /* --- Alternate method --- */ //Alternately, you can use $query->get() to return all saved queries $res = $query->get(); //find the QueryID $queryId = $res[0]["_id"]; |
$collection(string)
...