diff options
author | diosmosis <benaka@piwik.pro> | 2015-07-08 08:24:15 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-08-06 17:37:58 +0300 |
commit | 3821a56d0677d3602fb77aba52b6fbe55a6de0c1 (patch) | |
tree | 1a5260fb59c381464d8413838a15fa0fc9aaa5f6 /plugins/Goals | |
parent | 2ba74fba6bcb83a55963309d05cdc31c9d977103 (diff) |
Move more conversion/actions related logic from Visit::handle() to plugin specific RequestProcessors in manipulateVisitProperties method. Also temporarily made GoalManager a singleton that is set as a static var in GoalsRequestProcessor. Should be in DI, but until all of Visit::handle() is dealt w/, this can't be done.
Diffstat (limited to 'plugins/Goals')
-rw-r--r-- | plugins/Goals/Tracker/GoalsRequestProcessor.php | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/plugins/Goals/Tracker/GoalsRequestProcessor.php b/plugins/Goals/Tracker/GoalsRequestProcessor.php index 0cadff1a21..22315f7511 100644 --- a/plugins/Goals/Tracker/GoalsRequestProcessor.php +++ b/plugins/Goals/Tracker/GoalsRequestProcessor.php @@ -9,6 +9,7 @@ namespace Piwik\Plugins\Goals\Tracker; use Piwik\Common; +use Piwik\Tracker\Action; use Piwik\Tracker\GoalManager; use Piwik\Tracker\Request; use Piwik\Tracker\RequestProcessor; @@ -21,13 +22,20 @@ use Piwik\Tracker\Visit\VisitProperties; */ class GoalsRequestProcessor extends RequestProcessor { + /** + * TODO: GoalManager should be stateless and stored in DI. + * + * @var GoalManager + */ + public static $goalManager = null; + public function processRequestParams(VisitProperties $visitProperties, Request $request) { - $goalManager = new GoalManager($request); // TODO: GoalManager should be stateless and stored in DI. + self::$goalManager = new GoalManager($request); - if ($goalManager->isManualGoalConversion()) { + if (self::$goalManager->isManualGoalConversion()) { // this request is from the JS call to piwikTracker.trackGoal() - $someGoalsConverted = $goalManager->detectGoalId($request->getIdSite()); + $someGoalsConverted = self::$goalManager->detectGoalId($request->getIdSite()); $visitProperties->setRequestMetadata('Goals', 'someGoalsConverted', $someGoalsConverted); $visitProperties->setRequestMetadata('Goals', 'visitIsConverted', $someGoalsConverted); @@ -36,11 +44,30 @@ class GoalsRequestProcessor extends RequestProcessor // if we find a idgoal in the URL, but then the goal is not valid, this is most likely a fake request if (!$someGoalsConverted) { - Common::printDebug('Invalid goal tracking request for goal id = ' . $goalManager->idGoal); + Common::printDebug('Invalid goal tracking request for goal id = ' . self::$goalManager->idGoal); return true; } } return false; } -}
\ No newline at end of file + + public function manipulateVisitProperties(VisitProperties $visitProperties, Request $request) + { + $visitsConverted = $visitProperties->getRequestMetadata('Goals', 'visitIsConverted'); + + /** @var Action $action */ + $action = $visitProperties->getRequestMetadata('Actions', 'action'); + + // if the visit hasn't already been converted another way (ie, manual goal conversion or ecommerce conversion, + // try to convert based on the action) + if (!$visitsConverted + && $action + ) { + $someGoalsConverted = self::$goalManager->detectGoalsMatchingUrl($request->getIdSite(), $action); + + $visitProperties->setRequestMetadata('Goals', 'someGoalsConverted', $someGoalsConverted); + $visitProperties->setRequestMetadata('Goals', 'visitIsConverted', $someGoalsConverted); + } + } +} |