setCustomVariable() public method

See http://piwik.org/docs/custom-variables/
public setCustomVariable ( integer $id, string $name, string $value, string $scope = 'visit' )
$id integer Custom variable slot ID from 1-5
$name string Custom variable name
$value string Custom variable value
$scope string Custom variable scope. Possible values: visit, page, event
コード例 #1
0
ファイル: plugin.php プロジェクト: mm999/piwik-yourls
/**
 * Sends the keyword and destination URL to Piwik
 *
 * @param bool $return    The value to return. Defaults to false with doesn't enable the filter
 * @param string $keyword    The requested keyword
 * @return bool
 */
function itfs_piwik_log_request($return, $keyword)
{
    // Get current configuration from database
    $piwik_config = yourls_get_option('piwik_config');
    // Let's check if the user wants to log bots
    if ($piwik_config[remove_bots]) {
        if (itfs_piwik_is_bot()) {
            return $return;
        }
    }
    try {
        // Need to use a file_exists check as require only produces a fatal compilation error
        if (!file_exists(dirname(__FILE__) . '/libs/Piwik/PiwikTracker.php')) {
            throw new Exception("Error can't load PiwikTracker.php");
        } else {
            // Piwik Tracking API init
            require_once dirname(__FILE__) . '/libs/Piwik/PiwikTracker.php';
            PiwikTracker::$URL = $piwik_config[piwik_url];
        }
    } catch (Exception $e) {
        error_log("ITFS_PIWIK: " . $e->getMessage(), 0);
        return $return;
    }
    // Use this to get the destination
    $destination = yourls_get_keyword_longurl($keyword);
    // Only log a request if we have a destination and the proper Piwik settings
    if ($destination == false) {
        error_log("ITFS_PIWIK: Missing parameters prevented me from logging the request with Piwik", 0);
        error_log("ITFS_PIWIK: Parameters we have: " . $keyword . ', ' . $destination, 0);
        return $return;
    }
    //Useful for hosts using one Piwik installation with multiple YOURLS installation
    $domain_landed = $_SERVER['HTTP_HOST'];
    $page_url = "http://" . $domain_landed . "/" . $keyword;
    try {
        $pt = new PiwikTracker($piwik_config[site_id]);
        // This will be the entry page in Piwik
        $pt->setUrl($page_url);
        // This will fail silently if the token is not valid or if the user doesn't have admin rights
        if (!empty($piwik_config[token])) {
            $pt->setTokenAuth($piwik_config[token]);
        }
        // This shows up in the visitor logs and identify the source of the data
        $pt->setCustomVariable(1, 'App', 'Piwik plugin for YOURLS', 'visit');
        // Some useful variables
        $pt->setCustomVariable(2, 'Domain landed', $domain_landed, 'page');
        $pt->setCustomVariable(3, 'Keyword', $keyword, 'page');
        // User defined custom variable
        if (!empty($piwik_config[customvar_name]) && !empty($piwik_config[customvar_value])) {
            $pt->setCustomVariable(4, $piwik_config[customvar_name], $piwik_config[customvar_value], $piwik_config[customvar_scope]);
        }
        // Track the visit in Piwik
        $title = yourls_get_keyword_title($keyword);
        @$pt->doTrackPageView($title);
        // The destination URL will show up as an outlink
        @$pt->doTrackAction($destination, 'link');
    } catch (Exception $e) {
        error_log("ITFS_PIWIK: Error when trying to log the request with Piwik. " . $e->getMessage(), 0);
        return $return;
    }
    if ($piwik_config[disable_stats]) {
        //error_log("ITFS_PIWIK: NOT logging locally", 0);
        return;
    } else {
        //error_log("ITFS_PIWIK: Logging locally", 0);
        return $return;
    }
}
コード例 #2
0
ファイル: index.php プロジェクト: aelallam/emergencybutton
function exception_handler($exception)
{
    mylog("Uncaught exception: " . $exception->getMessage());
}
set_exception_handler('exception_handler');
require_once "Mail.php";
require_once "config.php";
//define("PIWIK_ENABLE_TRACKING");
//$_GET["idsite"] = "3";
//require_once "../piwik/piwik.php";
//echo($_GET["idsite"]);
// -- Piwik Tracking API init --
require_once "../PiwikTracker.php";
PiwikTracker::$URL = 'http://toplessproductions.com/static/piwik/';
$t = new PiwikTracker($idSite = 3);
$t->setCustomVariable(1, 'Force IP', $_SERVER['REMOTE_ADDR']);
$t->doTrackPageView('email by web');
$from = "<*****@*****.**>";
$to = $_POST["to"];
$subject = $_POST["subject"];
$body = $_POST["message"];
$secret = $_POST["secret"];
$replyto = $_POST["replyto"];
if ($secret != $SECRET) {
    log("Wrong secret");
    die("...");
}
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "******";
$password = $PW;
コード例 #3
0
 private function setMovieEventCustomVar(PiwikTracker $vis)
 {
     $vis->setCustomVariable($id = 1, $name = 'country', $value = '日本', $scope = 'event');
     $vis->setCustomVariable($id = 2, $name = 'genre', $value = 'Greatest animated films', $scope = 'event');
     $vis->setCustomVariable($id = 4, $name = 'genre', $value = 'Adventure', $scope = 'event');
     $vis->setCustomVariable($id = 5, $name = 'genre', $value = 'Family', $scope = 'event');
     $vis->setCustomVariable($id = 5, $name = 'movieid', $value = 15763, $scope = 'event');
     $vis->setCustomVariable($id = 1, $name = 'Visit Scope Custom var', $value = 'should not appear in events report Bis', $scope = 'visit');
 }