public function test_getAllDimensions_shouldLoadAllDimensionsButOnlyIfLoadedPlugins()
 {
     Manager::getInstance()->loadPlugins(array('Goals', 'Ecommerce', 'ExampleTracker'));
     $dimensions = ConversionDimension::getAllDimensions();
     $this->assertGreaterThan(5, count($dimensions));
     foreach ($dimensions as $dimension) {
         $this->assertInstanceOf('\\Piwik\\Plugin\\Dimension\\ConversionDimension', $dimension);
         $this->assertRegExp('/Piwik.Plugins.(ExampleTracker|Ecommerce|Goals).Columns/', get_class($dimension));
     }
 }
Esempio n. 2
0
 /**
  * @param $pluginName
  */
 private function executePluginUninstall($pluginName)
 {
     try {
         $plugin = $this->getLoadedPlugin($pluginName);
         $plugin->uninstall();
     } catch (\Exception $e) {
     }
     if (empty($plugin)) {
         return;
     }
     try {
         foreach (VisitDimension::getDimensions($plugin) as $dimension) {
             $this->uninstallDimension($dimension);
         }
     } catch (\Exception $e) {
     }
     try {
         foreach (ActionDimension::getDimensions($plugin) as $dimension) {
             $this->uninstallDimension($dimension);
         }
     } catch (\Exception $e) {
     }
     try {
         foreach (ConversionDimension::getDimensions($plugin) as $dimension) {
             $this->uninstallDimension($dimension);
         }
     } catch (\Exception $e) {
     }
 }
Esempio n. 3
0
 /**
  * @param VisitDimension|ActionDimension|ConversionDimension $dimension
  * @param VisitDimension[]|ActionDimension[]|ConversionDimension[] $allDimensions
  * @return bool
  */
 private function doesAnotherPluginDefineSameColumnWithDbEntry($dimension, $allDimensions)
 {
     $module = $dimension->getModule();
     $columnName = $dimension->getColumnName();
     foreach ($allDimensions as $dim) {
         if ($dim->getColumnName() === $columnName && $dim->hasColumnType() && $dim->getModule() !== $module) {
             return true;
         }
     }
     return false;
 }
Esempio n. 4
0
 /**
  * Records a standard non-Ecommerce goal in the DB (URL/Title matching),
  * linking the conversion to the action that triggered it
  * @param $goal
  * @param Visitor $visitor
  * @param Action $action
  * @param $visitorInformation
  */
 protected function recordStandardGoals($goal, Visitor $visitor, $action, $visitorInformation)
 {
     foreach ($this->convertedGoals as $convertedGoal) {
         $this->currentGoal = $convertedGoal;
         Common::printDebug("- Goal " . $convertedGoal['idgoal'] . " matched. Recording...");
         $conversion = $goal;
         $conversion['idgoal'] = $convertedGoal['idgoal'];
         $conversion['url'] = $convertedGoal['url'];
         if (!is_null($action)) {
             $conversion['idaction_url'] = $action->getIdActionUrl();
             $conversion['idlink_va'] = $action->getIdLinkVisitAction();
         }
         // If multiple Goal conversions per visit, set a cache buster
         $conversion['buster'] = $convertedGoal['allow_multiple'] == 0 ? '0' : $visitorInformation['visit_last_action_time'];
         $conversionDimensions = ConversionDimension::getAllDimensions();
         $conversion = $this->triggerHookOnDimensions($conversionDimensions, 'onGoalConversion', $visitor, $action, $conversion);
         $this->insertNewConversion($conversion, $visitorInformation);
         /**
          * Triggered after successfully recording a non-ecommerce conversion.
          *
          * _Note: Subscribers should be wary of doing any expensive computation here as it may slow
          * the tracker down._
          *
          * @param array $conversion The conversion entity that was just persisted. See what information
          *                          it contains [here](/guides/persistence-and-the-mysql-backend#conversions).
          */
         Piwik::postEvent('Tracker.recordStandardGoals', array($conversion));
     }
 }
Esempio n. 5
0
 public static function getDimensions(Plugin $plugin)
 {
     $dimensions = array();
     foreach (VisitDimension::getDimensions($plugin) as $dimension) {
         $dimensions[] = $dimension;
     }
     foreach (ActionDimension::getDimensions($plugin) as $dimension) {
         $dimensions[] = $dimension;
     }
     foreach (ConversionDimension::getDimensions($plugin) as $dimension) {
         $dimensions[] = $dimension;
     }
     return $dimensions;
 }
Esempio n. 6
0
 /**
  * @return mixed|Dimension[]
  */
 private static function getConversionDimensions()
 {
     return ConversionDimension::getAllDimensions();
 }
Esempio n. 7
0
 /**
  * @param ActionDimension|ConversionDimension|VisitDimension $dimension
  * @param string $componentPrefix
  * @param array $columns
  * @param array $versions
  * @return array The modified versions array
  */
 private static function mixinVersions($dimension, $componentPrefix, $columns, $versions)
 {
     $columnName = $dimension->getColumnName();
     if (!$columnName || !$dimension->hasColumnType()) {
         return $versions;
     }
     $component = $componentPrefix . $columnName;
     $version = $dimension->getVersion();
     if (array_key_exists($columnName, $columns) && false === PiwikUpdater::getCurrentRecordedComponentVersion($component) && self::wasDimensionMovedFromCoreToPlugin($component, $version)) {
         PiwikUpdater::recordComponentSuccessfullyUpdated($component, $version);
         return $versions;
     }
     $versions[$component] = $version;
     return $versions;
 }
