305 $clientId = $config->getOption(
'CLIENT_ID')->getValue();
306 $body = $config->getOption(
'BODY')->getValue();
307 $targetUrl = $config->getOption(
'TARGET_URL')->getValue();
308 $campaignName = $config->getOption(
'TITLE')->getValue();
320 if(!filter_var($targetUrl, FILTER_VALIDATE_URL))
331 [
'CODE' =>
'utm_source',
'VALUE' =>
'b24_sender_'.static::CODE],
332 [
'CODE' =>
'utm_medium',
'VALUE' =>
'ads'],
333 [
'CODE' =>
'utm_campaign',
'VALUE' => $campaignName]
336 if (!mb_strpos($targetUrl,
'b24_sender_'.static::CODE))
339 foreach($utmMarks as $utmMark)
341 $preparedMarks[$utmMark[
'CODE']] = $utmMark[
'VALUE'];
344 $config->getOption(
'TARGET_URL')->setValue(sprintf(
'%s/?%s',$targetUrl, http_build_query($preparedMarks)));
347 return Entity\Message::create()
350 ->saveConfiguration($this->configuration);
397 $clientId = $config->get(
'CLIENT_ID');
398 $accountId = $config->get(
'ACCOUNT_ID');
399 $instagramActorId = $config->get(
'INSTAGRAM_ACTOR_ID');
400 $permalink = $config->get(
'PERMALINK');
401 $targetUrl = $config->get(
'TARGET_URL');
402 $campaignId = $config->get(
'CAMPAIGN_ID');
403 $adSetId = $config->get(
'AD_SET_ID');
404 $creativeId = $config->get(
'CREATIVE_ID');
405 $body = $config->get(
'BODY');
406 $budget = $config->get(
'BUDGET');
407 $duration = $config->get(
'DURATION');
408 $adsId = $config->get(
'ADS_ID');
409 $pageId = $config->get(
'PAGE_ID');
410 $title = $config->get(
'TITLE');
411 $imageUrl = $config->get(
'IMAGE_URL');
412 $audienceId = $config->get(
'AUDIENCE_ID');
413 $mediaId = $config->get(
'MEDIA_ID');
414 $phoneAudienceId = $config->get(
'AUDIENCE_PHONE_ID');
415 $emailAudienceId = $config->get(
'AUDIENCE_EMAIL_ID');
416 $ageFrom = $config->get(
'AGE_FROM');
417 $ageTo = $config->get(
'AGE_TO');
418 $genders = $config->get(
'GENDERS') ? Json::decode($config->get(
'GENDERS')) : [];
419 $interests = $config->get(
'INTERESTS') ? Json::decode($config->get(
'INTERESTS')) : [];
420 $regions = $config->get(
'REGIONS') ? Json::decode($config->get(
'REGIONS')) : [];
421 $service = Marketing\Configurator::getService();
422 $service->setClientId($clientId);
424 $response = Marketing\Configurator::createCampaign(
425 Marketing\Services\AdCampaignFacebook::TYPE_CODE,
427 'accountId' => $accountId,
428 'instagramAccountId' => $instagramActorId,
430 'permalink' => $permalink,
431 'targetUrl' => $targetUrl,
432 'mediaId' => $mediaId,
433 'imageUrl' => $imageUrl,
434 'audience' => $audienceId,
435 'campaignId' => $campaignId,
436 'adSetId' => $adSetId,
437 'creativeId' => $creativeId,
438 'audienceId' => $audienceId,
439 'phoneAudienceId' => $phoneAudienceId,
440 'emailAudienceId' => $emailAudienceId,
441 'regions' => $regions,
442 'interests' => $interests,
443 'genders' => $genders,
445 'ageFrom' => $ageFrom,
447 'budget' => ($budget?: 100) * 100,
448 'duration' => $duration,
449 'type' => static::CODE,
452 'status' => self::STATUS_ACTIVE
456 $config->set(
'ADS_ID', $response[
'adsId']);
457 $config->set(
'CREATIVE_ID', $response[
'creativeId']);
458 $config->set(
'CAMPAIGN_ID', $response[
'campaignId']);
459 $config->set(
'AD_SET_ID', $response[
'adSetId']);
460 $config->set(
'STATUS', self::STATUS_ACTIVE);
463 $result->setSuccess(
true);
465 if (isset($response[
'RESULT']))
467 $responseResult = json_decode($response[
'RESULT'],
true);
468 $result->setSuccess(
false);
470 $errors[] = new \Bitrix\Main\Error($responseResult[
'error'][
'message']??
'');
471 $result->addErrors($errors);
474 $result->setSuccess(
true);