/** * Records an Ecommerce conversion in the DB. Deals with Items found in the request. * Will deal with 2 types of conversions: Ecommerce Order and Ecommerce Cart update (Add to cart, Update Cart etc). * * @param array $conversion * @param array $visitInformation */ protected function recordEcommerceGoal($conversion, $visitInformation) { if ($this->isThereExistingCartInVisit) { Common::printDebug("There is an existing cart for this visit"); } if ($this->isGoalAnOrder) { $conversion['idgoal'] = self::IDGOAL_ORDER; $conversion['idorder'] = $this->orderId; $conversion['buster'] = Common::hashStringToInt($this->orderId); $conversion['revenue_subtotal'] = $this->getRevenue($this->request->getParam('ec_st')); $conversion['revenue_tax'] = $this->getRevenue($this->request->getParam('ec_tx')); $conversion['revenue_shipping'] = $this->getRevenue($this->request->getParam('ec_sh')); $conversion['revenue_discount'] = $this->getRevenue($this->request->getParam('ec_dt')); $debugMessage = 'The conversion is an Ecommerce order'; } else { $conversion['buster'] = 0; $conversion['idgoal'] = self::IDGOAL_CART; $debugMessage = 'The conversion is an Ecommerce Cart Update'; } $conversion['revenue'] = $this->getRevenue($this->request->getGoalRevenue($defaultRevenue = 0)); Common::printDebug($debugMessage . ':' . var_export($conversion, true)); // INSERT or Sync items in the Cart / Order for this visit & order $items = $this->getEcommerceItemsFromRequest(); if ($items === false) { return; } $itemsCount = 0; foreach ($items as $item) { $itemsCount += $item[self::INTERNAL_ITEM_QUANTITY]; } $conversion['items'] = $itemsCount; if ($this->isThereExistingCartInVisit) { $updateWhere = array('idvisit' => $visitInformation['idvisit'], 'idgoal' => self::IDGOAL_CART, 'buster' => 0); $recorded = $this->updateExistingConversion($conversion, $updateWhere); } else { $recorded = $this->insertNewConversion($conversion, $visitInformation); } if ($recorded) { $this->recordEcommerceItems($conversion, $items, $visitInformation); } /** * Triggered after successfully persisting an 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). * @param array $visitInformation The visit entity that we are tracking a conversion for. See what * information it contains [here](/guides/persistence-and-the-mysql-backend#visits). */ Piwik::postEvent('Tracker.recordEcommerceGoal', array($conversion, $visitInformation)); }
/** * @param Request $request * @param Visitor $visitor * @param Action|null $action * @param GoalManager $goalManager * * @return mixed|false */ public function onEcommerceOrderConversion(Request $request, Visitor $visitor, $action, GoalManager $goalManager) { $defaultRevenue = 0; $revenue = $request->getGoalRevenue($defaultRevenue); return $this->roundRevenueIfNeeded($revenue); }