dbTableName, 'idgoal', GoalManager::IDGOAL_ORDER); } public function configureSegments(SegmentsList $segmentsList, DimensionSegmentFactory $dimensionSegmentFactory) { //new Segment revenue on order $segment = new Segment(); $segment->setCategory($this->category); $segment->setName(Piwik::translate('Ecommerce_OrderRevenue')); $segment->setSegment('revenueOrder'); $segment->setSqlSegment('log_conversion.idvisit'); $segment->setSqlFilter(function ($valueToMatch, $sqlField, $matchType) { return $this->getRevenueQuery($valueToMatch, $sqlField , $matchType, 0); }); $segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment)); //new Segment revenue left in cart $segment = new Segment(); $segment->setCategory($this->category); $segment->setName(Piwik::translate('Ecommerce_RevenueLeftInCart')); $segment->setSegment('revenueAbandonedCart'); $segment->setSqlSegment('log_conversion.idvisit'); $segment->setSqlFilter(function ($valueToMatch, $sqlField , $matchType) { return $this->getRevenueQuery($valueToMatch, $sqlField , $matchType,-1); }); $segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment)); } /** * revenue sql filter * @param $valueToMatch * @param $sqlField * @param $matchType * @param false $cart * @return array */ private function getRevenueQuery($valueToMatch, $sqlField , $matchType, $idGoal) { //supported operator type $supportType = [ SegmentExpression::MATCH_EQUAL, SegmentExpression::MATCH_GREATER_OR_EQUAL, SegmentExpression::MATCH_LESS_OR_EQUAL, SegmentExpression::MATCH_GREATER, SegmentExpression::MATCH_LESS, ]; if (!in_array($matchType, $supportType)) { throw new \Exception("This match type $matchType is not available for action-segments."); } //to fit mysql operator if ($matchType === SegmentExpression::MATCH_EQUAL) { $matchType = "="; } $table = Common::prefixTable($this->dbTableName); $sql = " SELECT idvisit from {$table} WHERE (idgoal = {$idGoal} and revenue {$matchType} ?) "; return [ 'SQL' => $sql, 'bind' =>(float)$valueToMatch, ]; } /** * @param Request $request * @param Visitor $visitor * @param Action|null $action * @param GoalManager $goalManager * * @return mixed|false */ public function onGoalConversion(Request $request, Visitor $visitor, $action, GoalManager $goalManager) { $defaultRevenue = $goalManager->getGoalColumn('revenue'); $revenue = $request->getGoalRevenue($defaultRevenue); return $this->roundRevenueIfNeeded($revenue); } /** * @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); } /** * @param Request $request * @param Visitor $visitor * @param Action|null $action * @param GoalManager $goalManager * * @return mixed|false */ public function onEcommerceCartUpdateConversion(Request $request, Visitor $visitor, $action, GoalManager $goalManager) { return $this->onEcommerceOrderConversion($request, $visitor, $action, $goalManager); } }