Log an Event - SDK_v0.0.1-rc

Logging an event is how you start collecting data.

An event can be anything you wish, from tracking page hits and app logins through to form submissions and app usage.

By default, a timestamp of the log will be automatically inserted, and so there is no need to include a timestamp yourself. You can, however, add as much extra information to the log as you wish. This extra information can also be queried on, as we will show later.

 

Code Snippet Example:

 

Log an Event
//to import the analytics classes
$t->runInteraction("Analytics.class.php");

//import config class which contains keys
$t->runInteraction("Config.class.php");

//create object
$analytics = new Event(Config::$ANALYTICS_COLLECTOR);
 
$name = "Login";
$tags = array("username" => "johnsmith", "group" => "Inspector");

//register login event with username, returns saved event with unique id
$response = $analytics->log($name, $tags);

 

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 object
$analytics = new Event(Config::$ANALYTICS_COLLECTOR);

This line will simply create the $analytics object, using the details from the the Config.class.php file. You don't need to modify this line.


//register login event with username, returns saved event with unique id
$response = $analytics->log("Login", array("username" => "johnsmith", 
"group" => "Inspector"));

This line is the method that will log an event. In this example, you may want to call this after a user successfully logs in.

The $analytics->log method takes two arguments:

  1. The name of the event
  2. Extra data you wish to include

$name (string value)

In the code example above, the event is named "Login". This is can be any string, and you can name it whatever you wish.

This will allow you to group specific events together, and so later you could run an query to show all "Logins", or all "Form Submissions", for example.

$tags (array)

The tags array can contain any extra information you want to include in this log. These are entirely freeform - you can include as much (within reason) or as little information in this array as you wish.

For the sake of performance, please don't include large amounts of data here, such as full form submission data, or images!

In the example above, we're including the username of the person logged in, and the group they are a part of. To add extra information, just add a new value to this array.

Response:

After running this method, you will receive a response object that will simply return the data you logged. You can use this to double check values if you wish, but this is optional.


Next Step:

Create a Query