setUrl() public method

Sets the current URL being tracked
public setUrl ( string $url )
$url string Raw URL (not URL encoded)
 protected function trackMusicPlaying(PiwikTracker $vis)
 {
     $vis->setUrl('http://example.org/webradio');
     $vis->setGenerationTime(333);
     self::checkResponse($vis->doTrackPageView('Welcome!'));
     $this->moveTimeForward($vis, 1);
     $this->setMusicEventCustomVar($vis);
     self::checkResponse($vis->doTrackEvent('Music', 'play', 'La fiancée de l\'eau'));
     $this->moveTimeForward($vis, 2);
     $this->setMusicEventCustomVar($vis);
     self::checkResponse($vis->doTrackEvent('Music', 'play25%', 'La fiancée de l\'eau'));
     $this->moveTimeForward($vis, 3);
     $this->setMusicEventCustomVar($vis);
     self::checkResponse($vis->doTrackEvent('Music', 'play50%', 'La fiancée de l\'eau'));
     $this->moveTimeForward($vis, 4);
     $this->setMusicEventCustomVar($vis);
     self::checkResponse($vis->doTrackEvent('Music', 'play75%', 'La fiancée de l\'eau'));
     $this->moveTimeForward($vis, 4.5);
     $this->setMusicEventCustomVar($vis);
     self::checkResponse($vis->doTrackEvent('Music', 'playEnd', 'La fiancée de l\'eau'));
 }
Exemplo n.º 2
0
 private function trackPageview(\PiwikTracker $tracker, $userId, $url)
 {
     $tracker->setUrl('http://www.example.org' . $url);
     $tracker->setUserId($userId);
     $tracker->doTrackPageView($url);
 }
function saveInPiwik($logHash)
{
    echo $logHash["ip"] . " " . $logHash["status"] . " " . $logHash["utcdatetime"] . " " . $logHash["path"] . " (" . $logHash["agent"] . ")... ";
    global $idSite, $webUrl, $piwikUrl, $tokenAuth;
    $t = new PiwikTracker($idSite, $piwikUrl);
    $t->setUserAgent($logHash["agent"]);
    $t->setTokenAuth($tokenAuth);
    $t->setIp($logHash["ip"]);
    $t->setForceVisitDateTime($logHash["utcdatetime"]);
    $t->setUrlReferrer($logHash["referer"]);
    $t->setUrl($webUrl . $logHash["path"]);
    $HTTPResult = false;
    $HTTPFailCount = 0;
    do {
        $HTTPResult = $t->doTrackPageView(basename($logHash["path"]));
        if (!$HTTPResult) {
            $HTTPFailCount++;
            echo "FAIL\n";
            echo "Unable to save (via HTTP) last log entry for the {$HTTPFailCount} time, retrying in a few seconds...\n";
            sleep($HTTPFailCount);
        } else {
            echo "SUCCESS\n";
        }
    } while (!$HTTPResult);
}
Exemplo n.º 4
0
<?php

