Skip to content

Commit

Permalink
moved more logic from core to plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
tsteur committed Jun 13, 2014
1 parent 83ee5a4 commit fccdcc0
Show file tree
Hide file tree
Showing 25 changed files with 561 additions and 128 deletions.
13 changes: 1 addition & 12 deletions core/Db/Schema/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,22 +148,12 @@ public function getTablesCreateSql()
idvisit INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
idsite INTEGER(10) UNSIGNED NOT NULL,
idvisitor BINARY(8) NOT NULL,
visitor_localtime TIME NOT NULL,
visitor_returning TINYINT(1) NOT NULL,
visitor_count_visits SMALLINT(5) UNSIGNED NOT NULL,
visitor_days_since_last SMALLINT(5) UNSIGNED NOT NULL,
visitor_days_since_order SMALLINT(5) UNSIGNED NOT NULL,
visitor_days_since_first SMALLINT(5) UNSIGNED NOT NULL,
visit_first_action_time DATETIME NOT NULL,
visit_last_action_time DATETIME NOT NULL,
visit_total_actions SMALLINT(5) UNSIGNED NOT NULL,
visit_total_searches SMALLINT(5) UNSIGNED NOT NULL,
visit_total_events SMALLINT(5) UNSIGNED NOT NULL,
visit_total_time SMALLINT(5) UNSIGNED NOT NULL,
visit_goal_converted TINYINT(1) NOT NULL,
visit_goal_buyer TINYINT(1) NOT NULL,
visit_last_action_time DATETIME NOT NULL,
config_id BINARY(8) NOT NULL,
config_resolution VARCHAR(9) NOT NULL,
config_pdf TINYINT(1) NOT NULL,
config_flash TINYINT(1) NOT NULL,
config_java TINYINT(1) NOT NULL,
Expand All @@ -175,7 +165,6 @@ public function getTablesCreateSql()
config_silverlight TINYINT(1) NOT NULL,
config_cookie TINYINT(1) NOT NULL,
location_ip VARBINARY(16) NOT NULL,
location_browser_lang VARCHAR(20) NOT NULL,
location_country CHAR(3) NOT NULL,
location_region char(2) DEFAULT NULL,
location_city varchar(255) DEFAULT NULL,
Expand Down
8 changes: 8 additions & 0 deletions core/Plugin/Segment.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ public function setType($type)
$this->type = $type;
}

/**
* @return string
*/
public function getType()
{
return $this->type;
}

/**
* @param bool $permission
*/
Expand Down
6 changes: 5 additions & 1 deletion core/Plugin/VisitDimension.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ protected function addSegment(Segment $segment)
$segment->setSqlSegment('log_visit.' . $this->fieldName);
}

$segment->setType(Segment::TYPE_DIMENSION);
$type = $segment->getType();

if (empty($type)) {
$segment->setType(Segment::TYPE_DIMENSION);
}

$this->segments[] = $segment;
}
Expand Down
5 changes: 1 addition & 4 deletions core/Tracker/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ protected function loadInfo()
list($plugin_Flash, $plugin_Java, $plugin_Director, $plugin_Quicktime, $plugin_RealPlayer, $plugin_PDF,
$plugin_WindowsMedia, $plugin_Gears, $plugin_Silverlight, $plugin_Cookie) = $this->request->getPlugins();

$resolution = $this->request->getParam('res');
$userAgent = $this->request->getUserAgent();

$deviceDetector = new \DeviceDetector($userAgent);
Expand Down Expand Up @@ -67,7 +66,6 @@ protected function loadInfo()

$this->params = array(
'config_id' => $configurationHash,
'config_resolution' => $resolution,
'config_pdf' => $plugin_PDF,
'config_flash' => $plugin_Flash,
'config_java' => $plugin_Java,
Expand All @@ -77,8 +75,7 @@ protected function loadInfo()
'config_windowsmedia' => $plugin_WindowsMedia,
'config_gears' => $plugin_Gears,
'config_silverlight' => $plugin_Silverlight,
'config_cookie' => $plugin_Cookie,
'location_browser_lang' => $browserLang,
'config_cookie' => $plugin_Cookie
);
}

