public function check()
 {
     if (!is_array($this->extractions)) {
         throw new Exception('extractions has to be an array');
     }
     foreach ($this->extractions as $extraction) {
         if (!is_array($extraction)) {
             throw new \Exception('Each extraction within extractions has to be an array');
         }
         if (count($extraction) !== 2 || !array_key_exists('dimension', $extraction) || !array_key_exists('pattern', $extraction)) {
             throw new \Exception('Each extraction within extractions must have a key "dimension" and "pattern" only');
         }
         $extraction = new Extraction($extraction['dimension'], $extraction['pattern']);
         $extraction->check();
     }
 }
 private function configureSomeDimensions()
 {
     $configuration = new Configuration();
     $configuration->configureNewDimension($this->idSite, 'MyName1', CustomDimensions::SCOPE_VISIT, 1, $active = true, $extractions = array(), $caseSensitive = true);
     $configuration->configureNewDimension($this->idSite, 'MyName2', CustomDimensions::SCOPE_VISIT, 2, $active = true, $extractions = array(), $caseSensitive = true);
     $configuration->configureNewDimension($this->idSite2, 'MyName1', CustomDimensions::SCOPE_VISIT, 1, $active = true, $extractions = array(), $caseSensitive = true);
     $extraction1 = new Extraction('urlparam', 'test');
     $extraction2 = new Extraction('urlparam', 'param');
     $extraction3 = new Extraction('url', '/sub_(.{2})/page');
     $configuration->configureNewDimension($this->idSite, 'MyName3', CustomDimensions::SCOPE_ACTION, 1, $active = true, $extractions = array($extraction3->toArray()), $caseSensitive = true);
     $configuration->configureNewDimension($this->idSite, 'MyName4', CustomDimensions::SCOPE_ACTION, 2, $active = false, $extractions = array(), $caseSensitive = true);
     $configuration->configureNewDimension($this->idSite, 'MyName5', CustomDimensions::SCOPE_ACTION, 3, $active = true, $extractions = array($extraction1->toArray(), $extraction2->toArray()), $caseSensitive = true);
     $configuration->configureNewDimension($this->idSite, 'MyName6', CustomDimensions::SCOPE_VISIT, 4, $active = true, $extractions = array(), $caseSensitive = true);
     Cache::deleteCacheWebsiteAttributes(1);
     Cache::deleteCacheWebsiteAttributes(2);
     Cache::clearCacheGeneral();
 }
 private function getCustomDimensionsInScope($scope, Request $request)
 {
     $dimensions = self::getCachedCustomDimensions($request);
     $params = $request->getParams();
     $values = array();
     foreach ($dimensions as $dimension) {
         if ($dimension['scope'] !== $scope) {
             continue;
         }
         $field = self::buildCustomDimensionTrackingApiName($dimension);
         $dbField = Dao\LogTable::buildCustomDimensionColumnName($dimension);
         $value = Common::getRequestVar($field, '', 'string', $params);
         if ($value !== '') {
             $values[$dbField] = $value;
             continue;
         }
         $extractions = $dimension['extractions'];
         if (is_array($extractions)) {
             foreach ($extractions as $extraction) {
                 if (!array_key_exists('dimension', $extraction) || !array_key_exists('pattern', $extraction) || empty($extraction['pattern'])) {
                     continue;
                 }
                 $extraction = new Extraction($extraction['dimension'], $extraction['pattern']);
                 $extraction->setCaseSensitive($dimension['case_sensitive']);
                 $value = $extraction->extract($request);
                 if (!isset($value) || '' === $value) {
                     continue;
                 }
                 $values[$dbField] = $value;
                 break;
             }
         }
     }
     return $values;
 }
Example #4
0
 /**
  * Get a list of all available dimensions that can be used in an extraction. Requires at least Admin access
  * to one website.
  *
  * @return array
  */
 public function getAvailableExtractionDimensions()
 {
     Piwik::checkUserHasSomeAdminAccess();
     $supported = Extraction::getSupportedDimensions();
     $dimensions = array();
     foreach ($supported as $value => $dimension) {
         $dimensions[] = array('value' => $value, 'name' => $dimension);
     }
     return $dimensions;
 }