1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* User: naxel |
4
|
|
|
* Date: 17.02.14 11:29 |
5
|
|
|
*/ |
6
|
|
|
use Yandex\Metrica\Management\ManagementClient; |
7
|
|
|
|
8
|
|
|
$goals = array(); |
9
|
|
|
$errorMessage = false; |
10
|
|
|
|
11
|
|
|
//Is auth |
12
|
|
View Code Duplication |
if (isset($_COOKIE['yaAccessToken']) && isset($_COOKIE['yaClientId'])) { |
|
|
|
|
13
|
|
|
$settings = require_once '../../settings.php'; |
14
|
|
|
|
15
|
|
|
try { |
16
|
|
|
$managementClient = new ManagementClient($_COOKIE['yaAccessToken']); |
17
|
|
|
|
18
|
|
|
if (isset($_GET['counter-id']) && $_GET['counter-id']) { |
19
|
|
|
$counterId = $_GET['counter-id']; |
20
|
|
|
//GET /management/v1/counter/{counterId}/goals; |
21
|
|
|
/** |
22
|
|
|
* @see http://api.yandex.ru/metrika/doc/beta/management/goals/goals.xml |
23
|
|
|
*/ |
24
|
|
|
$goals = $managementClient->goals()->getGoals($counterId); |
25
|
|
|
} |
26
|
|
|
} catch (\Exception $ex) { |
27
|
|
|
$errorMessage = $ex->getMessage(); |
28
|
|
|
if ($errorMessage === 'PlatformNotAllowed') { |
29
|
|
|
$errorMessage .= '<p>Возможно, у приложения нет прав на доступ к ресурсу. Попробуйте ' |
30
|
|
|
. '<a href="' . rtrim(str_replace($_SERVER['DOCUMENT_ROOT'], '', __DIR__), "/") . '/../OAuth/' . '">авторизироваться</a> и повторить.</p>'; |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
?> |
35
|
|
|
<!doctype html> |
36
|
|
|
<html lang="en-US"> |
37
|
|
|
<head> |
38
|
|
|
<meta charset="UTF-8"> |
39
|
|
|
<title>Yandex.SDK: Metrica Demo</title> |
40
|
|
|
|
41
|
|
|
<link rel="stylesheet" href="//yandex.st/bootstrap/3.0.3/css/bootstrap.min.css"> |
42
|
|
|
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet"> |
43
|
|
|
<link rel="stylesheet" href="/examples/Disk/css/style.css"> |
44
|
|
|
|
45
|
|
|
</head> |
46
|
|
|
<body> |
47
|
|
|
|
48
|
|
|
<div class="container"> |
49
|
|
|
<div class="jumbotron"> |
50
|
|
|
<h2><a href="/examples/Metrica"><span class="glyphicon glyphicon-tasks"></span></a> Пример работы с Яндекс Метрикой</h2> |
51
|
|
|
</div> |
52
|
|
|
<ol class="breadcrumb"> |
53
|
|
|
<li><a href="/examples">Examples</a></li> |
54
|
|
|
<li><a href="/examples/Metrica">Metrica</a></li> |
55
|
|
|
<li><a href="/examples/Metrica/Management/counters.php">Счетчики</a></li> |
56
|
|
|
<li class="active">Цели</li> |
57
|
|
|
</ol> |
58
|
|
|
<?php |
59
|
|
View Code Duplication |
if (!isset($_COOKIE['yaAccessToken']) || !isset($_COOKIE['yaClientId'])) { |
|
|
|
|
60
|
|
|
?> |
61
|
|
|
<div class="alert alert-info"> |
62
|
|
|
Для просмотра этой страницы вам необходимо авторизироваться. |
63
|
|
|
<a id="goToAuth" href="/examples/OAuth" class="alert-link">Перейти на страницу авторизации</a>. |
64
|
|
|
</div> |
65
|
|
|
<?php |
66
|
|
|
} else { |
67
|
|
|
if ($errorMessage) { |
|
|
|
|
68
|
|
|
?> |
69
|
|
|
<div class="alert alert-danger"><?= $errorMessage ?></div> |
70
|
|
|
<?php |
71
|
|
|
} else { |
72
|
|
|
?> |
73
|
|
|
<div> |
74
|
|
|
<h3>Цели:</h3> |
75
|
|
|
<table id="countersTable" class="table table-striped table-bordered table-hover"> |
76
|
|
|
<thead> |
77
|
|
|
<tr> |
78
|
|
|
<td>ID</td> |
79
|
|
|
<td>Название</td> |
80
|
|
|
<td>Тип</td> |
81
|
|
|
<td>Класс</td> |
82
|
|
|
<td>Тип цели для клиентов Яндекс.Маркета</td> |
83
|
|
|
</tr> |
84
|
|
|
</thead> |
85
|
|
|
<tbody> |
86
|
|
|
<?php |
87
|
|
|
if ($goals instanceof Traversable) { |
88
|
|
|
foreach ($goals as $goal) { |
89
|
|
|
?> |
90
|
|
|
<tr> |
91
|
|
|
<td><?= $goal->getId() ?></td> |
92
|
|
|
<td><?= $goal->getName() ?></td> |
93
|
|
|
<td><?= $goal->getType() ?></td> |
94
|
|
|
<td><?= $goal->getClass() ?></td> |
95
|
|
|
<td><?= $goal->getFlag() ?></td> |
96
|
|
|
</tr> |
97
|
|
|
|
98
|
|
|
<?php |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
?> |
102
|
|
|
</tbody> |
103
|
|
|
</table> |
104
|
|
|
</div> |
105
|
|
|
<?php |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
?> |
109
|
|
|
</div> |
110
|
|
|
</body> |
111
|
|
|
</html> |
112
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.