Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't generate visitor information #9921

Closed
kira510 opened this issue Mar 14, 2016 · 1 comment
Closed

Can't generate visitor information #9921

kira510 opened this issue Mar 14, 2016 · 1 comment
Labels
answered For when a question was asked and we referred to forum or answered it.
Milestone

Comments

@kira510
Copy link

kira510 commented Mar 14, 2016

@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);
        }

    }

}
@tsteur
Copy link
Member

tsteur commented Mar 14, 2016

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 tsteur closed this as completed Mar 14, 2016
@tsteur tsteur added the answered For when a question was asked and we referred to forum or answered it. label Mar 14, 2016
@tsteur tsteur added this to the 2.16.1 milestone Mar 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered For when a question was asked and we referred to forum or answered it.
Projects
None yet
Development

No branches or pull requests

2 participants