diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-06-18 01:05:17 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-06-18 01:05:17 +0400 |
commit | 23fcf598e04ec33d3c1b4f541a573b013a741b9d (patch) | |
tree | 669983feb709206b9a841cdb1212588c22cc0225 /core/Tracker/GoalManager.php | |
parent | cb6ae9d57117f918e6ea2f689df4bd1c6134cc65 (diff) |
moved more code from core to plugins, eg Visit, Actions and some Conversion columns
Diffstat (limited to 'core/Tracker/GoalManager.php')
-rw-r--r-- | core/Tracker/GoalManager.php | 105 |
1 files changed, 10 insertions, 95 deletions
diff --git a/core/Tracker/GoalManager.php b/core/Tracker/GoalManager.php index daa88bd7b9..9d7ece7c05 100644 --- a/core/Tracker/GoalManager.php +++ b/core/Tracker/GoalManager.php @@ -12,6 +12,7 @@ use Exception; use Piwik\Common; use Piwik\Config; use Piwik\Piwik; +use Piwik\Plugin\VisitDimension; use Piwik\Plugins\CustomVariables\CustomVariables; use Piwik\Tracker; @@ -186,43 +187,23 @@ class GoalManager /** * Records one or several goals matched in this request. * - * @param int $idSite + * @param Visitor $visitor * @param array $visitorInformation * @param array $visitCustomVariables * @param Action $action */ - public function recordGoals($idSite, $visitorInformation, $visitCustomVariables, $action) + public function recordGoals(Visitor $visitor, $visitorInformation, $visitCustomVariables, $action) { - $referrerTimestamp = $this->request->getParam('_refts'); - $referrerUrl = $this->request->getParam('_ref'); - $referrerCampaignName = trim(urldecode($this->request->getParam('_rcn'))); - $referrerCampaignKeyword = trim(urldecode($this->request->getParam('_rck'))); - $browserLanguage = $this->request->getBrowserLanguage(); - - $location_country = isset($visitorInformation['location_country']) - ? $visitorInformation['location_country'] - : Common::getCountry( - $browserLanguage, - $enableLanguageToCountryGuess = Config::getInstance()->Tracker['enable_language_to_country_guess'], - $visitorInformation['location_ip'] - ); - $goal = array( - 'idvisit' => $visitorInformation['idvisit'], - 'idsite' => $idSite, - 'idvisitor' => $visitorInformation['idvisitor'], - 'server_time' => Tracker::getDatetimeFromTimestamp($visitorInformation['visit_last_action_time']), - 'location_country' => $location_country, - 'visitor_returning' => $visitorInformation['visitor_returning'], - 'visitor_days_since_first' => $visitorInformation['visitor_days_since_first'], - 'visitor_days_since_order' => $visitorInformation['visitor_days_since_order'], - 'visitor_count_visits' => $visitorInformation['visitor_count_visits'], + 'idvisit' => $visitorInformation['idvisit'], + 'idvisitor' => $visitorInformation['idvisitor'], + 'server_time' => Tracker::getDatetimeFromTimestamp($visitorInformation['visit_last_action_time']) ); - $extraLocationCols = array('location_region', 'location_city', 'location_latitude', 'location_longitude'); - foreach ($extraLocationCols as $col) { - if (isset($visitorInformation[$col])) { - $goal[$col] = $visitorInformation[$col]; + foreach (VisitDimension::getAllDimensions() as $dimension) { + $value = $dimension->onRecordGoal($this->request, $visitor, $action); + if (false !== $value) { + $goal[$dimension->getFieldName()] = $value; } } @@ -244,55 +225,6 @@ class GoalManager } } - // Attributing the correct Referrer to this conversion. - // Priority order is as follows: - // 0) In some cases, the campaign is not passed from the JS so we look it up from the current visit - // 1) Campaign name/kwd parsed in the JS - // 2) Referrer URL stored in the _ref cookie - // 3) If no info from the cookie, attribute to the current visit referrer - - // 3) Default values: current referrer - $type = $visitorInformation['referer_type']; - $name = $visitorInformation['referer_name']; - $keyword = $visitorInformation['referer_keyword']; - $time = $visitorInformation['visit_first_action_time']; - - // 0) In some (unknown!?) cases the campaign is not found in the attribution cookie, but the URL ref was found. - // In this case we look up if the current visit is credited to a campaign and will credit this campaign rather than the URL ref (since campaigns have higher priority) - if (empty($referrerCampaignName) - && $type == Common::REFERRER_TYPE_CAMPAIGN - && !empty($name) - ) { - // Use default values per above - } // 1) Campaigns from 1st party cookie - elseif (!empty($referrerCampaignName)) { - $type = Common::REFERRER_TYPE_CAMPAIGN; - $name = $referrerCampaignName; - $keyword = $referrerCampaignKeyword; - $time = $referrerTimestamp; - } // 2) Referrer URL parsing - elseif (!empty($referrerUrl)) { - $referrer = new Referrer(); - $referrer = $referrer->getReferrerInformation($referrerUrl, $currentUrl = '', $idSite); - - // if the parsed referrer is interesting enough, ie. website or search engine - if (in_array($referrer['referer_type'], array(Common::REFERRER_TYPE_SEARCH_ENGINE, Common::REFERRER_TYPE_WEBSITE))) { - $type = $referrer['referer_type']; - $name = $referrer['referer_name']; - $keyword = $referrer['referer_keyword']; - $time = $referrerTimestamp; - } - } - $this->setCampaignValuesToLowercase($type, $name, $keyword); - - $goal += array( - 'referer_type' => $type, - 'referer_name' => $name, - 'referer_keyword' => $keyword, - // this field is currently unused - 'referer_visit_server_date' => date("Y-m-d", $time), - ); - // some goals are converted, so must be ecommerce Order or Cart Update if ($this->requestIsEcommerce) { $this->recordEcommerceGoal($goal, $visitorInformation); @@ -841,23 +773,6 @@ class GoalManager } /** - * @param $type - * @param $name - * @param $keyword - */ - protected function setCampaignValuesToLowercase($type, &$name, &$keyword) - { - if ($type === Common::REFERRER_TYPE_CAMPAIGN) { - if (!empty($name)) { - $name = Common::mb_strtolower($name); - } - if (!empty($keyword)) { - $keyword = Common::mb_strtolower($keyword); - } - } - } - - /** * @param $goal * @param $pattern_type * @param $url |