You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@tsteur ,
Am developing a plugin to export data into another application. I have called it visitorforecast and here is my code for visitoreForecast.php,
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\VisitorForecast;
require_once("StatsD.php");
use Piwik\Piwik;
use Piwik\Plugin;
class VisitorForecast extends \Piwik\Plugin
{
//getListHooksRegistered method must return an array, mapping the hook name to a callback function
public function getListHooksRegistered()
{
return array( 'Tracker.newVisitorInformation' => 'addVisitorInformation' ,
'Tracker.existingVisitInformation' => 'updateExistingVisitorInfo'
);
}
public function addVisitorInformation(array &$visitorInfo)
{
// get the referrer_url
$url = $visitorInfo['referer_url'];
// do something with the url
$eventTotal = $visitorInfo['visit_total_events'];
$timeTotal = $visitorInfo['visit_total_time'];
//send eventTotal via statsd to owl
$stats = new StatsD("owl-statsd.etv.nce.amadeus.net","8125");
$key = "Users3.2016.January";
$stats ->gauge($key,$eventTotal);
//send timetotal via statsd to owl
$key = "Users4.2016.January";
$stats ->gauge($key,$timeTotal);
}
public function updateExistingVisitorInfo(array &$visitorInfo)
{
// get the referrer_url
$url = $visitorInfo['referer_url'];
$eventTotal = $visitorInfo['visit_total_events'];
$timeTotal = $visitorInfo['visit_total_time'];
$totalnumOfVisits = $visitorInfo['visitor_count_visits'];
//send eventTotal via statsd to owl
$stats = new StatsD("owl-statsd.etv.nce.amadeus.net","8125");
$key = "Users5.2016.January";
$stats ->gauge($key,$eventTotal);
//send timetotal via statsd to owl
$key = "Users6.2016.January";
$stats ->gauge($key,$timeTotal);
//send totalnumOfVisits via statsd to owl
$key = "Users8.2016.January";
$stats ->gauge($key,$totalnumOfVisits);
}
}_
The code connects to my server as i can receive the key but i cant see the data like $eventTotal or $timeTotal. I believe that no data is getting assigned to these variables from the $visitorInfo. May i know what mistakes i have done? Please help me because am new to php.
My statsD code looks like this
/*
* A simple PHP class for interacting with a statsd server
* @author John Crepezzi <john.crepezzi@gmail.com>
*/
namespace Piwik\Plugins\VisitorForecast;
class StatsD {
private $host, $port;
// Instantiate a new client
public function __construct($host = 'localhost', $port = 8125) {
$this->host = $host;
$this->port = $port;
}
// Record timing
public function timing($key, $time, $rate = 1) {
$this->send("$key:$time|ms", $rate);
}
// Record gauge
public function gauge($key, $gauge) {
$this->send("$key:$gauge|g");
}
// Time something
public function time_this($key, $callback, $rate = 1) {
$begin = microtime(true);
$callback();
$time = floor((microtime(true) - $begin) * 1000);
// And record
$this->timing($key, $time, $rate);
}
// Record counting
public function counting($key, $amount = 1, $rate = 1) {
$this->send("$key:$amount|c", $rate);
}
// Send
private function send($value, $rate = NULL) {
$fp = fsockopen('udp://' . $this->host, $this->port, $errno, $errstr);
// Will show warning if not opened, and return false
if ($fp) {
fwrite($fp, $rate ? "$value|@$rate" : $value);
fclose($fp);
}
}
}
The text was updated successfully, but these errors were encountered:
visit_total_events will be only set if there was actually a change, meaning if actually an event was tracked after debugging code. Instead try to generate a visitor dimension maybe (see https://developer.piwik.org/guides/dimensions ). There you can access likely all visitor fields.
Next time please ask such questions in forum (which may result in a bit of waiting) as we can't always answer them here. We're only handling bugs and feature requests here.
@tsteur ,
Am developing a plugin to export data into another application. I have called it visitorforecast and here is my code for visitoreForecast.php,
The code connects to my server as i can receive the key but i cant see the data like $eventTotal or $timeTotal. I believe that no data is getting assigned to these variables from the $visitorInfo. May i know what mistakes i have done? Please help me because am new to php.
My statsD code looks like this
The text was updated successfully, but these errors were encountered: