function detectGoals($idSite) { if (!Piwik_PluginsManager::getInstance()->isPluginActivated('Goals')) { return false; } $url = $this->action->getActionUrl(); $actionType = $this->action->getActionType(); $goals = $this->getGoalDefinitions($idSite); foreach ($goals as $goal) { $attribute = $goal['match_attribute']; // if the attribute to match is not the type of the current action if ($actionType == Piwik_Tracker_Action::TYPE_ACTION && $attribute != 'url' || $actionType == Piwik_Tracker_Action::TYPE_DOWNLOAD && $attribute != 'file' || $actionType == Piwik_Tracker_Action::TYPE_OUTLINK && $attribute != 'external_website') { continue; } $pattern_type = $goal['pattern_type']; switch ($pattern_type) { case 'regex': $pattern = '/' . $goal['pattern'] . '/'; if (!$goal['case_sensitive']) { $pattern .= 'i'; } $match = preg_match($pattern, $url) == 1; break; case 'contains': if ($goal['case_sensitive']) { $matched = strpos($url, $goal['pattern']); } else { $matched = stripos($url, $goal['pattern']); } $match = $matched !== false; break; case 'exact': if ($goal['case_sensitive']) { $matched = strcmp($goal['pattern'], $url); } else { $matched = strcasecmp($goal['pattern'], $url); } $match = $matched == 0; break; default: throw new Exception("Pattern type {$pattern_type} not valid."); break; } if ($match) { $this->matchedGoals[] = $goal; } } // var_dump($this->matchedGoals);exit; return count($this->matchedGoals) > 0; }
/** * Look at the URL or Page Title and sees if it matches any existing Goal definition * * @param int $idSite * @param Piwik_Tracker_Action $action * @throws Exception * @return int Number of goals matched */ function detectGoalsMatchingUrl($idSite, $action) { if (!Piwik_Common::isGoalPluginEnabled()) { return false; } $decodedActionUrl = $action->getActionUrl(); $actionType = $action->getActionType(); $goals = $this->getGoalDefinitions($idSite); foreach ($goals as $goal) { $attribute = $goal['match_attribute']; // if the attribute to match is not the type of the current action if ($actionType == Piwik_Tracker_Action::TYPE_ACTION_URL && $attribute != 'url' && $attribute != 'title' || $actionType == Piwik_Tracker_Action::TYPE_DOWNLOAD && $attribute != 'file' || $actionType == Piwik_Tracker_Action::TYPE_OUTLINK && $attribute != 'external_website' || $attribute == 'manually') { continue; } $url = $decodedActionUrl; // Matching on Page Title if ($attribute == 'title') { $url = $action->getActionName(); } $pattern_type = $goal['pattern_type']; switch ($pattern_type) { case 'regex': $pattern = $goal['pattern']; if (strpos($pattern, '/') !== false && strpos($pattern, '\\/') === false) { $pattern = str_replace('/', '\\/', $pattern); } $pattern = '/' . $pattern . '/'; if (!$goal['case_sensitive']) { $pattern .= 'i'; } $match = @preg_match($pattern, $url) == 1; break; case 'contains': if ($goal['case_sensitive']) { $matched = strpos($url, $goal['pattern']); } else { $matched = stripos($url, $goal['pattern']); } $match = $matched !== false; break; case 'exact': if ($goal['case_sensitive']) { $matched = strcmp($goal['pattern'], $url); } else { $matched = strcasecmp($goal['pattern'], $url); } $match = $matched == 0; break; default: throw new Exception(Piwik_TranslateException('General_ExceptionInvalidGoalPattern', array($pattern_type))); break; } if ($match) { $goal['url'] = $decodedActionUrl; $this->convertedGoals[] = $goal; } } // var_dump($this->convertedGoals);exit; return count($this->convertedGoals) > 0; }