Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
accountgoogle.php
1<?
2
4
10
13
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}
updateAnalyticParams($accountId, array $params, array $publicPageIds=[])
getExpensesReport($accountId, Date $dateFrom=null, Date $dateTo=null)
getExpenses($accountId, Date $dateFrom=null, Date $dateTo=null)