- Модуль: sender
- Путь к файлу: ~/bitrix/modules/sender/lib/integration/seo/ads/messagemarketingfb.php
- Класс: Bitrix\Sender\Integration\Seo\Ads\MessageMarketingFb
- Вызов: MessageMarketingFb::onAfterEnd
public function onAfterEnd()
: \Bitrix\Main\Result
{
$result = new EventResult();
$config = $this->configuration;
$clientId = $config->get('CLIENT_ID');
$accountId = $config->get('ACCOUNT_ID');
$instagramActorId = $config->get('INSTAGRAM_ACTOR_ID');
$permalink = $config->get('PERMALINK');
$targetUrl = $config->get('TARGET_URL');
$campaignId = $config->get('CAMPAIGN_ID');
$adSetId = $config->get('AD_SET_ID');
$creativeId = $config->get('CREATIVE_ID');
$body = $config->get('BODY');
$budget = $config->get('BUDGET');
$duration = $config->get('DURATION');
$adsId = $config->get('ADS_ID');
$pageId = $config->get('PAGE_ID');
$title = $config->get('TITLE');
$imageUrl = $config->get('IMAGE_URL');
$audienceId = $config->get('AUDIENCE_ID');
$mediaId = $config->get('MEDIA_ID');
$phoneAudienceId = $config->get('AUDIENCE_PHONE_ID');
$emailAudienceId = $config->get('AUDIENCE_EMAIL_ID');
$ageFrom = $config->get('AGE_FROM');
$ageTo = $config->get('AGE_TO');
$genders = $config->get('GENDERS') ? Json::decode($config->get('GENDERS')) : [];
$interests = $config->get('INTERESTS') ? Json::decode($config->get('INTERESTS')) : [];
$regions = $config->get('REGIONS') ? Json::decode($config->get('REGIONS')) : [];
$service = Marketing\Configurator::getService();
$service->setClientId($clientId);
$response = Marketing\Configurator::createCampaign(
Marketing\Services\AdCampaignFacebook::TYPE_CODE,
[
'accountId' => $accountId,
'instagramAccountId' => $instagramActorId,
'name' => $title,
'permalink' => $permalink,
'targetUrl' => $targetUrl,
'mediaId' => $mediaId,
'imageUrl' => $imageUrl,
'audience' => $audienceId,
'campaignId' => $campaignId,
'adSetId' => $adSetId,
'creativeId' => $creativeId,
'audienceId' => $audienceId,
'phoneAudienceId' => $phoneAudienceId,
'emailAudienceId' => $emailAudienceId,
'regions' => $regions,
'interests' => $interests,
'genders' => $genders,
'ageTo' => $ageTo,
'ageFrom' => $ageFrom,
'body' => $body,
'budget' => ($budget?: 100) * 100,
'duration' => $duration,
'type' => static::CODE,
'adsId' => $adsId,
'pageId' => $pageId,
'status' => self::STATUS_ACTIVE
]
);
$config->set('ADS_ID', $response['adsId']);
$config->set('CREATIVE_ID', $response['creativeId']);
$config->set('CAMPAIGN_ID', $response['campaignId']);
$config->set('AD_SET_ID', $response['adSetId']);
$config->set('STATUS', self::STATUS_ACTIVE);
$this->saveConfiguration($config);
$result->setSuccess(true);
if (isset($response['RESULT']))
{
$responseResult = json_decode($response['RESULT'], true);
$result->setSuccess(false);
$errors[] = new \Bitrix\Main\Error($responseResult['error']['message']?? '');
$result->addErrors($errors);
}
$result->setSuccess(true);
return $result;
}