Versions Compared

Key

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

Logging an event is how you start collecting data.

...

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:

 

Code Block
languagephp
themeRDark
titleLog 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//Log one event
$events = array(
   "name" => "Login";
$params,
   "tags" => array(
       "username" => "johnsmith", "group" => "Inspector"
   ),
       "date" => date("c")
);


//register login event with username, Log more then one event
$events = array(
   array(
       "name" => "Login",
       "tags" => array(
           "username" => "johnsmith", "group" => "Inspector"
       ),
       "date" => date("c")
   ),
   array(
       "name" => "Login",
       "tags" => array(
           "username" => "janesmith", "group" => "Inspector"
       ),
       "date" => date("c")
   )
);


//register login events, returns saved event with unique id ids for each event
$response = $analytics->log($name, $params$events);

 

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 usernameevents, returns saved event with unique idids for each event
$response = $analytics->log("Login", array("username" => "johnsmith", 
"group" => "Inspector")$events
);

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 argumentsaccepts an array(), there are three keys that can be included for each event:

  1. The name of the event using  the "name" key. (Required)
  2. Extra data that you wish to include ( formatted as an array() ) under the "tags" key. (Required)
  3. A date timestamp using the "date" key. (Optional - if left blank, the timestamp will be taken when the data is submitted to the database)

$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 extra data tags array can contain any extra information you want to include in this log. These is are entirely freeform - you can include as much (within reason) or as little information in this array as you wish.

...