Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Once you have created a query, you can run a report to return the query result.

...

Code Block
languagephp
themeRDark
firstline1
titleCode Block Example
linenumberstrue
//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",
    "lte" => "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
themeRDark
titleReturn
Array
(
    [0] => Array
        (
            [_id] => 56ef4b9d019b38e073bad70e56de2fr0219b38e071aac27e
            [name] => Login
            [tags] => Array
                (
                    [username] => johnsmith
                    [group] => Inspector
                )
            [date] => 2016-03-21T01:17:17.328Z
        )
)

...