Expand Down
55 changes: 0 additions & 55 deletions core/Tracker/Visit.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ protected function handleNewVisit($action, $visitIsConverted)
$this->visitorInfo = array_merge($this->visitorInfo, $this->visitorCustomVariables);

$this->visitorInfo['visit_goal_converted'] = $visitIsConverted ? 1 : 0;
$this->visitorInfo['config_resolution'] = substr($this->visitorInfo['config_resolution'], 0, 9);

$dimensions = VisitDimension::getAllDimensions();
foreach ($dimensions as $dimension) {
Expand Down Expand Up @@ -505,22 +504,12 @@ protected function printVisitorInformation()

protected function getNewVisitorInformation($action)
{
$actionType = false;
if($action) {
$actionType = $action->getActionType();
}

$daysSinceFirstVisit = $this->request->getDaysSinceFirstVisit();
$visitCount = $this->request->getVisitCount();
$daysSinceLastVisit = $this->request->getDaysSinceLastVisit();

$daysSinceLastOrder = $this->request->getDaysSinceLastOrder();
$isReturningCustomer = ($daysSinceLastOrder !== false);

if ($daysSinceLastOrder === false) {
$daysSinceLastOrder = 0;
}

// User settings
$userInfo = $this->getSettingsObject();
$userInfo = $userInfo->getInfo();
Expand All @@ -534,28 +523,11 @@ protected function getNewVisitorInformation($action)

return array(
'idsite' => $this->request->getIdSite(),
'visitor_localtime' => $this->request->getLocalTime(),
'idvisitor' => $this->getVisitorIdcookie(),
'visitor_returning' => $visitorReturning,
'visitor_count_visits' => $visitCount,
'visitor_days_since_last' => $daysSinceLastVisit,
'visitor_days_since_order' => $daysSinceLastOrder,
'visitor_days_since_first' => $daysSinceFirstVisit,
'visit_first_action_time' => Tracker::getDatetimeFromTimestamp($this->request->getCurrentTimestamp()),
'visit_last_action_time' => Tracker::getDatetimeFromTimestamp($this->request->getCurrentTimestamp()),
'visit_total_actions' => in_array($actionType,
array(Action::TYPE_PAGE_URL,
Action::TYPE_DOWNLOAD,
Action::TYPE_OUTLINK,
Action::TYPE_SITE_SEARCH,
Action::TYPE_EVENT))
? 1 : 0, // if visit starts with something else (e.g. ecommerce order), don't record as an action
'visit_total_searches' => $actionType == Action::TYPE_SITE_SEARCH ? 1 : 0,
'visit_total_events' => $actionType == Action::TYPE_EVENT ? 1 : 0,
'visit_total_time' => self::cleanupVisitTotalTime($defaultTimeOnePageVisit),
'visit_goal_buyer' => $this->goalManager->getBuyerType(),
'config_id' => $userInfo['config_id'],
'config_resolution' => $userInfo['config_resolution'],
'config_pdf' => $userInfo['config_pdf'],
'config_flash' => $userInfo['config_flash'],
'config_java' => $userInfo['config_java'],
Expand All @@ -567,7 +539,6 @@ protected function getNewVisitorInformation($action)
'config_silverlight' => $userInfo['config_silverlight'],
'config_cookie' => $userInfo['config_cookie'],
'location_ip' => $this->getVisitorIp(),
'location_browser_lang' => $userInfo['location_browser_lang'],
);
}

Expand All @@ -582,32 +553,6 @@ protected function getExistingVisitFieldsToUpdate($action, $visitIsConverted)
{
$valuesToUpdate = array();

if ($action) {
$actionType = $action->getActionType();
$idActionUrl = $action->getIdActionUrlForEntryAndExitIds();

$incrementActions = false;

if ($idActionUrl !== false) {
$incrementActions = true;
}

if ($actionType == Action::TYPE_SITE_SEARCH) {
$valuesToUpdate['visit_total_searches'] = 'visit_total_searches + 1';
$incrementActions = true;
} else if ($actionType == Action::TYPE_EVENT) {
$valuesToUpdate['visit_total_events'] = 'visit_total_events + 1';
$incrementActions = true;
}

if ($incrementActions) {
$valuesToUpdate['visit_total_actions'] = 'visit_total_actions + 1';
}
}

$datetimeServer = Tracker::getDatetimeFromTimestamp($this->request->getCurrentTimestamp());
$valuesToUpdate['visit_last_action_time'] = $datetimeServer;

// Add 1 so it's always > 0
$visitTotalTime = 1 + $this->request->getCurrentTimestamp() - $this->visitorInfo['visit_first_action_time'];
$valuesToUpdate['visit_total_time'] = self::cleanupVisitTotalTime($visitTotalTime);
Expand Down
30 changes: 0 additions & 30 deletions plugins/API/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,6 @@ public function getSegmentsMetadata($idSites = array(), $_hideImplementationData
'sqlFilterValue' => array('Piwik\IP', 'P2N'),
'permission' => $isAuthenticatedWithViewAccess,
);
$segments[] = array(
'type' => 'metric',
'category' => Piwik::translate('General_Visit'),
'name' => 'General_NbActions',
'segment' => 'actions',
'sqlSegment' => 'log_visit.visit_total_actions',
);
$segments[] = array(
'type' => 'metric',
'category' => Piwik::translate('General_Visit'),
'name' => 'General_NbSearches',
'segment' => 'searches',
'sqlSegment' => 'log_visit.visit_total_searches',
'acceptedValues' => 'To select all visits who used internal Site Search, use: &segment=searches>0',
);
$segments[] = array(
'type' => 'metric',
'category' => Piwik::translate('General_Visit'),
Expand All @@ -220,21 +205,6 @@ public function getSegmentsMetadata($idSites = array(), $_hideImplementationData
'segment' => 'daysSinceLastVisit',
'sqlSegment' => 'log_visit.visitor_days_since_last',
);
$segments[] = array(
'type' => 'metric',
'category' => Piwik::translate('General_Visit'),
'name' => 'General_DaysSinceFirstVisit',
'segment' => 'daysSinceFirstVisit',
'sqlSegment' => 'log_visit.visitor_days_since_first',
);
$segments[] = array(
'type' => 'metric',
'category' => Piwik::translate('General_Visit'),
'name' => 'General_NumberOfVisits',
'segment' => 'visitCount',
'sqlSegment' => 'log_visit.visitor_count_visits',
);

$segments[] = array(
'type' => 'dimension',
'category' => Piwik::translate('General_Visit'),
Expand Down
4 changes: 2 additions & 2 deletions plugins/Actions/Columns/EntryPageTitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ protected function init()

/**
* @param Request $request
* @param $visit
* @param array $visit
* @param Action|null $action
* @return bool
* @return int
*/
public function onNewVisit(Request $request, $visit, $action)
{
Expand Down
4 changes: 2 additions & 2 deletions plugins/Actions/Columns/EntryPageUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ protected function init()

/**
* @param Request $request
* @param $visit
* @param array $visit
* @param Action|null $action
* @return bool
* @return int
*/
public function onNewVisit(Request $request, $visit, $action)
{
Expand Down
18 changes: 9 additions & 9 deletions plugins/Actions/Columns/ExitPageTitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ protected function init()

/**
* @param Request $request
* @param $visit
* @param array $visit
* @param Action|null $action
* @return bool
* @return int|bool
*/
public function onNewVisit(Request $request, $visit, $action)
{
Expand All @@ -44,19 +44,19 @@ public function onNewVisit(Request $request, $visit, $action)
return (int) $idActionName;
}

/**
* @param Request $request
* @param array $visit
* @param Action|null $action
* @return int|bool
*/
public function onExistingVisit(Request $request, $visit, $action)
{
if (empty($action)) {
return false;
}

$id = $action->getIdActionNameForEntryAndExitIds();

if (!empty($id)) {
$id = (int) $id;
}

return $id;
return $action->getIdActionNameForEntryAndExitIds();
}

public function getName()
Expand Down
4 changes: 2 additions & 2 deletions plugins/Actions/Columns/ExitPageUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ protected function init()

/**
* @param Request $request
* @param $visit
* @param array $visit
* @param Action|null $action
* @return bool
* @return int|bool
*/
public function onNewVisit(Request $request, $visit, $action)
{
Expand Down
Loading

0 comments on commit fccdcc0

Please sign in to comment.