private function getActionDimensions() { // see eg https://github.com/piwik/piwik/issues/8399 we fetch them only on demand to improve performance if (!isset($this->actionDimensions)) { $this->actionDimensions = ActionDimension::getAllDimensions(); } return $this->actionDimensions; }
/** * @param $pluginName */ private function executePluginUninstall($pluginName) { try { $plugin = $this->getLoadedPlugin($pluginName); $plugin->uninstall(); } catch (\Exception $e) { } if (empty($plugin)) { return; } try { $visitDimensions = VisitDimension::getAllDimensions(); foreach (VisitDimension::getDimensions($plugin) as $dimension) { $this->uninstallDimension(VisitDimension::INSTALLER_PREFIX, $dimension, $visitDimensions); } } catch (\Exception $e) { } try { $actionDimensions = ActionDimension::getAllDimensions(); foreach (ActionDimension::getDimensions($plugin) as $dimension) { $this->uninstallDimension(ActionDimension::INSTALLER_PREFIX, $dimension, $actionDimensions); } } catch (\Exception $e) { } try { $conversionDimensions = ConversionDimension::getAllDimensions(); foreach (ConversionDimension::getDimensions($plugin) as $dimension) { $this->uninstallDimension(ConversionDimension::INSTALLER_PREFIX, $dimension, $conversionDimensions); } } catch (\Exception $e) { } }
/** * Gets an instance of all available visit, action and conversion dimension. * @return Dimension[] */ public static function getAllDimensions() { $dimensions = array(); foreach (VisitDimension::getAllDimensions() as $dimension) { $dimensions[] = $dimension; } foreach (ActionDimension::getAllDimensions() as $dimension) { $dimensions[] = $dimension; } foreach (ConversionDimension::getAllDimensions() as $dimension) { $dimensions[] = $dimension; } return $dimensions; }
/** * @return mixed|Dimension[] */ private static function getActionDimensions() { return ActionDimension::getAllDimensions(); }
/** * Records in the DB the association between the visit and this action. * * @param int $idReferrerActionUrl is the ID of the last action done by the current visit. * @param $idReferrerActionName * @param Visitor $visitor */ public function record(Visitor $visitor, $idReferrerActionUrl, $idReferrerActionName) { $this->loadIdsFromLogActionTable(); $visitAction = array('idvisit' => $visitor->getVisitorColumn('idvisit'), 'idsite' => $this->request->getIdSite(), 'idvisitor' => $visitor->getVisitorColumn('idvisitor'), 'idaction_url' => $this->getIdActionUrl(), 'idaction_url_ref' => $idReferrerActionUrl, 'idaction_name_ref' => $idReferrerActionName); /** @var ActionDimension[] $dimensions */ $dimensions = ActionDimension::getAllDimensions(); foreach ($dimensions as $dimension) { $value = $dimension->onNewAction($this->request, $visitor, $this); if ($value !== false) { if (is_float($value)) { $value = Common::forceDotAsSeparatorForDecimalPoint($value); } $visitAction[$dimension->getColumnName()] = $value; } } // idaction_name is NULLable. we only set it when applicable if ($this->isActionHasActionName()) { $visitAction['idaction_name'] = (int) $this->getIdActionName(); } foreach ($this->actionIdsCached as $field => $idAction) { $visitAction[$field] = $idAction === false ? 0 : $idAction; } $customValue = $this->getCustomFloatValue(); if (!empty($customValue)) { $visitAction[self::DB_COLUMN_CUSTOM_FLOAT] = Common::forceDotAsSeparatorForDecimalPoint($customValue); } $visitAction = array_merge($visitAction, $this->customFields); $this->idLinkVisitAction = $this->getModel()->createAction($visitAction); $visitAction['idlink_va'] = $this->idLinkVisitAction; Common::printDebug("Inserted new action:"); $visitActionDebug = $visitAction; $visitActionDebug['idvisitor'] = bin2hex($visitActionDebug['idvisitor']); Common::printDebug($visitActionDebug); /** * Triggered after successfully persisting a [visit action entity](/guides/persistence-and-the-mysql-backend#visit-actions). * * This event is deprecated, use [Dimensions](http://developer.piwik.org/guides/dimensions) instead. * * @param Action $tracker Action The Action tracker instance. * @param array $visitAction The visit action entity that was persisted. Read * [this](/guides/persistence-and-the-mysql-backend#visit-actions) to see what it contains. * @deprecated */ Piwik::postEvent('Tracker.recordAction', array($trackerAction = $this, $visitAction)); }
public static function getAllVersions() { // to avoid having to load all dimensions on each request we check if there were any changes on the file system // can easily save > 100ms for each request $cachedTimes = self::getCachedDimensionFileChanges(); $currentTimes = self::getCurrentDimensionFileChanges(); $diff = array_diff_assoc($currentTimes, $cachedTimes); if (empty($diff)) { return array(); } $versions = array(); $visitColumns = DbHelper::getTableColumns(Common::prefixTable('log_visit')); $actionColumns = DbHelper::getTableColumns(Common::prefixTable('log_link_visit_action')); $conversionColumns = DbHelper::getTableColumns(Common::prefixTable('log_conversion')); foreach (VisitDimension::getAllDimensions() as $dimension) { $versions = self::mixinVersions($dimension, 'log_visit.', $visitColumns, $versions); } foreach (ActionDimension::getAllDimensions() as $dimension) { $versions = self::mixinVersions($dimension, 'log_link_visit_action.', $actionColumns, $versions); } foreach (ConversionDimension::getAllDimensions() as $dimension) { $versions = self::mixinVersions($dimension, 'log_conversion.', $conversionColumns, $versions); } return $versions; }
/** * @param VisitDimension[]|null $visitDimensions * @param ActionDimension[]|null $actionDimensions * @param ConversionDimension[]|null $conversionDimensions */ public function __construct(array $visitDimensions = null, array $actionDimensions = null, array $conversionDimensions = null) { $this->visitDimensions = $visitDimensions === null ? VisitDimension::getAllDimensions() : $visitDimensions; $this->actionDimensions = $actionDimensions === null ? ActionDimension::getAllDimensions() : $actionDimensions; $this->conversionDimensions = $conversionDimensions === null ? ConversionDimension::getAllDimensions() : $conversionDimensions; }
public function test_getAllDimensions_shouldLoadAllDimensionsButOnlyIfLoadedPlugins() { Manager::getInstance()->loadPlugins(array('Actions', 'Events')); $dimensions = ActionDimension::getAllDimensions(); $this->assertGreaterThan(8, count($dimensions)); foreach ($dimensions as $dimension) { $this->assertInstanceOf('\\Piwik\\Plugin\\Dimension\\ActionDimension', $dimension); $this->assertRegExp('/Piwik.Plugins.(Actions|Events).Columns/', get_class($dimension)); } }
/** * Records in the DB the association between the visit and this action. * * @param int $idReferrerActionUrl is the ID of the last action done by the current visit. * @param $idReferrerActionName * @param Visitor $visitor */ public function record(Visitor $visitor, $idReferrerActionUrl, $idReferrerActionName) { $this->loadIdsFromLogActionTable(); $visitAction = array('idvisit' => $visitor->getVisitorColumn('idvisit'), 'idsite' => $this->request->getIdSite(), 'idvisitor' => $visitor->getVisitorColumn('idvisitor'), 'idaction_url' => $this->getIdActionUrl(), 'idaction_url_ref' => $idReferrerActionUrl, 'idaction_name_ref' => $idReferrerActionName); $dimensions = ActionDimension::getAllDimensions(); foreach ($dimensions as $dimension) { $value = $dimension->onNewAction($this->request, $visitor, $this); if ($value !== false) { $visitAction[$dimension->getColumnName()] = $value; } } // idaction_name is NULLable. we only set it when applicable if ($this->isActionHasActionName()) { $visitAction['idaction_name'] = (int) $this->getIdActionName(); } foreach ($this->actionIdsCached as $field => $idAction) { $visitAction[$field] = $idAction === false ? 0 : $idAction; } $customValue = $this->getCustomFloatValue(); if (!empty($customValue)) { $visitAction[self::DB_COLUMN_CUSTOM_FLOAT] = $customValue; } $customVariables = $this->getCustomVariables(); if (!empty($customVariables)) { Common::printDebug("Page level Custom Variables: "); Common::printDebug($customVariables); } $visitAction = array_merge($visitAction, $customVariables); $fields = implode(", ", array_keys($visitAction)); $bind = array_values($visitAction); $values = Common::getSqlStringFieldsArray($visitAction); $sql = "INSERT INTO " . Common::prefixTable('log_link_visit_action') . " ({$fields}) VALUES ({$values})"; Tracker::getDatabase()->query($sql, $bind); $this->idLinkVisitAction = Tracker::getDatabase()->lastInsertId(); $visitAction['idlink_va'] = $this->idLinkVisitAction; Common::printDebug("Inserted new action:"); Common::printDebug($visitAction); /** * Triggered after successfully persisting a [visit action entity](/guides/persistence-and-the-mysql-backend#visit-actions). * * @param Action $tracker Action The Action tracker instance. * @param array $visitAction The visit action entity that was persisted. Read * [this](/guides/persistence-and-the-mysql-backend#visit-actions) to see what it contains. */ Piwik::postEvent('Tracker.recordAction', array($trackerAction = $this, $visitAction)); }
/** * Records in the DB the association between the visit and this action. * * @param int $idReferrerActionUrl is the ID of the last action done by the current visit. * @param $idReferrerActionName * @param Visitor $visitor */ public function record(Visitor $visitor, $idReferrerActionUrl, $idReferrerActionName) { $this->loadIdsFromLogActionTable(); $visitAction = array('idvisit' => $visitor->getVisitorColumn('idvisit'), 'idsite' => $this->request->getIdSite(), 'idvisitor' => $visitor->getVisitorColumn('idvisitor'), 'idaction_url' => $this->getIdActionUrl(), 'idaction_url_ref' => $idReferrerActionUrl, 'idaction_name_ref' => $idReferrerActionName); /** @var ActionDimension[] $dimensions */ $dimensions = ActionDimension::getAllDimensions(); foreach ($dimensions as $dimension) { $value = $dimension->onNewAction($this->request, $visitor, $this); if ($value !== false) { if (is_float($value)) { $value = Common::forceDotAsSeparatorForDecimalPoint($value); } $visitAction[$dimension->getColumnName()] = $value; } } // idaction_name is NULLable. we only set it when applicable if ($this->isActionHasActionName()) { $visitAction['idaction_name'] = (int) $this->getIdActionName(); } foreach ($this->actionIdsCached as $field => $idAction) { $visitAction[$field] = $idAction === false ? 0 : $idAction; } $customValue = $this->getCustomFloatValue(); if (!empty($customValue)) { $visitAction[self::DB_COLUMN_CUSTOM_FLOAT] = Common::forceDotAsSeparatorForDecimalPoint($customValue); } $visitAction = array_merge($visitAction, $this->customFields); $this->idLinkVisitAction = $this->getModel()->createAction($visitAction); $visitAction['idlink_va'] = $this->idLinkVisitAction; Common::printDebug("Inserted new action:"); $visitActionDebug = $visitAction; $visitActionDebug['idvisitor'] = bin2hex($visitActionDebug['idvisitor']); Common::printDebug($visitActionDebug); }