public function hasGoal($counter, $goal) { $goals = $this->client->goals()->getGoals($counter->getId()); /** @var Goal $remote */ foreach ($goals as $remote) { $conditions = $remote->getConditions() ? $remote->getConditions()->getAll() : array(); /** @var Condition $condition */ foreach ($conditions as $condition) { if ($condition->getUrl() == $goal->getAlias()) { return true; } } } return false; }
public function testGetGoalsClient() { $token = 'test'; $metricaClient = new ManagementClient($token); $client = $metricaClient->goals(); $this->assertTrue($client instanceof GoalsClient); $this->assertEquals($token, $client->getAccessToken()); }
*/ use Yandex\Metrica\Management\ManagementClient; $goals = array(); $errorMessage = false; //Is auth if (isset($_COOKIE['yaAccessToken']) && isset($_COOKIE['yaClientId'])) { $settings = (require_once '../../settings.php'); try { $managementClient = new ManagementClient($_COOKIE['yaAccessToken']); if (isset($_GET['counter-id']) && $_GET['counter-id']) { $counterId = $_GET['counter-id']; //GET /management/v1/counter/{counterId}/goals; /** * @see http://api.yandex.ru/metrika/doc/beta/management/goals/goals.xml */ $goals = $managementClient->goals()->getGoals($counterId); } } catch (\Exception $ex) { $errorMessage = $ex->getMessage(); if ($errorMessage === 'PlatformNotAllowed') { $errorMessage .= '<p>Возможно, у приложения нет прав на доступ к ресурсу. Попробуйте ' . '<a href="' . rtrim(str_replace($_SERVER['DOCUMENT_ROOT'], '', __DIR__), "/") . '/../OAuth/' . '">авторизироваться</a> и повторить.</p>'; } } } ?> <!doctype html> <html lang="en-US"> <head> <meta charset="UTF-8"> <title>Yandex.SDK: Metrica Demo</title>