Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
service.php
1<?php
10
14
20{
26 public static function canUse()
27 {
28 if (!Loader::includeModule('seo'))
29 {
30 return false;
31 }
32
33 return Retargeting\AdsAudience::canUse();
34 }
35
41 public static function isAvailable()
42 {
43 return self::canUse() && Integration\Bitrix24\Service::isAdAvailable();
44 }
45
51 public static function getTypeMap()
52 {
53 return array(
54 MessageBase::CODE_ADS_FB => Retargeting\Service::TYPE_FACEBOOK,
55 MessageBase::CODE_ADS_VK => Retargeting\Service::TYPE_VKONTAKTE,
56 MessageBase::CODE_ADS_YA => Retargeting\Service::TYPE_YANDEX,
57 MessageBase::CODE_ADS_GA => Retargeting\Service::TYPE_GOOGLE,
58 MessageBase::CODE_ADS_LOOKALIKE_FB => Retargeting\Service::TYPE_FACEBOOK,
59 MessageBase::CODE_ADS_LOOKALIKE_VK => Retargeting\Service::TYPE_VKONTAKTE,
60 MessageBase::CODE_ADS_LOOKALIKE_YANDEX => Retargeting\Service::TYPE_YANDEX,
61 );
62 }
63
70 public static function getAdsProvider($adsType, $clientId = null)
71 {
72 $service = Retargeting\AdsAudience::getService();
73 $service->setClientId($clientId);
74 $providers = Retargeting\AdsAudience::getProviders([$adsType]);
75 $isFound = false;
76 $provider = array();
77 foreach ($providers as $type => $provider)
78 {
79 if ($type == $adsType)
80 {
81 $isFound = true;
82 break;
83 }
84 }
85
86 if (!$isFound)
87 {
88 return null;
89 }
90
91 return $provider;
92 }
93
101 public static function send(\stdClass $config, array $contacts)
102 {
103 if (!static::canUse())
104 {
105 return false;
106 }
107
108 $audience = Retargeting\Service::getAudience($config->type);
109 $audience->setAccountId($config->accountId);
110 $audience->enableQueueMode();
111
112 if ($config->autoRemoveDayNumber)
113 {
114 $audience->enableQueueAutoRemove($config->autoRemoveDayNumber);
115 }
116 else
117 {
118 $audience->disableQueueAutoRemove();
119 }
120
121 $audienceImportResult = $audience->addContacts(
122 $config->audienceId,
123 $contacts,
124 array(
125 'type' => $config->contactType
126 )
127 );
128
129 return $audienceImportResult->isSuccess();
130 }
131}
static includeModule($moduleName)
Definition loader.php:69
static send(\stdClass $config, array $contacts)
Definition service.php:101
static getAdsProvider($adsType, $clientId=null)
Definition service.php:70