9use \Bitrix\Seo\Retargeting\Audience;
19 private const EXAMPLE_MAIL =
'example@mail.domain';
27 'COUNT_VALID' =>
'VALID_UNIQUE_QUANTITY',
28 'COUNT_MATCHED' =>
'MATCHED_QUANTITY',
31 'SUPPORTED_CONTACT_TYPES' => array(
32 self::ENUM_CONTACT_TYPE_PHONE,
33 self::ENUM_CONTACT_TYPE_EMAIL
43 self::ENUM_CONTACT_TYPE_PHONE,
44 self::ENUM_CONTACT_TYPE_EMAIL
47 static::$listRowMap[
'SUPPORTED_CONTACT_TYPES'] = $map[$row[
'CONTENT_TYPE']];
48 return parent::normalizeListRow($row);
87 public function add(array $data)
89 $response = $this->request->send(array(
90 'methodName' =>
'retargeting.audience.add',
91 'parameters' => array(
92 'name' => $data[
'NAME'],
94 'contacts' => $this->
prepareContacts([
"email" => [self::EXAMPLE_MAIL]]),
98 $responseData = $response->getData();
99 if (isset($responseData[
'id']))
101 $response->setId($responseData[
'id']);
115 protected function prepareContacts(array $contacts = array(), $hashed =
false, $type =
'')
121 $type => isset($contacts[$type]) ? $contacts[$type] : []
128 $types = array_keys($contacts);
129 $typeCount = count($types);
130 $result = implode($separator, $types);
131 foreach ($types as $index => $contactType)
133 foreach ($contacts[$contactType] as $contact)
135 $contact = $hashed ? md5($contact) : $contact;
136 $data = array_fill(0, $typeCount,
"");
137 $data[$index] = $contact;
138 $result .= $eol . implode($separator, $data);
154 $createNewAudience = (
$audienceId == static::NEW_AUDIENCE_FAKE_ID);
163 $hashed = (bool)$audienceData[
'HASHED'];
164 $payload = $this->
prepareContacts($contacts, $hashed, $options[
'type']);
166 if ($createNewAudience)
168 $name = $options[
'audienceName'] ?:
Loc::getMessage(
'SEO_RETARGETING_SERVICE_AUDIENCE_NAME_TEMPLATE', [
'#DATE#' => FormatDate(
'j F')]);
170 'methodName' =>
'retargeting.audience.add',
171 'parameters' => array(
173 'hashed' => $hashed ? 1 : 0,
174 'contacts' => $payload
176 'timeout' => static::UPDATE_AUDIENCE_TIMEOUT
182 'methodName' =>
'retargeting.audience.contacts.rewrite',
183 'parameters' => array(
185 'contacts' => $payload
187 'timeout' => static::UPDATE_AUDIENCE_TIMEOUT
216 'methodName' =>
'retargeting.audience.list',
217 'parameters' => array()
219 $data = $response->getData();
220 if (is_array($data[
'segments']))
222 $data = array_values(array_filter($data[
'segments'],
function ($item) {
224 $item[
'type'] ==
'uploading' &&
225 $item[
'content_type'] ==
'crm'
235 $response->setData($data);
246 array_unshift($data, [
247 'name' =>
Loc::getMessage(
"SEO_RETARGETING_SERVICE_AUDIENCE_YANDEX_ADD"),
248 'id' => static::NEW_AUDIENCE_FAKE_ID,
249 'valid_unique_quantity' =>
'',
250 'matched_quantity' =>
'',
264 'AUDIENCE_LOOKALIKE',
265 'DEVICE_DISTRIBUTION',
268 'AUDIENCE_LOOKALIKE' => [
284 'methodName' =>
'retargeting.audience.lookalike.add',
286 'name' => (
string) $options[
'name'],
287 'lookalike_link' => (
int) $sourceAudienceId,
288 'lookalike_value' => (
int) $options[
'lookalike_value'],
289 'maintain_device_distribution' => (
bool) $options[
'maintain_device_distribution'],
290 'maintain_geo_distribution' => (
bool) $options[
'maintain_geo_distribution'],
294 if ($result->isSuccess())
296 $result->setId($result->getData()[
'id']);
static getMessage($code, $replace=null, $language=null)
const UPDATE_AUDIENCE_TIMEOUT
removeContacts($audienceId, array $contacts, array $options)
static isAddingRequireContacts()
prepareContacts(array $contacts=array(), $hashed=false, $type='')
addNewAudienceValue($data)
static isSupportMultiTypeContacts()
const NEW_AUDIENCE_FAKE_ID
static isSupportAddAudience()
static isSupportAccount()
importContacts($audienceId, array $contacts, array $options)
static normalizeListRow(array $row)
static isSupportRemoveContacts()
const MIN_CONTACTS_FOR_ACTIVATING
const MAX_CONTACTS_PER_PACKET
getLookalikeAudiencesParams()
static isSupportCreateLookalikeFromSegments()
createLookalike($sourceAudienceId, array $options)