/** * Returns a PiwikTracker object that you can then use to track pages or goals. * * @param $idSite * @param $dateTime * @param boolean $defaultInit If set to true, the tracker object will have default IP, user agent, time, resolution, etc. * * @return PiwikTracker */ public static function getTracker($idSite, $dateTime, $defaultInit = true, $useLocal = false) { if ($useLocal) { require_once PIWIK_INCLUDE_PATH . '/tests/LocalTracker.php'; $t = new Piwik_LocalTracker($idSite, self::getTrackerUrl()); } else { $t = new PiwikTracker($idSite, self::getTrackerUrl()); } $t->setForceVisitDateTime($dateTime); if ($defaultInit) { $t->setIp('156.5.3.2'); // Optional tracking $t->setUserAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)"); $t->setBrowserLanguage('fr'); $t->setLocalTime('12:34:06'); $t->setResolution(1024, 768); $t->setBrowserHasCookies(true); $t->setPlugins($flash = true, $java = true, $director = false); } return $t; }
private function doPingRequest(\PiwikTracker $tracker, $pingTime, $changeDimensionValues) { if ($changeDimensionValues) { $tracker->setUserAgent(self::CHANGED_USER_AGENT); $tracker->setBrowserLanguage(self::CHANGED_BROWSER_LANGUAGE); $tracker->setCountry(self::CHANGED_COUNTRY); $tracker->setRegion(self::CHANGED_REGION); } $tracker->setForceVisitDateTime($pingTime); $response = $tracker->doPing(); Fixture::checkResponse($response); return $response; }
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); }
/** * Inicia a análise de tráfego. */ private function iniciarAnaliseTrafego() { if ($this->_configuracao->get($this->_servidor . '.piwik_id')) { require_once implode(DIRECTORY_SEPARATOR, [__DIR__, '..', '..', '..', '..', 'library', 'PiwikTracker.php']); $piwikTracker = new \PiwikTracker($this->_configuracao->get($this->_servidor . '.piwik_id'), $this->_configuracao->get($this->_servidor . '.piwik_url')); if ($this->_configuracao->get($this->_servidor . '.piwik_token_auth')) { $piwikTracker->setTokenAuth($this->_configuracao->get($this->_servidor . '.piwik_token_auth')); } if (isset($_SERVER['HTTP_REFERER'])) { $piwikTracker->setReferrer($_SERVER['HTTP_REFERER']); } // detecta o endereço da internet do cliente if (isset($_SERVER['HTTP_CLIENT_IP'])) { $piwikTracker->setIp($_SERVER['HTTP_CLIENT_IP']); } else { if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $piwikTracker->setIp($_SERVER['HTTP_X_FORWARDED_FOR']); } else { if (isset($_SERVER['HTTP_X_FORWARDED'])) { $piwikTracker->setIp($_SERVER['HTTP_X_FORWARDED']); } else { if (isset($_SERVER['HTTP_FORWARDED_FOR'])) { $piwikTracker->setIp($_SERVER['HTTP_FORWARDED_FOR']); } else { if (isset($_SERVER['HTTP_FORWARDED'])) { $piwikTracker->setIp($_SERVER['HTTP_FORWARDED']); } else { if (isset($_SERVER['REMOTE_ADDR'])) { $piwikTracker->setIp($_SERVER['REMOTE_ADDR']); } else { $piwikTracker->setIp('DESCONHECIDO'); } } } } } } $piwikTracker->setUserAgent($_SERVER['HTTP_USER_AGENT']); if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $idioma = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); $piwikTracker->setBrowserLanguage($idioma[0]); unset($idioma); } if ($this->postExists('localTime')) { $piwikTracker->setLocalTime($this->post('localTime')); } if ($this->postExists('screenWidth') && $this->postExists('screenHeight')) { $piwikTracker->setResolution($this->post('screenWidth'), $this->post('screenHeight')); } if ($this->postExists('position')) { $posicao = $this->post('position'); $piwikTracker->setLongitude($posicao['longitude']); $piwikTracker->setLatitude($posicao['latitude']); unset($posicao); } } else { $piwikTracker = null; } return $piwikTracker; }
<?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);
/** * Returns a PiwikTracker object that you can then use to track pages or goals. * * @param $idSite * @param $dateTime * @param $defaultInit If set to true, the tracker object will have default IP, user agent, time, resolution, etc. * @return PiwikTracker */ protected function getTracker($idSite, $dateTime, $defaultInit = true) { $t = new PiwikTracker($idSite, $this->getTrackerUrl()); $t->setForceVisitDateTime($dateTime); if ($defaultInit) { $t->setIp('156.5.3.2'); // Optional tracking $t->setUserAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)"); $t->setBrowserLanguage('fr'); $t->setLocalTime('12:34:06'); $t->setResolution(1024, 768); $t->setBrowserHasCookies(true); $t->setPlugins($flash = true, $java = true, $director = false); } return $t; }
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); }
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); } }