include '../../includes/config.php';
require_once '../../includes/PiwikTracker.php';
PiwikTracker::$URL = get_page_url('stats', $CONF) . '/piwik.php';
$fileURL = $_GET['file'];
$file_db = $db->select('uploads', "url=? LIMIT 1", array($fileURL));
$file_path = $CONF['upload_dir'] . $file_db['filename'];
$temp_path = sys_get_temp_dir() . "\\" . $file_db['filename'];
if (file_exists($file_path) && $file_db) {
    $t = new PiwikTracker($idSite = 1);
    $t->setUserAgent($_SERVER['HTTP_USER_AGENT']);
    $t->setUrlReferrer($_SERVER['HTTP_REFERER']);
    $t->setUrl($url = get_page_url('u', $CONF) . '/' . $fileURL);
    $t->doTrackPageView('Teknik Upload - ' . $fileURL);
    if ($file_db['hash'] != "") {
        $crypt = new Cryptography();
        $result = $crypt->Decrypt($CONF['key'], $file_db['hash'], $file_path, $temp_path, $file_db['cipher']);
        if ($result) {
            $file_path = $temp_path;
        }
    }
    $file_type = $file_db['type'];
    $pattern = "/^((image)|(text)|(audio)|(video))\\/(.*)\$/";
    if (!preg_match($pattern, $file_type)) {
        header("Content-Disposition: attachment; filename=\"" . $file_db['filename'] . "\"");
        header("Pragma: public");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header('Content-Type: ' . $file_type);
        header('Content-Length: ' . $file_db['filesize']);
        set_time_limit(0);
Exemplo n.º 5
0
 private function trackPageview(\PiwikTracker $tracker, $userId, $url = null)
 {
     if (null !== $url) {
         $tracker->setUrl('http://www.example.org' . $url);
     }
     $tracker->setUserId($userId);
     $title = $url ?: 'test';
     $tracker->doTrackPageView($title);
 }
Exemplo n.º 6
0
/**
 * 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;
    }
}
Exemplo n.º 7
0
function piwik_analytics($aid, $purl, $name, $go, $html = 1)
{
    require_once dirname(__FILE__) . '/lib/PiwikTracker.php';
    global $blog_settings;
    if (empty($go)) {
        $go = $_SERVER['PHP_SELF'];
    }
    PiwikTracker::$URL = $blog_settings->get('piwik_url');
    $screen_resolution = "1280x800";
    if (!isset($_SESSION[iterate]) && $html) {
        if (!isset($_COOKIE["piwik_user_resolution"])) {
            //means cookie is not found set it using Javascript
            $_SESSION[iterate] = 1;
            ?>
<script language="javascript"><!--
	writeCookie();
	function writeCookie() {
		var the_cookie = "piwik_user_resolution="+ screen.width +"x"+ screen.height;
		document.cookie=the_cookie
		location ='<?php 
            echo $go;
            ?>
';
	}
//--></script>
<?php 
        } else {
            $screen_resolution = $_COOKIE["piwik_user_resolution"];
        }
    } else {
        $screen_resolution = $_COOKIE["users_resolution"];
    }
    $screen_resolution = preg_split('x', $screen_resolution);
    $t = new PiwikTracker($idSite = $aid, $blog_settings->get('piwik_url'));
    // Optional tracking
    $t->setUserAgent($_SERVER['HTTP_USER_AGENT']);
    $t->setBrowserLanguage(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2));
    $t->setLocalTime(date("H:i:s"));
    $t->setResolution($screen_resolution[0], $screen_resolution[1]);
    // Mandatory
    $t->setUrl($url = $purl);
    $t->doTrackPageView($name);
}
Exemplo n.º 8
-1
function track($campaign, $keyword)
{
    # Piwik URL
    PiwikTracker::$URL = $GLOBALS['config']['piwik_url'];
    # PiwikTracker
    $piwik = new PiwikTracker($GLOBALS['config']['idsite']);
    # required for setIP()
    $piwik->setTokenAuth($GLOBALS['config']['piwik_token']);
    # IP of the remote client
    $piwik->setIP($_SERVER['REMOTE_ADDR']);
    # User Agent String of the client
    $piwik->setUserAgent($_SERVER['HTTP_USER_AGENT']);
    # get the schema
    $schema = 'https://';
    if (empty($_SERVER['HTTPS']) or $_SERVER['HTTPS'] === 'off') {
        $schema = 'http://';
    }
    # set the tracked URL
    $piwik->setUrl($schema . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
    # referer
    $piwik->setUrlReferrer($_SERVER['HTTP_REFERER']);
    # set attribution info (keyword, campaign, et al)
    # http://developer.piwik.org/api-reference/PHP-Piwik-Tracker#setattributioninfo
    # 0 - campaign name
    # 1 - keyword
    # 2 - timestamp
    # 3 - referrer
    $att = json_encode(array($campaign, $keyword, time(), $_SERVER['HTTP_REFERER']));
    $piwik->setAttributionInfo($att);
    if (defined("DEBUG") and DEBUG) {
        header("X-Debug-Referred: from " . $_SERVER['HTTP_REFERER']);
        header("X-Debug-AttInfo: {$att}");
    }
    # do track the page view
    if (empty($keyword)) {
        $keyword = 'none';
    }
    $piwik->doTrackPageView("Reprint Tracker for: {$campaign} (keyword: {$keyword})");
    if (defined("DEBUG") and DEBUG) {
        header('X-Last-Piwik-Call: ' . $piwik::$DEBUG_LAST_REQUESTED_URL);
    }
}