3namespace Bitrix\Seo\Retargeting;
5use Bitrix\Main\Localization\Loc;
7use Bitrix\Seo\Retargeting\Audience\Status\AudienceStatusNormalizerFactory;
28 return Loader::includeModule(
'seo') && Loader::includeModule(
'socialservices');
38 self::$isQueueUsed =
true;
69 self::$errors[] = Loc::getMessage(
"SEO_RETARGETING_EMPTY_AUDIENCE_NAME");
72 $audience->setAccountId($accountId);
76 $addResult = $audience->add($parameters);
77 if ($addResult->isSuccess() && $addResult->getId())
79 return $addResult->getId();
83 self::$errors = $addResult->getErrorMessages();
95 $audience->setAccountId($accountId);
96 $addResult = $audience->createLookalike($sourceAudienceId,
$options);
97 if ($addResult->isSuccess() && $addResult->getId())
99 return $addResult->getId();
103 self::$errors = $addResult->getErrorMessages();
127 $audience->setAccountId($accountId);
128 $audiencesResult = $audience->getList();
129 if ($audiencesResult->isSuccess())
131 while ($audienceData = $audiencesResult->fetch())
133 $audienceData = $audience->normalizeListRow($audienceData);
134 if ($audienceData[
'ID'])
137 'id' => $audienceData[
'ID'],
138 'isSupportMultiTypeContacts' => $audience->isSupportMultiTypeContacts(),
140 'supportedContactTypes' => $audienceData[
'SUPPORTED_CONTACT_TYPES'],
141 'status' => $audienceData[
'STATUS'] ??
'',
143 $audienceData[
'NAME']
145 $audienceData[
'NAME'] . (
146 $audienceData[
'COUNT_VALID'] > 0 ?
147 ' (' . $audienceData[
'COUNT_VALID'] .
')'
159 self::$errors = $audiencesResult->getErrorMessages();
167 $audiences = static::getAudiences(
$type, $accountId);
172 foreach ($audiences as &$audience)
174 $audienceStatus = $audience[
'status'];
176 $audience[
'normalizedStatus'] = $audienceStatusNormalizer->getNormalizedStatus($audienceStatus);
177 $audience[
'normalizedStatusMessage'] = $audienceStatusNormalizer->getNormalizedStatusTranslation($audienceStatus);
178 $audience[
'isEnabled'] = $audienceStatusNormalizer->isEnabled($audienceStatus);
192 return $account->getRegionsList();
203 $providers = static::getServiceProviders($types);
207 $providers[
$type][
'URL_AUDIENCE_LIST'] = $audience->getUrlAudienceList();
208 $providers[
$type][
'IS_SUPPORT_ACCOUNT'] = $audience->isSupportAccount();
209 $providers[
$type][
'IS_SUPPORT_REMOVE_CONTACTS'] = $audience->isSupportRemoveContacts();
211 $providers[
$type][
'IS_SUPPORT_MULTI_TYPE_CONTACTS'] = $audience->isSupportMultiTypeContacts();
212 $providers[
$type][
'IS_SUPPORT_ADD_AUDIENCE'] = $audience->isSupportAddAudience();
213 $lookalikeAudienceParams = $audience->getLookalikeAudiencesParams();
214 $providers[
$type][
'IS_SUPPORT_LOOKALIKE_AUDIENCE'] = !!$lookalikeAudienceParams;
215 $providers[
$type][
'LOOKALIKE_AUDIENCE_PARAMS'] = $lookalikeAudienceParams;
216 $providers[
$type][
'IS_SUPPORT_CREATE_LOOKALIKE_FROM_SEGMENTS'] = $audience::isSupportCreateLookalikeFromSegments();
230 static $audiences =
array();
231 if (!isset($audiences[
$config->type]))
239 $audiences[
$config->type] = $audience;
243 $audience = $audiences[
$config->type];
246 $audience->setAccountId(
$config->accountId);
247 static::$isQueueUsed ? $audience->enableQueueMode() : $audience->disableQueueMode();
248 if (
$config->autoRemoveDayNumber)
250 $audience->enableQueueAutoRemove(
$config->autoRemoveDayNumber);
254 $audience->disableQueueAutoRemove();
257 $audienceImportResult = $audience->addContacts(
261 'type' =>
$config->contactType,
262 'parentId' =>
$config->parentId
266 self::$errors = $audienceImportResult->getErrorMessages();
267 return $audienceImportResult->isSuccess();
277 return self::$errors;
287 self::$errors =
array();
297 return count(self::$errors) > 0;
308 static::getService()->getAuthAdapter(
$type)->removeAuth();
318 if (!static::canUse())
323 return static::getService()->getTypes();
334 $typeList = static::getServiceTypes();
336 $providers =
array();
337 foreach ($typeList as
$type)
339 if ($types && !in_array(
$type, $types))
347 $canUserMultiClients = $authAdapter->canUseMultipleClients();
351 'HAS_AUTH' => $authAdapter->hasAuth(),
352 'AUTH_URL' => $authAdapter->getAuthUrl(),
353 'PROFILE' => $authAdapter->getToken() ? $account->getProfileCached() :
false,
354 'ENGINE_CODE' => $service::getEngineCode(
$type)
356 if ($canUserMultiClients)
358 $providers[
$type][
'CLIENTS'] = static::getClientsProfiles($authAdapter);
359 if (empty($providers[
$type][
'CLIENTS']))
361 $providers[
$type][
'HAS_AUTH'] =
false;
366 if ($providers[
$type][
'HAS_AUTH'] && empty($providers[
$type][
'PROFILE']))
368 static::removeAuth(
$type);
369 if (!$canUserMultiClients)
371 $providers[
$type][
'HAS_AUTH'] =
false;
387 return array_values(array_filter(array_map(
function ($item) use (
$type) {
389 $service->setClientId($item[
'proxy_client_id']);
396 $account->getRequest()->setAuthAdapter($authAdapter);
398 $profile = $account->getProfileCached();
419 if (!static::canUse())
426 $account = static::getService()->getAccount(
$type);
427 $accountsResult = $account->getList();
428 if ($accountsResult->isSuccess())
430 while ($accountData = $accountsResult->fetch())
432 $accountData = $account->normalizeListRow($accountData);
433 if ($accountData[
'ID'])
436 'id' => $accountData[
'ID'],
437 'name' => $accountData[
'NAME'] ? $accountData[
'NAME'] : $accountData[
'ID']
444 self::$errors = $accountsResult->getErrorMessages();
if(!Loader::includeModule('messageservice')) $provider
static getClientsProfiles(AuthAdapter $authAdapter)
static addLookalikeAudience($type, $accountId=null, $sourceAudienceId=null, $options=[])
static getAudiences($type, $accountId=null)
static getProviders(array $types=null)
static getAccounts($type)
static getAudienceWithNormalizedStatus($type, string $messageCode, $accountId=null)
static addToAudience(AdsAudienceConfig $config, $contacts)
static getServiceProviders(array $types=null)
static addAudience($type, $accountId=null, $name=null)
static build(string $typeCode, string $messageCode)
setService(IService $service)
getAuthorizedClientsList()
static getAudience($type)
static getAuthAdapter($type)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"