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);
     }
 }
 /**
  * @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));
         }
     }
 }
Exemplo n.º 3
0
 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));
         }
     }
 }
 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;
 }
 public function getSegmentsMetadata(&$segments, $idSites)
 {
     if (empty($idSites) || is_array($idSites) && count($idSites) !== 1) {
         return array();
     }
     if (is_array($idSites)) {
         $idSite = array_shift($idSites);
     } else {
         $idSite = $idSites;
     }
     $idSite = (int) $idSite;
     $dimensions = $this->configuration->getCustomDimensionsForSite($idSite);
     foreach ($dimensions as $dimension) {
         if (!$dimension['active']) {
             continue;
         }
         $segment = new Plugin\Segment();
         $segment->setSegment(CustomDimensionsRequestProcessor::buildCustomDimensionTrackingApiName($dimension));
         $segment->setType(Plugin\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;
         }
         $segments[] = $segment->toArray();
     }
 }
 public function test_onExistingVisit_ShouldOnlyAddColumnsOfCustomDimensionsInScopeVisit()
 {
     $this->configureSomeDimensions();
     $valuesToUpdate = array();
     $visitProperties = new VisitProperties();
     $request = new Request(array('idsite' => 1, 'something' => 5, Processor::buildCustomDimensionTrackingApiName(2) => '2 value', Processor::buildCustomDimensionTrackingApiName(6) => '6 value', 'dimension_' => 'not an actual dimension', 'dimension99' => 'not an actual dimension2', Processor::buildCustomDimensionTrackingApiName(3) => '3 value', Processor::buildCustomDimensionTrackingApiName(9) => '9 value'));
     $this->processor->onExistingVisit($valuesToUpdate, $visitProperties, $request);
     $expected = array('custom_dimension_2' => '2 value', 'custom_dimension_4' => '6 value');
     $this->assertSame($expected, $valuesToUpdate);
 }