Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
audiencegoogle.php
1<?php
2
4
5use \Bitrix\Seo\Retargeting\Audience;
6
8{
9 const TYPE_CODE = 'google';
10
13 const URL_AUDIENCE_LIST = 'https://ads.google.com/aw/audiences/management';
14
15 protected static $listRowMap = array(
16 'ID' => 'ID',
17 'NAME' => 'NAME',
18 'SUPPORTED_CONTACT_TYPES' => array(
19 self::ENUM_CONTACT_TYPE_EMAIL,
20 self::ENUM_CONTACT_TYPE_IDFA_GAID
21 ),
22 );
23
24 public static function normalizeListRow(array $row)
25 {
26 $map = array(
27 'email' => self::ENUM_CONTACT_TYPE_EMAIL,
28 );
29 static::$listRowMap['SUPPORTED_CONTACT_TYPES'] = array($map[$row['CONTENT_TYPE']]);
30 return parent::normalizeListRow($row);
31 }
32
33 public static function isSupportMultiTypeContacts()
34 {
35 return true;
36 }
37
38 public static function isSupportAccount()
39 {
40 return true;
41 }
42
43 public static function isSupportRemoveContacts()
44 {
45 return true;
46 }
47
48 public function add(array $data)
49 {
50 $response = $this->request->send(array(
51 'methodName' => 'audience.add',
52 'parameters' => array(
53 'ACCOUNT_ID' => $this->accountId,
54 'NAME' => $data['NAME'],
55 'DESCRIPTION' => ''
56 )
57 ));
58
59 $responseData = $response->getData();
60 if (isset($responseData['id']))
61 {
62 $response->setId($responseData['id']);
63 }
64
65 return $response;
66 }
67
68 protected function prepareContacts(array $contacts = array(), $type = null)
69 {
70 if ($type && isset($contacts[$type]))
71 {
72 return $contacts[$type];
73 }
74
75 $data = array();
76 foreach (static::$listRowMap['SUPPORTED_CONTACT_TYPES'] as $contactType)
77 {
78 if (!isset($contacts[$contactType]) || !is_array($contacts[$contactType]))
79 {
80 continue;
81 }
82
83 $data = $contacts[$contactType];
84 }
85
86 return $data;
87 }
88
89 public function importContacts($audienceId, array $contacts, array $options)
90 {
91 $response = $this->request->send(array(
92 'methodName' => 'audience.importcontacts',
93 'parameters' => array(
94 'ACCOUNT_ID' => $this->accountId,
95 'AUDIENCE_ID' => $audienceId,
96 'LIST' => $this->prepareContacts($contacts, $options['type'])
97 )
98 ));
99
100 return $response;
101 }
102
103 public function removeContacts($audienceId, array $contacts, array $options)
104 {
105 $response = $this->request->send(array(
106 'methodName' => 'audience.removecontacts',
107 'parameters' => array(
108 'ACCOUNT_ID' => $this->accountId,
109 'AUDIENCE_ID' => $audienceId,
110 'LIST' => $this->prepareContacts($contacts, $options['type'])
111 )
112 ));
113
114 return $response;
115 }
116
117 public function getList()
118 {
119 $response = $this->request->send(array(
120 'methodName' => 'audience.list',
121 'parameters' => array(
122 'ACCOUNT_ID' => $this->accountId,
123 )
124 ));
125
126 return $response;
127 }
128
129 public function getAudienceIdFromRow(array $row = null)
130 {
131 $key = 'ID';
132 return (is_array($row) && $row[$key]) ? $row[$key] : null;
133 }
134
135 public static function isSupportAddAudience()
136 {
137 return true;
138 }
139}
removeContacts($audienceId, array $contacts, array $options)
importContacts($audienceId, array $contacts, array $options)
prepareContacts(array $contacts=array(), $type=null)