protected function configureSegments() { $idSite = Common::getRequestVar('idSite', 0, 'int'); if (empty($idSite)) { return array(); } $configuration = StaticContainer::get('Piwik\\Plugins\\CustomDimensions\\Dao\\Configuration'); $dimensions = $configuration->getCustomDimensionsForSite($idSite); foreach ($dimensions as $dimension) { if (!$dimension['active']) { continue; } $segment = new Segment(); $segment->setSegment(CustomDimensionsRequestProcessor::buildCustomDimensionTrackingApiName($dimension)); $segment->setType(Segment::TYPE_DIMENSION); $segment->setName($dimension['name']); $columnName = LogTable::buildCustomDimensionColumnName($dimension); if ($dimension['scope'] === CustomDimensions::SCOPE_ACTION) { $segment->setSqlSegment('log_link_visit_action. ' . $columnName); $segment->setCategory('General_Actions'); $segment->setSuggestedValuesCallback(function ($idSite, $maxValuesToReturn) use($dimension) { $autoSuggest = new AutoSuggest(); return $autoSuggest->getMostUsedActionDimensionValues($dimension, $idSite, $maxValuesToReturn); }); } elseif ($dimension['scope'] === CustomDimensions::SCOPE_VISIT) { $segment->setSqlSegment('log_visit. ' . $columnName); $segment->setCategory('General_Visit'); } else { continue; } $this->addSegment($segment); } }
public function test_afterRequestProcessed_NoActionSet_ShouldBeAbleToHandleCaseSensitive() { $configuration = new Configuration(); $extractions = array(array('dimension' => 'url', 'pattern' => 'wwW(.+).com')); $configuration->configureNewDimension($idSite = 1, 'MyName1', CustomDimensions::SCOPE_ACTION, 1, true, $extractions, $caseSensitive = true); $configuration->configureNewDimension($idSite = 1, 'MyName2', CustomDimensions::SCOPE_ACTION, 2, true, $extractions, $caseSensitive = false); $request = new Request(array('idsite' => 1, 'url' => 'http://www.exAmple.com/test?id=11&module=test')); $action = new ActionPageview($request); $request->setMetadata('Actions', 'action', $action); $this->processor->afterRequestProcessed(new VisitProperties(), $request); $this->assertSame(array('custom_dimension_2' => '.exAmple'), $action->getCustomFields()); }
/** * @param DataTable $table */ public function filter($table) { $dimension = CustomDimensionsRequestProcessor::buildCustomDimensionTrackingApiName($this->idDimension); foreach ($table->getRows() as $row) { $label = $row->getColumn('label'); if ($label !== false) { if ($label === Archiver::LABEL_CUSTOM_VALUE_NOT_DEFINED) { $label = ''; } $row->setMetadata('segment', $dimension . '==' . urlencode($label)); } $subTable = $row->getSubtable(); if ($subTable) { $subTable->filter('Piwik\\Plugins\\CustomDimensions\\DataTable\\Filter\\AddSubtableSegmentMetadata', array($this->idDimension, $label)); } } }
public function getCustomDimensionValues($configuredVisitDimensions) { $values = array(); foreach ($configuredVisitDimensions as $dimension) { if ($dimension['active'] && $dimension['scope'] === CustomDimensions::SCOPE_VISIT) { // field in DB, eg custom_dimension_1 $field = LogTable::buildCustomDimensionColumnName($dimension); // field for user, eg dimension1 $column = CustomDimensionsRequestProcessor::buildCustomDimensionTrackingApiName($dimension); if (array_key_exists($field, $this->details)) { $values[$column] = $this->details[$field]; } else { $values[$column] = null; } } } return $values; }
/** * @param DataTable $table */ public function filter($table) { if (!$this->dimensionValue) { return; } $dimension = CustomDimensionsRequestProcessor::buildCustomDimensionTrackingApiName($this->idDimension); if ($this->dimensionValue === Archiver::LABEL_CUSTOM_VALUE_NOT_DEFINED) { $dimensionValue = ''; } else { $dimensionValue = urlencode($this->dimensionValue); } $conditionAnd = ';'; $partDimension = $dimension . '==' . $dimensionValue . $conditionAnd; foreach ($table->getRows() as $row) { $label = $row->getColumn('label'); if ($label !== false) { $row->setMetadata('segment', $partDimension . 'actionUrl=$' . urlencode($label)); $row->setMetadata('url', urlencode($label)); } } }
public function addConversionInformation(&$conversion, $visitInformation, Tracker\Request $request) { $dimensions = CustomDimensionsRequestProcessor::getCachedCustomDimensions($request); // we copy all visit custom dimensions, but only if the index also exists in the conversion table // to not fail while conversion custom dimensions are added $conversionIndexes = $this->getCachedInstalledIndexesForScope(self::SCOPE_CONVERSION); $conversionIndexes = array_map(function ($index) { return (int) $index; // make sure we work with integers }, $conversionIndexes); foreach ($dimensions as $dimension) { $index = (int) $dimension['index']; if ($dimension['scope'] === self::SCOPE_VISIT && in_array($index, $conversionIndexes)) { $field = LogTable::buildCustomDimensionColumnName($dimension); if (array_key_exists($field, $visitInformation)) { $conversion[$field] = $visitInformation[$field]; } } } }
private function initThisReportFromDimension($dimension) { $this->name = $dimension['name']; $this->menuTitle = $this->name; $this->widgetTitle = $this->name; $this->scopeOfDimension = $dimension['scope']; $this->subcategoryId = 'customdimension' . $dimension['idcustomdimension']; $dimensionField = CustomDimensionsRequestProcessor::buildCustomDimensionTrackingApiName($dimension); if ($this->scopeOfDimension === CustomDimensions::SCOPE_ACTION) { $this->categoryId = 'General_Actions'; $this->dimension = new CustomActionDimension($dimensionField, $this->name); $this->metrics = array('nb_hits', 'nb_visits'); $this->processedMetrics = array(new AverageTimeOnDimension(), new BounceRate(), new ExitRate(), new AveragePageGenerationTime()); } elseif ($this->scopeOfDimension === CustomDimensions::SCOPE_VISIT) { $this->categoryId = 'General_Visitors'; $this->dimension = new CustomVisitDimension($dimensionField, $this->name); $this->metrics = array('nb_visits', 'nb_actions'); $this->processedMetrics = array(new AverageTimeOnSite(), new BounceRate(), new ActionsPerVisit()); } else { return false; } $this->parameters = array('idDimension' => $dimension['idcustomdimension']); $this->order = 100 + $dimension['idcustomdimension']; return true; }