-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added feature Custom Dimensions #9217
Changes from all commits
d995029
e9656af
b294a78
05cd81f
c0603d4
bf0aac0
1a4db22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,7 @@ public function getDataArrayWithTwoLevels() | |
public function sumMetricsVisits($label, $row) | ||
{ | ||
if (!isset($this->data[$label])) { | ||
$this->data[$label] = self::makeEmptyRow(); | ||
$this->data[$label] = static::makeEmptyRow(); | ||
} | ||
$this->doSumVisitsMetrics($row, $this->data[$label]); | ||
} | ||
|
@@ -80,17 +80,14 @@ public static function makeEmptyRow() | |
* | ||
* @return void | ||
*/ | ||
protected function doSumVisitsMetrics($newRowToAdd, &$oldRowToUpdate, $onlyMetricsAvailableInActionsTable = false) | ||
protected function doSumVisitsMetrics($newRowToAdd, &$oldRowToUpdate) | ||
{ | ||
// Pre 1.2 format: string indexed rows are returned from the DB | ||
// Left here for Backward compatibility with plugins doing custom SQL queries using these metrics as string | ||
if (!isset($newRowToAdd[Metrics::INDEX_NB_VISITS])) { | ||
$oldRowToUpdate[Metrics::INDEX_NB_VISITS] += $newRowToAdd['nb_visits']; | ||
$oldRowToUpdate[Metrics::INDEX_NB_ACTIONS] += $newRowToAdd['nb_actions']; | ||
$oldRowToUpdate[Metrics::INDEX_NB_UNIQ_VISITORS] += $newRowToAdd['nb_uniq_visitors']; | ||
if ($onlyMetricsAvailableInActionsTable) { | ||
return; | ||
} | ||
$oldRowToUpdate[Metrics::INDEX_NB_USERS] += $newRowToAdd['nb_users']; | ||
$oldRowToUpdate[Metrics::INDEX_MAX_ACTIONS] = (float)max($newRowToAdd['max_actions'], $oldRowToUpdate[Metrics::INDEX_MAX_ACTIONS]); | ||
$oldRowToUpdate[Metrics::INDEX_SUM_VISIT_LENGTH] += $newRowToAdd['sum_visit_length']; | ||
|
@@ -107,9 +104,6 @@ protected function doSumVisitsMetrics($newRowToAdd, &$oldRowToUpdate, $onlyMetri | |
$oldRowToUpdate[Metrics::INDEX_NB_VISITS] += $newRowToAdd[Metrics::INDEX_NB_VISITS]; | ||
$oldRowToUpdate[Metrics::INDEX_NB_ACTIONS] += $newRowToAdd[Metrics::INDEX_NB_ACTIONS]; | ||
$oldRowToUpdate[Metrics::INDEX_NB_UNIQ_VISITORS] += $newRowToAdd[Metrics::INDEX_NB_UNIQ_VISITORS]; | ||
if ($onlyMetricsAvailableInActionsTable) { | ||
return; | ||
} | ||
|
||
// In case the existing Row had no action metrics (eg. Custom Variable XYZ with "visit" scope) | ||
// but the new Row has action metrics (eg. same Custom Variable XYZ this time with a "page" scope) | ||
|
@@ -133,11 +127,50 @@ protected function doSumVisitsMetrics($newRowToAdd, &$oldRowToUpdate, $onlyMetri | |
$oldRowToUpdate[Metrics::INDEX_NB_VISITS_CONVERTED] += $newRowToAdd[Metrics::INDEX_NB_VISITS_CONVERTED]; | ||
} | ||
|
||
/** | ||
* Adds the given row $newRowToAdd to the existing $oldRowToUpdate passed by reference | ||
* The rows are php arrays Name => value | ||
* | ||
* @param array $newRowToAdd | ||
* @param array $oldRowToUpdate | ||
* @param bool $onlyMetricsAvailableInActionsTable | ||
* | ||
* @return void | ||
*/ | ||
protected function doSumActionsMetrics($newRowToAdd, &$oldRowToUpdate) | ||
{ | ||
// Pre 1.2 format: string indexed rows are returned from the DB | ||
// Left here for Backward compatibility with plugins doing custom SQL queries using these metrics as string | ||
if (!isset($newRowToAdd[Metrics::INDEX_NB_VISITS])) { | ||
$oldRowToUpdate[Metrics::INDEX_NB_VISITS] += $newRowToAdd['nb_visits']; | ||
$oldRowToUpdate[Metrics::INDEX_NB_ACTIONS] += $newRowToAdd['nb_actions']; | ||
$oldRowToUpdate[Metrics::INDEX_NB_UNIQ_VISITORS] += $newRowToAdd['nb_uniq_visitors']; | ||
return; | ||
} | ||
|
||
// Edge case fail safe | ||
if (!isset($oldRowToUpdate[Metrics::INDEX_NB_VISITS])) { | ||
return; | ||
} | ||
|
||
$oldRowToUpdate[Metrics::INDEX_NB_VISITS] += $newRowToAdd[Metrics::INDEX_NB_VISITS]; | ||
if (array_key_exists(Metrics::INDEX_NB_ACTIONS, $newRowToAdd)) { | ||
$oldRowToUpdate[Metrics::INDEX_NB_ACTIONS] += $newRowToAdd[Metrics::INDEX_NB_ACTIONS]; | ||
} | ||
if (array_key_exists(Metrics::INDEX_PAGE_NB_HITS, $newRowToAdd)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We noticed sometimes there are hits and sometimes there are actions, needs to work with both |
||
if (!array_key_exists(Metrics::INDEX_PAGE_NB_HITS, $oldRowToUpdate)) { | ||
$oldRowToUpdate[Metrics::INDEX_PAGE_NB_HITS] = 0; | ||
} | ||
$oldRowToUpdate[Metrics::INDEX_PAGE_NB_HITS] += $newRowToAdd[Metrics::INDEX_PAGE_NB_HITS]; | ||
} | ||
$oldRowToUpdate[Metrics::INDEX_NB_UNIQ_VISITORS] += $newRowToAdd[Metrics::INDEX_NB_UNIQ_VISITORS]; | ||
} | ||
|
||
public function sumMetricsGoals($label, $row) | ||
{ | ||
$idGoal = $row['idgoal']; | ||
if (!isset($this->data[$label][Metrics::INDEX_GOALS][$idGoal])) { | ||
$this->data[$label][Metrics::INDEX_GOALS][$idGoal] = self::makeEmptyGoalRow($idGoal); | ||
$this->data[$label][Metrics::INDEX_GOALS][$idGoal] = static::makeEmptyGoalRow($idGoal); | ||
} | ||
$this->doSumGoalsMetrics($row, $this->data[$label][Metrics::INDEX_GOALS][$idGoal]); | ||
} | ||
|
@@ -201,9 +234,10 @@ protected function doSumGoalsMetrics($newRowToAdd, &$oldRowToUpdate) | |
public function sumMetricsActions($label, $row) | ||
{ | ||
if (!isset($this->data[$label])) { | ||
$this->data[$label] = self::makeEmptyActionRow(); | ||
$this->data[$label] = static::makeEmptyActionRow(); | ||
} | ||
$this->doSumVisitsMetrics($row, $this->data[$label], $onlyMetricsAvailableInActionsTable = true); | ||
|
||
$this->doSumActionsMetrics($row, $this->data[$label]); | ||
} | ||
|
||
protected static function makeEmptyActionRow() | ||
|
@@ -218,7 +252,7 @@ protected static function makeEmptyActionRow() | |
public function sumMetricsEvents($label, $row) | ||
{ | ||
if (!isset($this->data[$label])) { | ||
$this->data[$label] = self::makeEmptyEventRow(); | ||
$this->data[$label] = static::makeEmptyEventRow(); | ||
} | ||
$this->doSumEventsMetrics($row, $this->data[$label], $onlyMetricsAvailableInActionsTable = true); | ||
} | ||
|
@@ -250,16 +284,16 @@ protected function doSumEventsMetrics($newRowToAdd, &$oldRowToUpdate) | |
$oldRowToUpdate[Metrics::INDEX_EVENT_NB_HITS] += $newRowToAdd[Metrics::INDEX_EVENT_NB_HITS]; | ||
$oldRowToUpdate[Metrics::INDEX_EVENT_NB_HITS_WITH_VALUE] += $newRowToAdd[Metrics::INDEX_EVENT_NB_HITS_WITH_VALUE]; | ||
|
||
$newRowToAdd[Metrics::INDEX_EVENT_SUM_EVENT_VALUE] = round($newRowToAdd[Metrics::INDEX_EVENT_SUM_EVENT_VALUE], self::EVENT_VALUE_PRECISION); | ||
$newRowToAdd[Metrics::INDEX_EVENT_SUM_EVENT_VALUE] = round($newRowToAdd[Metrics::INDEX_EVENT_SUM_EVENT_VALUE], static::EVENT_VALUE_PRECISION); | ||
$oldRowToUpdate[Metrics::INDEX_EVENT_SUM_EVENT_VALUE] += $newRowToAdd[Metrics::INDEX_EVENT_SUM_EVENT_VALUE]; | ||
$oldRowToUpdate[Metrics::INDEX_EVENT_MAX_EVENT_VALUE] = round(max($newRowToAdd[Metrics::INDEX_EVENT_MAX_EVENT_VALUE], $oldRowToUpdate[Metrics::INDEX_EVENT_MAX_EVENT_VALUE]), self::EVENT_VALUE_PRECISION); | ||
$oldRowToUpdate[Metrics::INDEX_EVENT_MAX_EVENT_VALUE] = round(max($newRowToAdd[Metrics::INDEX_EVENT_MAX_EVENT_VALUE], $oldRowToUpdate[Metrics::INDEX_EVENT_MAX_EVENT_VALUE]), static::EVENT_VALUE_PRECISION); | ||
|
||
// Update minimum only if it is set | ||
if ($newRowToAdd[Metrics::INDEX_EVENT_MIN_EVENT_VALUE] !== false) { | ||
if ($oldRowToUpdate[Metrics::INDEX_EVENT_MIN_EVENT_VALUE] === false) { | ||
$oldRowToUpdate[Metrics::INDEX_EVENT_MIN_EVENT_VALUE] = round($newRowToAdd[Metrics::INDEX_EVENT_MIN_EVENT_VALUE], self::EVENT_VALUE_PRECISION); | ||
$oldRowToUpdate[Metrics::INDEX_EVENT_MIN_EVENT_VALUE] = round($newRowToAdd[Metrics::INDEX_EVENT_MIN_EVENT_VALUE], static::EVENT_VALUE_PRECISION); | ||
} else { | ||
$oldRowToUpdate[Metrics::INDEX_EVENT_MIN_EVENT_VALUE] = round(min($newRowToAdd[Metrics::INDEX_EVENT_MIN_EVENT_VALUE], $oldRowToUpdate[Metrics::INDEX_EVENT_MIN_EVENT_VALUE]), self::EVENT_VALUE_PRECISION); | ||
$oldRowToUpdate[Metrics::INDEX_EVENT_MIN_EVENT_VALUE] = round(min($newRowToAdd[Metrics::INDEX_EVENT_MIN_EVENT_VALUE], $oldRowToUpdate[Metrics::INDEX_EVENT_MIN_EVENT_VALUE]), static::EVENT_VALUE_PRECISION); | ||
} | ||
} | ||
} | ||
|
@@ -290,7 +324,7 @@ public function sumMetrics($label, $row) | |
public function sumMetricsVisitsPivot($parentLabel, $label, $row) | ||
{ | ||
if (!isset($this->dataTwoLevels[$parentLabel][$label])) { | ||
$this->dataTwoLevels[$parentLabel][$label] = self::makeEmptyRow(); | ||
$this->dataTwoLevels[$parentLabel][$label] = static::makeEmptyRow(); | ||
} | ||
$this->doSumVisitsMetrics($row, $this->dataTwoLevels[$parentLabel][$label]); | ||
} | ||
|
@@ -299,7 +333,7 @@ public function sumMetricsGoalsPivot($parentLabel, $label, $row) | |
{ | ||
$idGoal = $row['idgoal']; | ||
if (!isset($this->dataTwoLevels[$parentLabel][$label][Metrics::INDEX_GOALS][$idGoal])) { | ||
$this->dataTwoLevels[$parentLabel][$label][Metrics::INDEX_GOALS][$idGoal] = self::makeEmptyGoalRow($idGoal); | ||
$this->dataTwoLevels[$parentLabel][$label][Metrics::INDEX_GOALS][$idGoal] = static::makeEmptyGoalRow($idGoal); | ||
} | ||
$this->doSumGoalsMetrics($row, $this->dataTwoLevels[$parentLabel][$label][Metrics::INDEX_GOALS][$idGoal]); | ||
} | ||
|
@@ -309,7 +343,7 @@ public function sumMetricsActionsPivot($parentLabel, $label, $row) | |
if (!isset($this->dataTwoLevels[$parentLabel][$label])) { | ||
$this->dataTwoLevels[$parentLabel][$label] = $this->makeEmptyActionRow(); | ||
} | ||
$this->doSumVisitsMetrics($row, $this->dataTwoLevels[$parentLabel][$label], $onlyMetricsAvailableInActionsTable = true); | ||
$this->doSumActionsMetrics($row, $this->dataTwoLevels[$parentLabel][$label]); | ||
} | ||
|
||
public function sumMetricsEventsPivot($parentLabel, $label, $row) | ||
|
@@ -382,7 +416,7 @@ protected function enrichWithConversions(&$data) | |
*/ | ||
public static function isRowActions($row) | ||
{ | ||
return (count($row) == count(self::makeEmptyActionRow())) && isset($row[Metrics::INDEX_NB_ACTIONS]); | ||
return (count($row) == count(static::makeEmptyActionRow())) && isset($row[Metrics::INDEX_NB_ACTIONS]); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1070,11 +1070,20 @@ private function installPluginIfNecessary(Plugin $plugin) | |
|
||
if ($saveConfig) { | ||
PiwikConfig::getInstance()->forceSave(); | ||
$this->clearCache($pluginName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was actually a bug, when a plugin was installed we sometimes did not clear the caches. Eg when installing core plugins |
||
} | ||
} | ||
|
||
public function isTrackerPlugin(Plugin $plugin) | ||
{ | ||
if (!$this->isPluginInstalled($plugin->getPluginName())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should not load a plugin in tracker mode that is not installed. Otherwise the plugin might wants to read or write to columns that do not exist yet There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good find! |
||
return false; | ||
} | ||
|
||
if ($plugin->isTrackerPlugin()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved it further up as a performance tweak, this way we do not have to check for all dimensions, events, ... when a plugin directly marks itself as a tracker plugin |
||
return true; | ||
} | ||
|
||
$dimensions = VisitDimension::getDimensions($plugin); | ||
if (!empty($dimensions)) { | ||
return true; | ||
|
@@ -1101,10 +1110,6 @@ public function isTrackerPlugin(Plugin $plugin) | |
return true; | ||
} | ||
|
||
if ($plugin->isTrackerPlugin()) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ abstract class Action | |
|
||
private $idLinkVisitAction; | ||
private $actionIdsCached = array(); | ||
private $customFields = array(); | ||
private $actionName; | ||
private $actionType; | ||
|
||
|
@@ -228,6 +229,16 @@ protected function getUrlAndType() | |
return false; | ||
} | ||
|
||
public function setCustomField($field, $value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was needed in order to add any fields for the tracker from a |
||
{ | ||
$this->customFields[$field] = $value; | ||
} | ||
|
||
public function getCustomFields() | ||
{ | ||
return $this->customFields; | ||
} | ||
|
||
public function getIdActionUrl() | ||
{ | ||
$idUrl = $this->actionIdsCached['idaction_url']; | ||
|
@@ -379,13 +390,7 @@ public function record(Visitor $visitor, $idReferrerActionUrl, $idReferrerAction | |
$visitAction[self::DB_COLUMN_CUSTOM_FLOAT] = Common::forceDotAsSeparatorForDecimalPoint($customValue); | ||
} | ||
|
||
$customVariables = $this->getCustomVariables(); | ||
if (!empty($customVariables)) { | ||
Common::printDebug("Page level Custom Variables: "); | ||
Common::printDebug($customVariables); | ||
} | ||
|
||
$visitAction = array_merge($visitAction, $customVariables); | ||
$visitAction = array_merge($visitAction, $this->customFields); | ||
|
||
$this->idLinkVisitAction = $this->getModel()->createAction($visitAction); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of a boolean parameter splitted logic into
doSumVisitsMetrics
anddoSumActionMetrics