Builds URL to track a page view.
public getUrlTrackPageView ( string $documentTitle = '' ) : string | ||
$documentTitle | string | Page view name as it will appear in Piwik reports |
Результат | string | URL to piwik.php with all parameters set to track the pageview |
public function test_response_ShouldSend400ResponseCode_IfInvalidRequestParameterIsGiven() { $url = $this->tracker->getUrlTrackPageView('Test'); $url .= '&cid=' . str_pad('1', 16, '1'); $this->assertResponseCode(200, $url); $this->assertResponseCode(400, $url . '1'); // has to be 16 char, but is 17 now }
/** * Helper function to quickly generate the URL to track a page view. * * @param $idSite * @param string $documentTitle * @return string */ function Piwik_getUrlTrackPageView($idSite, $documentTitle = '') { $tracker = new PiwikTracker($idSite); return $tracker->getUrlTrackPageView($documentTitle); }
<?php // Script that creates 100 websites, then outputs a IMG that records a pageview in each website // Used initially to test how to handle cookies for this use case (see http://dev.piwik.org/trac/ticket/409) exit; define('PIWIK_INCLUDE_PATH', '..'); define('PIWIK_ENABLE_DISPATCH', false); define('PIWIK_ENABLE_ERROR_HANDLER', false); define('PIWIK_ENABLE_SESSION_START', false); require_once PIWIK_INCLUDE_PATH . "/index.php"; require_once PIWIK_INCLUDE_PATH . "/core/API/Request.php"; require_once PIWIK_INCLUDE_PATH . "/libs/PiwikTracker/PiwikTracker.php"; Piwik_FrontController::getInstance()->init(); Piwik::setUserIsSuperUser(); $count = 100; for($i = 0; $i <= $count; $i++) { $id = Piwik_SitesManager_API::getInstance()->addSite(Piwik_Common::getRandomString(), 'http://piwik.org'); $t = new PiwikTracker($id, 'http://localhost/trunk/piwik.php'); echo $id . " <img width=100 height=10 border=1 src='".$t->getUrlTrackPageView('title') ."'><br/>"; }
/** * Test setting/getting the first party cookie via the PHP Tracking Client * @param $t */ private function testFirstPartyCookies(PiwikTracker $t) { $domainHash = $this->getFirstPartyCookieDomainHash(); $idCookieName = '_pk_id_1_' . $domainHash; $refCookieName = '_pk_ref_1_' . $domainHash; $customVarCookieName = '_pk_cvar_1_' . $domainHash; $viewts = '1302307497'; $uuid = 'ca0afe7b6b692ff5'; $_COOKIE[$idCookieName] = $uuid . '.1302307497.1.' . $viewts . '.1302307497'; $_COOKIE[$refCookieName] = '["YEAH","RIGHT!",1302307497,"http://referrer.example.org/page/sub?query=test&test2=test3"]'; $_COOKIE[$customVarCookieName] = '{"1":["VAR 1 set, var 2 not set","yes"],"3":["var 3 set","yes!!!!"]}'; // test loading 'id' cookie self::assertContains("_viewts=" . $viewts, $t->getUrlTrackPageView()); self::assertEquals($uuid, $t->getVisitorId()); self::assertEquals($t->getAttributionInfo(), $_COOKIE[$refCookieName]); self::assertEquals(array("VAR 1 set, var 2 not set", "yes"), $t->getCustomVariable(1)); self::assertFalse($t->getCustomVariable(2)); self::assertEquals(array("var 3 set", "yes!!!!"), $t->getCustomVariable(3)); self::assertFalse($t->getCustomVariable(4)); self::assertFalse($t->getCustomVariable(5)); self::assertFalse($t->getCustomVariable(6)); self::assertFalse($t->getCustomVariable(-1)); unset($_COOKIE[$idCookieName]); unset($_COOKIE[$refCookieName]); unset($_COOKIE[$customVarCookieName]); }