Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
accountgoogle.php
1
<?
2
3
namespace
Bitrix\Seo\Analytics\Services
;
4
5
use
Bitrix\Main\NotImplementedException
;
6
use
Bitrix\Main\PhoneNumber\Parser
;
7
use
Bitrix\Main\Result
;
8
use
Bitrix\Main\Type\Date
;
9
use
Bitrix\Main\Web\Json
;
10
11
use
Bitrix\Seo\Analytics
;
12
use
Bitrix\Seo\Retargeting
;
13
14
class
AccountGoogle
extends
Analytics\Account
15
{
16
const
TYPE_CODE
=
'google'
;
17
18
public
function
getList
()
19
{
20
$response = $this->request->send(array(
21
'methodName'
=>
'analytics.account.list'
,
22
'parameters'
=> array()
23
));
24
25
return
$response;
26
}
27
28
public
function
getProfile
()
29
{
30
$response = $this->
getRequest
()->getClient()->get(
31
'https://www.googleapis.com/oauth2/v1/userinfo?access_token='
.
32
urlencode($this->
getRequest
()->getAuthAdapter()->getToken())
33
);
34
35
if
($response)
36
{
37
$response = Json::decode($response);
38
if
(is_array($response))
39
{
40
return
array(
41
'ID'
=> $response[
'id'
],
42
'NAME'
=> $response[
'name'
],
43
'LINK'
=>
''
,
44
'PICTURE'
=> $response[
'picture'
],
45
);
46
}
47
}
48
49
50
return
null
;
51
}
52
59
public
function
getExpenses
($accountId,
Date
$dateFrom =
null
,
Date
$dateTo =
null
)
60
{
61
$parameters = [
62
'ACCOUNT_ID'
=> $accountId,
63
];
64
if
($dateFrom && $dateTo)
65
{
66
$parameters[
'DATE_FROM'
] = $dateFrom->format(
'Ymd'
);
67
$parameters[
'DATE_TO'
] = $dateTo->format(
'Ymd'
);
68
}
69
$response = $this->
getRequest
()->send([
70
'methodName'
=>
'analytics.expenses.get'
,
71
'parameters'
=> $parameters,
72
]);
73
74
if
($response->isSuccess())
75
{
76
$data = $response->getData();
77
$response->setData([
78
'expenses'
=>
new
Analytics\Internals\
Expenses
([
79
'impressions'
=> $data[
'Impressions'
],
80
'clicks'
=> $data[
'Clicks'
],
81
'actions'
=> $data[
'Interactions'
],
82
'cpc'
=> $data[
'Avg. CPC'
],
83
'cpm'
=> $data[
'Avg. CPM'
],
84
'spend'
=> $data[
'Cost'
],
85
'currency'
=> $data[
'Currency'
],
86
]),
87
]);
88
}
89
90
return
$response;
91
}
92
102
public
function
getExpensesReport
($accountId,
Date
$dateFrom =
null
,
Date
$dateTo =
null
)
103
{
104
$parameters = [
105
'ACCOUNT_ID'
=> $accountId,
106
];
107
if
($dateFrom && $dateTo)
108
{
109
$parameters[
'DATE_FROM'
] = $dateFrom->format(
'Ymd'
);
110
$parameters[
'DATE_TO'
] = $dateTo->format(
'Ymd'
);
111
}
112
$response = $this->
getRequest
()->send([
113
'methodName'
=>
'analytics.expenses.report'
,
114
'parameters'
=> $parameters,
115
]);
116
117
return
$response;
118
}
119
120
126
public
function
hasExpensesReport
()
127
{
128
return
true
;
129
}
130
137
public
function
updateAnalyticParams
($accountId, array $params, array $publicPageIds = [])
138
{
139
$result =
new
Result
();
140
if
(!isset($params[
'phone'
]) && !isset($params[
'url_tags'
]))
141
{
142
return
$result;
143
}
144
$parameters = [
145
'ACCOUNT_ID'
=> $accountId,
146
];
147
if
(isset($params[
'phone'
]))
148
{
149
$phoneNumber =
Parser::getInstance
()->parse($params[
'phone'
]);
150
$parameters[
'PHONE'
] = [
'COUNTRY_CODE'
=> mb_strtoupper($phoneNumber->getCountry()),
'NUMBER'
=> $phoneNumber->format()];
151
}
152
if
(isset($params[
'url_tags'
]))
153
{
154
$parameters[
'URL_TAGS'
] = $params[
'url_tags'
];
155
}
156
157
return
$this->
getRequest
()->send([
158
'methodName'
=>
'analytics.update'
,
159
'parameters'
=> $parameters,
160
]);
161
}
162
}
Bitrix\Main\NotImplementedException
Definition
exception.php:147
Bitrix\Main\ORM\Data\Result
Definition
result.php:16
Bitrix\Main\PhoneNumber\Parser
Definition
parser.php:10
Bitrix\Main\PhoneNumber\Parser\getInstance
static getInstance()
Definition
parser.php:78
Bitrix\Main\Type\Date
Definition
date.php:9
Bitrix\Main\Web\Json
Definition
json.php:11
Bitrix\Seo\Analytics\Account
Definition
account.php:12
Bitrix\Seo\Analytics\Internals\Expenses
Definition
expenses.php:6
Bitrix\Seo\Analytics\Services\AccountGoogle
Definition
accountgoogle.php:15
Bitrix\Seo\Analytics\Services\AccountGoogle\TYPE_CODE
const TYPE_CODE
Definition
accountgoogle.php:16
Bitrix\Seo\Analytics\Services\AccountGoogle\updateAnalyticParams
updateAnalyticParams($accountId, array $params, array $publicPageIds=[])
Definition
accountgoogle.php:137
Bitrix\Seo\Analytics\Services\AccountGoogle\getList
getList()
Definition
accountgoogle.php:18
Bitrix\Seo\Analytics\Services\AccountGoogle\hasExpensesReport
hasExpensesReport()
Definition
accountgoogle.php:126
Bitrix\Seo\Analytics\Services\AccountGoogle\getExpensesReport
getExpensesReport($accountId, Date $dateFrom=null, Date $dateTo=null)
Definition
accountgoogle.php:102
Bitrix\Seo\Analytics\Services\AccountGoogle\getProfile
getProfile()
Definition
accountgoogle.php:28
Bitrix\Seo\Analytics\Services\AccountGoogle\getExpenses
getExpenses($accountId, Date $dateFrom=null, Date $dateTo=null)
Definition
accountgoogle.php:59
Bitrix\Seo\Retargeting\BaseApiObject\getRequest
getRequest()
Definition
baseapiobject.php:44
Bitrix\Seo\Analytics\Services
Definition
accountfacebook.php:3
Bitrix\Seo\Analytics
Definition
account.php:3
Bitrix\Seo\Retargeting
Definition
account.php:3
modules
seo
lib
analytics
services
accountgoogle.php
Создано системой
1.10.0