Esempio n. 8
0
 /**
  * Records a standard non-Ecommerce goal in the DB (URL/Title matching),
  * linking the conversion to the action that triggered it
  * @param $goal
  * @param Visitor $visitor
  * @param Action $action
  * @param $visitorInformation
  */
 protected function recordStandardGoals(VisitProperties $visitProperties, Request $request, $goal, $action)
 {
     $visitor = Visitor::makeFromVisitProperties($visitProperties, $request);
     $convertedGoals = $request->getMetadata('Goals', 'goalsConverted') ?: array();
     foreach ($convertedGoals as $convertedGoal) {
         $this->currentGoal = $convertedGoal;
         Common::printDebug("- Goal " . $convertedGoal['idgoal'] . " matched. Recording...");
         $conversion = $goal;
         $conversion['idgoal'] = $convertedGoal['idgoal'];
         $conversion['url'] = $convertedGoal['url'];
         if (!is_null($action)) {
             $conversion['idaction_url'] = $action->getIdActionUrl();
             $conversion['idlink_va'] = $action->getIdLinkVisitAction();
         }
         // If multiple Goal conversions per visit, set a cache buster
         $conversion['buster'] = $convertedGoal['allow_multiple'] == 0 ? '0' : $visitProperties->getProperty('visit_last_action_time');
         $conversionDimensions = ConversionDimension::getAllDimensions();
         $conversion = $this->triggerHookOnDimensions($request, $conversionDimensions, 'onGoalConversion', $visitor, $action, $conversion);
         $this->insertNewConversion($conversion, $visitProperties->getProperties(), $request);
         /**
          * Triggered after successfully recording a non-ecommerce conversion.
          *
          * _Note: Subscribers should be wary of doing any expensive computation here as it may slow
          * the tracker down._
          *
          * This event is deprecated, use [Dimensions](http://developer.piwik.org/guides/dimensions) instead.
          *
          * @param array $conversion The conversion entity that was just persisted. See what information
          *                          it contains [here](/guides/persistence-and-the-mysql-backend#conversions).
          * @deprecated
          */
         Piwik::postEvent('Tracker.recordStandardGoals', array($conversion));
     }
 }
Esempio n. 9
0
 /**
  * @param ActionDimension|ConversionDimension|VisitDimension $dimension
  * @param string $componentPrefix
  * @param array $columns
  * @param array $versions
  * @return array The modified versions array
  */
 private function mixinVersions(PiwikUpdater $updater, $dimension, $componentPrefix, $columns, $versions)
 {
     $columnName = $dimension->getColumnName();
     // dimensions w/o columns do not need DB updates
     if (!$columnName || !$dimension->hasColumnType()) {
         return $versions;
     }
     $component = $componentPrefix . $columnName;
     $version = $dimension->getVersion();
     // if the column exists in the table, but has no associated version, and was one of the core columns
     // that was moved when the dimension refactor took place, then:
     // - set the installed version in the DB to the current code version
     // - and do not check for updates since we just set the version to the latest
     if (array_key_exists($columnName, $columns) && false === $updater->getCurrentComponentVersion($component) && self::wasDimensionMovedFromCoreToPlugin($component, $version)) {
         $updater->markComponentSuccessfullyUpdated($component, $version);
         return $versions;
     }
     $versions[$component] = $version;
     return $versions;
 }
Esempio n. 10
0
 /**
  * Records a standard non-Ecommerce goal in the DB (URL/Title matching),
  * linking the conversion to the action that triggered it
  * @param $goal
  * @param Visitor $visitor
  * @param Action $action
  * @param $visitorInformation
  */
 protected function recordStandardGoals(VisitProperties $visitProperties, Request $request, $goal, $action)
 {
     $visitor = Visitor::makeFromVisitProperties($visitProperties, $request);
     $convertedGoals = $request->getMetadata('Goals', 'goalsConverted') ?: array();
     foreach ($convertedGoals as $convertedGoal) {
         $this->currentGoal = $convertedGoal;
         Common::printDebug("- Goal " . $convertedGoal['idgoal'] . " matched. Recording...");
         $conversion = $goal;
         $conversion['idgoal'] = $convertedGoal['idgoal'];
         $conversion['url'] = $convertedGoal['url'];
         if (!is_null($action)) {
             $conversion['idaction_url'] = $action->getIdActionUrl();
             $conversion['idlink_va'] = $action->getIdLinkVisitAction();
         }
         // If multiple Goal conversions per visit, set a cache buster
         $conversion['buster'] = $convertedGoal['allow_multiple'] == 0 ? '0' : $visitProperties->getProperty('visit_last_action_time');
         $conversionDimensions = ConversionDimension::getAllDimensions();
         $conversion = $this->triggerHookOnDimensions($request, $conversionDimensions, 'onGoalConversion', $visitor, $action, $conversion);
         $this->insertNewConversion($conversion, $visitProperties->getProperties(), $request);
     }
 }