本文整理汇总了PHP中Piwik\Tracker\PageUrl类的典型用法代码示例。如果您正苦于以下问题:PHP PageUrl类的具体用法?PHP PageUrl怎么用?PHP PageUrl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PageUrl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getReferrerInformation
/**
* Returns an array containing the following information:
* - referer_type
* - direct -- absence of referrer URL OR referrer URL has the same host
* - site -- based on the referrer URL
* - search_engine -- based on the referrer URL
* - campaign -- based on campaign URL parameter
*
* - referer_name
* - ()
* - piwik.net -- site host name
* - google.fr -- search engine host name
* - adwords-search -- campaign name
*
* - referer_keyword
* - ()
* - ()
* - my keyword
* - my paid keyword
* - ()
* - ()
*
* - referer_url : the same for all the referrer types
*
* @param string $referrerUrl must be URL Encoded
* @param string $currentUrl
* @param int $idSite
* @return array
*/
public function getReferrerInformation($referrerUrl, $currentUrl, $idSite)
{
$this->idsite = $idSite;
// default values for the referer_* fields
$referrerUrl = Common::unsanitizeInputValue($referrerUrl);
if (!empty($referrerUrl) && !UrlHelper::isLookLikeUrl($referrerUrl)) {
$referrerUrl = '';
}
$currentUrl = PageUrl::cleanupUrl($currentUrl);
$this->referrerUrl = $referrerUrl;
$this->referrerUrlParse = @parse_url($this->referrerUrl);
$this->currentUrlParse = @parse_url($currentUrl);
$this->typeReferrerAnalyzed = Common::REFERRER_TYPE_DIRECT_ENTRY;
$this->nameReferrerAnalyzed = '';
$this->keywordReferrerAnalyzed = '';
$this->referrerHost = '';
if (isset($this->referrerUrlParse['host'])) {
$this->referrerHost = $this->referrerUrlParse['host'];
}
$referrerDetected = $this->detectReferrerCampaign();
if (!$referrerDetected) {
if ($this->detectReferrerDirectEntry() || $this->detectReferrerSearchEngine()) {
$referrerDetected = true;
}
}
if (!empty($this->referrerHost) && !$referrerDetected) {
$this->typeReferrerAnalyzed = Common::REFERRER_TYPE_WEBSITE;
$this->nameReferrerAnalyzed = Common::mb_strtolower($this->referrerHost);
}
$referrerInformation = array('referer_type' => $this->typeReferrerAnalyzed, 'referer_name' => $this->nameReferrerAnalyzed, 'referer_keyword' => $this->keywordReferrerAnalyzed, 'referer_url' => $this->referrerUrl);
return $referrerInformation;
}
示例2: renderSidebar
/** Render the area left of the iframe */
public function renderSidebar()
{
$idSite = Common::getRequestVar('idSite');
$period = Common::getRequestVar('period');
$date = Common::getRequestVar('date');
$currentUrl = Common::getRequestVar('currentUrl');
$currentUrl = Common::unsanitizeInputValue($currentUrl);
$normalizedCurrentUrl = PageUrl::excludeQueryParametersFromUrl($currentUrl, $idSite);
$normalizedCurrentUrl = Common::unsanitizeInputValue($normalizedCurrentUrl);
// load the appropriate row of the page urls report using the label filter
ArchivingHelper::reloadConfig();
$path = ArchivingHelper::getActionExplodedNames($normalizedCurrentUrl, Action::TYPE_PAGE_URL);
$path = array_map('urlencode', $path);
$label = implode('>', $path);
$request = new Request('method=Actions.getPageUrls' . '&idSite=' . urlencode($idSite) . '&date=' . urlencode($date) . '&period=' . urlencode($period) . '&label=' . urlencode($label) . '&format=original' . '&format_metrics=0');
$dataTable = $request->process();
$formatter = new Metrics\Formatter\Html();
$data = array();
if ($dataTable->getRowsCount() > 0) {
$row = $dataTable->getFirstRow();
$translations = Metrics::getDefaultMetricTranslations();
$showMetrics = array('nb_hits', 'nb_visits', 'nb_users', 'nb_uniq_visitors', 'bounce_rate', 'exit_rate', 'avg_time_on_page');
foreach ($showMetrics as $metric) {
$value = $row->getColumn($metric);
if ($value === false) {
// skip unique visitors for period != day
continue;
}
if ($metric == 'bounce_rate' || $metric == 'exit_rate') {
$value = $formatter->getPrettyPercentFromQuotient($value);
} else {
if ($metric == 'avg_time_on_page') {
$value = $formatter->getPrettyTimeFromSeconds($value, $displayAsSentence = true);
}
}
$data[] = array('name' => $translations[$metric], 'value' => $value);
}
}
// generate page url string
foreach ($path as &$part) {
$part = preg_replace(';^/;', '', urldecode($part));
}
$page = '/' . implode('/', $path);
$page = preg_replace(';/index$;', '/', $page);
if ($page == '/') {
$page = '/index';
}
// render template
$view = new View('@Overlay/renderSidebar');
$view->data = $data;
$view->location = $page;
$view->normalizedUrl = $normalizedCurrentUrl;
$view->label = $label;
$view->idSite = $idSite;
$view->period = $period;
$view->date = $date;
$this->outputCORSHeaders();
return $view->render();
}
示例3: getActionsToLookup
protected function getActionsToLookup()
{
$actionUrl = false;
$url = $this->getActionUrl();
if (!empty($url)) {
// normalize urls by stripping protocol and www
$url = Tracker\PageUrl::normalizeUrl($url);
$actionUrl = array($url['url'], $this->getActionType(), $url['prefixId']);
}
return array('idaction_url' => $actionUrl);
}
示例4: getCampaignInformation
/**
* Returns the extracted utm details from the url
* @param string $currentUrl
* @param int $idSite
* @param Request $request
* @return array
*/
private function getCampaignInformation($currentUrl, $idSite, Request $request)
{
$cacheKey = $currentUrl . $idSite;
if (isset(self::$cachedReferrer[$cacheKey])) {
return self::$cachedReferrer[$cacheKey];
}
$currentUrl = PageUrl::cleanupUrl($currentUrl);
$this->currentUrlParse = @parse_url($currentUrl);
$utmInformation = $this->extractUtmDetailsFromUrl();
self::$cachedReferrer[$cacheKey] = $utmInformation;
return $utmInformation;
}
示例5: getReferrerInformation
/**
* Returns an array containing the following information:
* - referer_type
* - direct -- absence of referrer URL OR referrer URL has the same host
* - site -- based on the referrer URL
* - search_engine -- based on the referrer URL
* - campaign -- based on campaign URL parameter
*
* - referer_name
* - ()
* - piwik.net -- site host name
* - google.fr -- search engine host name
* - adwords-search -- campaign name
*
* - referer_keyword
* - ()
* - ()
* - my keyword
* - my paid keyword
* - ()
* - ()
*
* - referer_url : the same for all the referrer types
*
* @param string $referrerUrl must be URL Encoded
* @param string $currentUrl
* @param int $idSite
* @return array
*/
protected function getReferrerInformation($referrerUrl, $currentUrl, $idSite, Request $request)
{
$cacheKey = $referrerUrl . $currentUrl . $idSite;
if (isset(self::$cachedReferrer[$cacheKey])) {
return self::$cachedReferrer[$cacheKey];
}
$this->idsite = $idSite;
// default values for the referer_* fields
$referrerUrl = Common::unsanitizeInputValue($referrerUrl);
if (!empty($referrerUrl) && !UrlHelper::isLookLikeUrl($referrerUrl)) {
$referrerUrl = '';
}
$currentUrl = PageUrl::cleanupUrl($currentUrl);
$this->referrerUrl = $referrerUrl;
$this->referrerUrlParse = @parse_url($this->referrerUrl);
$this->currentUrlParse = @parse_url($currentUrl);
$this->typeReferrerAnalyzed = Common::REFERRER_TYPE_DIRECT_ENTRY;
$this->nameReferrerAnalyzed = '';
$this->keywordReferrerAnalyzed = '';
$this->referrerHost = '';
if (isset($this->referrerUrlParse['host'])) {
$this->referrerHost = $this->referrerUrlParse['host'];
}
$referrerDetected = $this->detectReferrerCampaign($request);
if (!$referrerDetected) {
if ($this->detectReferrerDirectEntry() || $this->detectReferrerSearchEngine()) {
$referrerDetected = true;
}
}
if (!$referrerDetected && !empty($this->referrerHost)) {
$this->typeReferrerAnalyzed = Common::REFERRER_TYPE_WEBSITE;
$this->nameReferrerAnalyzed = Common::mb_strtolower($this->referrerHost);
$urlsByHost = $this->getCachedUrlsByHostAndIdSite();
$directEntry = new SiteUrls();
$path = $directEntry->getPathMatchingUrl($this->referrerUrlParse, $urlsByHost);
if (!empty($path) && $path !== '/') {
$this->nameReferrerAnalyzed .= rtrim($path, '/');
}
}
$referrerInformation = array('referer_type' => $this->typeReferrerAnalyzed, 'referer_name' => $this->nameReferrerAnalyzed, 'referer_keyword' => $this->keywordReferrerAnalyzed, 'referer_url' => $this->referrerUrl);
self::$cachedReferrer[$cacheKey] = $referrerInformation;
return $referrerInformation;
}
示例6: getFollowingPages
/**
* Get following pages of a url.
* This is done on the logs - not the archives!
*
* Note: if you use this method via the regular API, the number of results will be limited.
* Make sure, you set filter_limit=-1 in the request.
*/
public function getFollowingPages($url, $idSite, $period, $date, $segment = false)
{
$this->authenticate($idSite);
$url = PageUrl::excludeQueryParametersFromUrl($url, $idSite);
// we don't unsanitize $url here. it will be done in the Transitions plugin.
$resultDataTable = new DataTable();
try {
$limitBeforeGrouping = Config::getInstance()->General['overlay_following_pages_limit'];
$transitionsReport = APITransitions::getInstance()->getTransitionsForAction($url, $type = 'url', $idSite, $period, $date, $segment, $limitBeforeGrouping, $part = 'followingActions', $returnNormalizedUrls = true);
} catch (Exception $e) {
return $resultDataTable;
}
$reports = array('followingPages', 'outlinks', 'downloads');
foreach ($reports as $reportName) {
if (!isset($transitionsReport[$reportName])) {
continue;
}
foreach ($transitionsReport[$reportName]->getRows() as $row) {
// don't touch the row at all for performance reasons
$resultDataTable->addRow($row);
}
}
return $resultDataTable;
}
示例7: getPageLabel
private function getPageLabel(&$pageRecord, $type)
{
if ($type == Action::TYPE_PAGE_TITLE) {
$label = $pageRecord['name'];
if (empty($label)) {
$label = ArchivingHelper::getUnknownActionName(Action::TYPE_PAGE_TITLE);
}
return $label;
}
if ($type == Action::TYPE_OUTLINK || $type == Action::TYPE_DOWNLOAD) {
return PageUrl::reconstructNormalizedUrl($pageRecord['name'], $pageRecord['url_prefix']);
}
return $pageRecord['name'];
}
示例8: getFilterPageDatatableSearch
/**
* Will search in the DataTable for a Label matching the searched string
* and return only the matching row, or an empty datatable
*/
protected function getFilterPageDatatableSearch($callBackParameters, $search, $actionType, $table = false, $searchTree = false)
{
if ($searchTree === false) {
// build the query parts that are searched inside the tree
if ($actionType == Action::TYPE_PAGE_TITLE) {
$searchedString = Common::unsanitizeInputValue($search);
} else {
$idSite = $callBackParameters[1];
try {
$searchedString = PageUrl::excludeQueryParametersFromUrl($search, $idSite);
} catch (Exception $e) {
$searchedString = $search;
}
}
ArchivingHelper::reloadConfig();
$searchTree = ArchivingHelper::getActionExplodedNames($searchedString, $actionType);
}
if ($table === false) {
// fetch the data table
$table = call_user_func_array(array($this, 'getDataTableFromArchive'), $callBackParameters);
if ($table instanceof DataTable\Map) {
// search an array of tables, e.g. when using date=last30
// note that if the root is an array, we filter all children
// if an array occurs inside the nested table, we only look for the first match (see below)
$dataTableMap = $table->getEmptyClone();
foreach ($table->getDataTables() as $label => $subTable) {
$newSubTable = $this->doFilterPageDatatableSearch($callBackParameters, $subTable, $searchTree);
$dataTableMap->addTable($newSubTable, $label);
}
return $dataTableMap;
}
}
return $this->doFilterPageDatatableSearch($callBackParameters, $table, $searchTree);
}
示例9: detectGoalId
public function detectGoalId($idSite)
{
if (!Common::isGoalPluginEnabled()) {
return false;
}
$goals = $this->getGoalDefinitions($idSite);
if (!isset($goals[$this->idGoal])) {
return false;
}
$goal = $goals[$this->idGoal];
$url = $this->request->getParam('url');
$goal['url'] = PageUrl::excludeQueryParametersFromUrl($url, $idSite);
$this->convertedGoals[] = $goal;
return true;
}
示例10: getUrlIfLookValid
public static function getUrlIfLookValid($url)
{
$url = PageUrl::cleanupString($url);
if (!UrlHelper::isLookLikeUrl($url)) {
Common::printDebug("WARNING: URL looks invalid and is discarded");
return false;
}
return $url;
}
示例11: detectSiteSearch
protected function detectSiteSearch($originalUrl)
{
$website = Cache::getCacheWebsiteAttributes($this->request->getIdSite());
if (empty($website['sitesearch'])) {
Common::printDebug("Internal 'Site Search' tracking is not enabled for this site. ");
return false;
}
$actionName = $url = $categoryName = $count = false;
$originalUrl = PageUrl::cleanupUrl($originalUrl);
// Detect Site search from Tracking API parameters rather than URL
$searchKwd = $this->request->getParam('search');
if (!empty($searchKwd)) {
$actionName = $searchKwd;
$isCategoryName = $this->request->getParam('search_cat');
if (!empty($isCategoryName)) {
$categoryName = $isCategoryName;
}
$isCount = $this->request->getParam('search_count');
if ($this->isValidSearchCount($isCount)) {
$count = $isCount;
}
}
if (empty($actionName)) {
$parsedUrl = @parse_url($originalUrl);
// Detect Site Search from URL query parameters
if (!empty($parsedUrl['query']) || !empty($parsedUrl['fragment'])) {
// array($url, $actionName, $categoryName, $count);
$searchInfo = $this->detectSiteSearchFromUrl($website, $parsedUrl);
if (!empty($searchInfo)) {
list($url, $actionName, $categoryName, $count) = $searchInfo;
}
}
}
$actionName = trim($actionName);
$categoryName = trim($categoryName);
if (empty($actionName)) {
Common::printDebug("(this is not a Site Search request)");
return false;
}
Common::printDebug("Detected Site Search keyword '{$actionName}'. ");
if (!empty($categoryName)) {
Common::printDebug("- Detected Site Search Category '{$categoryName}'. ");
}
if ($count !== false) {
Common::printDebug("- Search Results Count was '{$count}'. ");
}
if ($url != $originalUrl) {
Common::printDebug("NOTE: The Page URL was changed / removed, during the Site Search detection, was '{$originalUrl}', now is '{$url}'");
}
return array($actionName, $url, $categoryName, $count);
}
示例12: enrichVisitorArrayWithActions
/**
* @param $visitorDetailsArray
* @param $actionsLimit
* @param $timezone
* @return array
*/
public static function enrichVisitorArrayWithActions($visitorDetailsArray, $actionsLimit, $timezone)
{
$idVisit = $visitorDetailsArray['idVisit'];
$model = new Model();
$actionDetails = $model->queryActionsForVisit($idVisit, $actionsLimit);
$formatter = new Formatter();
$maxCustomVariables = CustomVariables::getNumUsableCustomVariables();
foreach ($actionDetails as $actionIdx => &$actionDetail) {
$actionDetail =& $actionDetails[$actionIdx];
$customVariablesPage = array();
for ($i = 1; $i <= $maxCustomVariables; $i++) {
if (!empty($actionDetail['custom_var_k' . $i])) {
$cvarKey = $actionDetail['custom_var_k' . $i];
$cvarKey = static::getCustomVariablePrettyKey($cvarKey);
$customVariablesPage[$i] = array('customVariablePageName' . $i => $cvarKey, 'customVariablePageValue' . $i => $actionDetail['custom_var_v' . $i]);
}
unset($actionDetail['custom_var_k' . $i]);
unset($actionDetail['custom_var_v' . $i]);
}
if (!empty($customVariablesPage)) {
$actionDetail['customVariables'] = $customVariablesPage;
}
if ($actionDetail['type'] == Action::TYPE_CONTENT) {
unset($actionDetails[$actionIdx]);
continue;
} elseif ($actionDetail['type'] == Action::TYPE_EVENT) {
// Handle Event
if (strlen($actionDetail['pageTitle']) > 0) {
$actionDetail['eventName'] = $actionDetail['pageTitle'];
}
unset($actionDetail['pageTitle']);
} else {
if ($actionDetail['type'] == Action::TYPE_SITE_SEARCH) {
// Handle Site Search
$actionDetail['siteSearchKeyword'] = $actionDetail['pageTitle'];
unset($actionDetail['pageTitle']);
}
}
// Event value / Generation time
if ($actionDetail['type'] == Action::TYPE_EVENT) {
if (strlen($actionDetail['custom_float']) > 0) {
$actionDetail['eventValue'] = round($actionDetail['custom_float'], self::EVENT_VALUE_PRECISION);
}
} elseif ($actionDetail['custom_float'] > 0) {
$actionDetail['generationTime'] = $formatter->getPrettyTimeFromSeconds($actionDetail['custom_float'] / 1000, true);
}
unset($actionDetail['custom_float']);
if ($actionDetail['type'] != Action::TYPE_EVENT) {
unset($actionDetail['eventCategory']);
unset($actionDetail['eventAction']);
}
// Reconstruct url from prefix
$url = Tracker\PageUrl::reconstructNormalizedUrl($actionDetail['url'], $actionDetail['url_prefix']);
$url = Common::unsanitizeInputValue($url);
$actionDetail['url'] = $url;
unset($actionDetail['url_prefix']);
}
// If the visitor converted a goal, we shall select all Goals
$goalDetails = $model->queryGoalConversionsForVisit($idVisit, $actionsLimit);
$ecommerceDetails = $model->queryEcommerceConversionsForVisit($idVisit, $actionsLimit);
foreach ($ecommerceDetails as &$ecommerceDetail) {
if ($ecommerceDetail['type'] == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART) {
unset($ecommerceDetail['orderId']);
unset($ecommerceDetail['revenueSubTotal']);
unset($ecommerceDetail['revenueTax']);
unset($ecommerceDetail['revenueShipping']);
unset($ecommerceDetail['revenueDiscount']);
}
// 25.00 => 25
foreach ($ecommerceDetail as $column => $value) {
if (strpos($column, 'revenue') !== false) {
if ($value == round($value)) {
$ecommerceDetail[$column] = round($value);
}
}
}
}
// Enrich ecommerce carts/orders with the list of products
usort($ecommerceDetails, array('static', 'sortByServerTime'));
foreach ($ecommerceDetails as &$ecommerceConversion) {
$idOrder = isset($ecommerceConversion['orderId']) ? $ecommerceConversion['orderId'] : GoalManager::ITEM_IDORDER_ABANDONED_CART;
$itemsDetails = $model->queryEcommerceItemsForOrder($idVisit, $idOrder, $actionsLimit);
foreach ($itemsDetails as &$detail) {
if ($detail['price'] == round($detail['price'])) {
$detail['price'] = round($detail['price']);
}
}
$ecommerceConversion['itemDetails'] = $itemsDetails;
}
// Enrich with time spent per action
foreach ($actionDetails as $actionIdx => &$actionDetail) {
// Set the time spent for this action (which is the timeSpentRef of the next action)
$nextActionFound = isset($actionDetails[$actionIdx + 1]);
if ($nextActionFound) {
//.........这里部分代码省略.........
示例13: detectGoalId
public function detectGoalId($idSite, Request $request)
{
if (!Common::isGoalPluginEnabled()) {
return null;
}
$idGoal = $request->getParam('idgoal');
$goals = $this->getGoalDefinitions($idSite);
if (!isset($goals[$idGoal])) {
return null;
}
$goal = $goals[$idGoal];
$url = $request->getParam('url');
$goal['url'] = PageUrl::excludeQueryParametersFromUrl($url, $idSite);
return $goal;
}
示例14: parseNameFromPageUrl
private static function parseNameFromPageUrl($name, $type, $urlPrefix)
{
$urlRegexAfterDomain = '([^/]+)[/]?([^#]*)[#]?(.*)';
if ($urlPrefix === null) {
// match url with protocol (used for outlinks / downloads)
$urlRegex = '@^http[s]?://' . $urlRegexAfterDomain . '$@i';
} else {
// the name is a url that does not contain protocol and www anymore
// we know that normalization has been done on db level because $urlPrefix is set
$urlRegex = '@^' . $urlRegexAfterDomain . '$@i';
}
$matches = array();
preg_match($urlRegex, $name, $matches);
if (!count($matches)) {
return $name;
}
$urlHost = $matches[1];
$urlPath = $matches[2];
$urlFragment = $matches[3];
if (in_array($type, array(Action::TYPE_DOWNLOAD, Action::TYPE_OUTLINK))) {
$path = '/' . trim($urlPath);
if (!empty($urlFragment)) {
$path .= '#' . $urlFragment;
}
return array(trim($urlHost), $path);
}
$name = $urlPath;
if ($name === '' || substr($name, -1) == '/') {
$name .= self::$defaultActionName;
}
$urlFragment = PageUrl::processUrlFragment($urlFragment);
if (!empty($urlFragment)) {
$name .= '#' . $urlFragment;
}
return $name;
}
示例15: aggregateFromActions
protected function aggregateFromActions($valueField)
{
$resultSet = $this->queryCustomDimensionActions($this->dataArray, $valueField);
while ($row = $resultSet->fetch()) {
$label = $row[$valueField];
$label = $this->cleanCustomDimensionValue($label);
$this->dataArray->sumMetricsActions($label, $row);
// make sure we always work with normalized URL no matter how the individual action stores it
$normalized = Tracker\PageUrl::normalizeUrl($row['url']);
$row['url'] = $normalized['url'];
$subLabel = $row['url'];
if (empty($subLabel)) {
continue;
}
$this->dataArray->sumMetricsActionCustomDimensionsPivot($label, $subLabel, $row);
}
}