Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiosmosis <benaka@piwik.pro>2015-07-23 02:38:22 +0300
committerdiosmosis <benaka@piwik.pro>2015-08-06 17:38:00 +0300
commitce95796113417924ac47eda75bba2c20317dbcf5 (patch)
tree168e8599a522dd13b4b000390c470f0fcbbbd4f5 /plugins/Ecommerce
parent27cc53695f62f60d8dfb6aec68b39637c406d9f5 (diff)
Re-add Request parameter to RequestProcessor::recordLogs(), make GoalManager stateless and store in DI, move logic in GoalManager that determined info about a tracking request to request metadata, change someGoalsConverted request metadata to goalsConverted metadata so we can see exactly which goals were converted.
Diffstat (limited to 'plugins/Ecommerce')
-rw-r--r--plugins/Ecommerce/Tracker/EcommerceRequestProcessor.php60
1 files changed, 54 insertions, 6 deletions
diff --git a/plugins/Ecommerce/Tracker/EcommerceRequestProcessor.php b/plugins/Ecommerce/Tracker/EcommerceRequestProcessor.php
index a072a46cf2..fd701207d9 100644
--- a/plugins/Ecommerce/Tracker/EcommerceRequestProcessor.php
+++ b/plugins/Ecommerce/Tracker/EcommerceRequestProcessor.php
@@ -16,23 +16,71 @@ use Piwik\Tracker\Visit\VisitProperties;
/**
* Handles ecommerce tracking requests.
*
- * Defines no new request metadata.
+ * ## Request Metadata
+ *
+ * This processor defines the following request metadata under the **Ecommerce**
+ * plugin:
+ *
+ * * **isRequestEcommerce**: If `true`, the request is for an ecommerce goal conversion.
+ *
+ * Set in `processRequestParams()`.
+ *
+ * * **isGoalAnOrder**: If `true` the request is tracking an ecommerce order.
+ *
+ * Set in `processRequestParams()`.
*/
class EcommerceRequestProcessor extends RequestProcessor
{
+ /**
+ * @var GoalManager
+ */
+ public $goalManager = null;
+
+ public function __construct(GoalManager $goalManager)
+ {
+ $this->goalManager = $goalManager;
+ }
+
public function processRequestParams(VisitProperties $visitProperties, Request $request)
{
- $goalManager = new GoalManager($request); // TODO: GoalManager should be stateless and stored in DI.
+ $isGoalAnOrder = $this->isRequestForAnOrder($request);
+ $visitProperties->setRequestMetadata('Ecommerce', 'isGoalAnOrder', $isGoalAnOrder);
- if ($goalManager->requestIsEcommerce) {
- $visitProperties->setRequestMetadata('Goals', 'someGoalsConverted', true);
+ $isRequestEcommerce = $this->isRequestEcommerce($request);
+ $visitProperties->setRequestMetadata('Ecommerce', 'isRequestEcommerce', $isRequestEcommerce);
+ if ($isRequestEcommerce) {
// Mark the visit as Converted only if it is an order (not for a Cart update)
- if ($goalManager->isGoalAnOrder()) {
+ $idGoal = GoalManager::IDGOAL_CART;
+ if ($isGoalAnOrder) {
+ $idGoal = GoalManager::IDGOAL_ORDER;
$visitProperties->setRequestMetadata('Goals', 'visitIsConverted', true);
}
+ $visitProperties->setRequestMetadata('Goals', 'goalsConverted', array(array('idgoal' => $idGoal)));
+
$visitProperties->setRequestMetadata('Actions', 'action', null); // don't track actions when tracking ecommerce orders
}
}
-} \ No newline at end of file
+
+ public function afterRequestProcessed(VisitProperties $visitProperties, Request $request)
+ {
+ $goalsConverted = $visitProperties->getRequestMetadata('Goals', 'goalsConverted');
+ if (!empty($goalsConverted)) {
+ $isThereExistingCartInVisit = $this->goalManager->detectIsThereExistingCartInVisit($visitProperties->visitorInfo);
+ $visitProperties->setRequestMetadata('Goals', 'isThereExistingCartInVisit', $isThereExistingCartInVisit);
+ }
+ }
+
+ private function isRequestForAnOrder(Request $request)
+ {
+ $orderId = $request->getParam('ec_id');
+ return !empty($orderId);
+ }
+
+ private function isRequestEcommerce(Request $request)
+ {
+ $idGoal = $request->getParam('idgoal');
+ return 0 == $idGoal;
+ }
+}