Campaigns
Note
此页面的内容需要进行重大更新。旧页面包含过时且可能不准确的信息。您仍然可以通过 Mautic Developer Documentation archived repository 访问它。
如果您有兴趣帮助开发此页面和其他新内容的,请考虑加入文档编写工作。
请阅读 Contributing Guidelines 和 Contributing to Mautic’s documentation 以开始您的贡献。
Registering Campaign Events
Mautic 派发事件 \Mautic\CampaignBundle\CampaignEvents::CAMPAIGN_ON_BUILD,供插件注册其 Campaign Actions、Conditions 和 Decisions。监听器接收一个 Mautic\CampaignBundle\Events\CampaignBuilderEvent 对象。使用以下描述的适当 add 方法注册该事件。
- class Mautic\CampaignBundle\Events\CampaignBuilderEvent
CampaignBuilderEvent 类
- public addAction(string $key, array $action)
- Parameters:
$key (
string) – Action 的唯一键。$action (
array) – Action 定义.
- Return type:
void
- public addCondition(string $key, array $condition)
- Parameters:
$key (
string) – Condition 的唯一键。$condition (
array) – Condition 定义.
- Return type:
void
- public addDecision(string $key, array $decision)
- Parameters:
$key (
string) – Decision 的唯一键。$decision (
array) – Decision 定义.
- Return type:
void
- public getActions()
- Returns:
注册的 Action 数组。
- Return type:
array
- public getConditions()
- Returns:
注册的 Condition 数组。
- Return type:
array
- public getDecisions()
- Returns:
注册的 Decision 数组。
- Return type:
array
Registering a Campaign Action
<?php
declare(strict_types=1);
namespace MauticPlugin\HelloWorldBundle\EventListener;
use Mautic\CampaignBundle\CampaignEvents;
use Mautic\CampaignBundle\Event\CampaignBuilderEvent;
use MauticPlugin\HelloWorldBundle\HelloWorldEvents;
use MauticPlugin\HelloWorldBundle\Form\Type\TravelType;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class CampaignActionSubscriber implements EventSubscriberInterface
{
public const TYPE = 'helloworld.action';
public static function getSubscribedEvents(): array
{
return [
CampaignEvents::CAMPAIGN_ON_BUILD => ['onCampaignBuild', 0],
];
}
- public function onCampaignBuild(CampaignBuilderEvent $event): void
- {
- $event->addAction(
self::TYPE, [
‘label’ => ‘helloworld.campaign.event.action’, ‘description’ => ‘helloworld.campaign.event.action.descr’, ‘batchEventName’ => HelloWorldEvents::EXECUTE_CAMPAIGN_ACTION, ‘formType’ => TravelType::class,
]
);
}
}
Campaign Action definition
Key |
Is required? |
Type |
Description |
|---|---|---|---|
|
yes |
string |
Display name for the UI. |
|
yes |
string |
The Campaign engine dispatches this Event through the |
|
no |
string |
Displays as the tool-tip for this Event. |
|
no |
string |
Symfony form type class for the Event’s configuration. |
|
no |
array |
Array of options passed into the given Symfony form type. |
|
no |
array |
Array of field:filter pairs of input masks supported by |
|
no |
string |
PHP template to customize the UI of the given form type. |
|
no |
array |
Array of restrictions defining the Events and anchors this Event is compatible with. |
|
no |
array |
Array of Event anchors this Event isn’t allowed to connect to. Names of anchors are |
|
no |
array[] |
Array with keys as Event types of |
|
no |
array[] |
Array with keys as Event types of |
|
no |
string |
PHP template to customize the UI for this Event in the Contact’s timeline. |
Registering a Campaign Condition
<?php
declare(strict_types=1);
namespace MauticPlugin\HelloWorldBundle\EventListener;
```markdown use MauticCampaignBundleCampaignEvents;
use MauticCampaignBundleEventCampaignBuilderEvent; use MauticPluginHelloWorldBundleHelloWorldEvents; use MauticPluginHelloWorldBundleFormTypeTravelType; use SymfonyComponentEventDispatcherEventSubscriberInterface;
class CampaignConditionSubscriber implements EventSubscriberInterface {
public const TYPE = ‘helloworld.condition’;
public static function getSubscribedEvents(): array {
- return [
CampaignEvents::CAMPAIGN_ON_BUILD => [‘onCampaignBuild’, 0],
];
}
public function onCampaignBuild(CampaignBuilderEvent $event): void {
- $event->addCondition(
self::TYPE, [
‘label’ => ‘helloworld.campaign.event.condition’, ‘description’ => ‘helloworld.campaign.event.condition.descr’, ‘eventName’ => HelloWorldEvents::EVALUATE_CAMPAIGN_CONDITION, ‘formType’ => TravelType::class,
]
);
}
}
Campaign Condition definition
- Key
Is required?
Type
Description
labelyes
string
UI 显示名称。
eventNameyes
string
Campaign 引擎通过
event_dispatcher服务分发此事件,当联系人到达流程中的某个阶段时触发。
descriptionno
string
作为此事件的工具提示显示。
formTypeno
string
Symfony form type class,用于配置该事件。
formTypeOptionsno
array
传递给给定 Symfony 表单类型的选项数组。
formTypeCleanMasksno
array
包含字段:过滤器对的输入掩码,由
Mautic\CoreBundle\Helper\InputHelper支持,用于清理表单提交的数据。
formTypeThemeno
string
PHP 模板,用于自定义给定表单类型的 UI。
connectionRestrictionsno
array
定义与此事件兼容的事件和锚点的限制数组。
connectionRestrictions.anchorno
array
此事件**不允许**连接到的事件锚点数组。锚点的名称为 “action” 或 “TRUE” 路径的
yes,以及 “inaction” 或 “FALSE” 路径的no。预期格式为EventType.anchorName。例如:decision.no。
connectionRestrictions.sourceno
array[]
一个数组,其键为
action、condition和/或decision类型的事件,并且包含允许连接到此事件顶部锚点的其他事件的键。
connectionRestrictions.targetno
array[]
一个数组,其键为
action、condition和/或decision类型的事件,并且包含允许从该事件流出的其他事件的键。换句话说,连接到此事件的底部锚点。
timelineTemplateno
string
PHP 模板,用于自定义联系人的时间线中此事件的 UI。
注册 Campaign Decision
<?php
declare(strict_types=1);
namespace MauticPlugin\HelloWorldBundle\EventListener;
use Mautic\CampaignBundle\CampaignEvents;
use Mautic\CampaignBundle\Event\CampaignBuilderEvent;
use MauticPlugin\HelloWorldBundle\HelloWorldEvents;
use MauticPlugin\HelloWorldBundle\Form\Type\TravelType;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class CampaignDecisionSubscriber implements EventSubscriberInterface
{
public const TYPE = 'helloworld.decision';
public static function getSubscribedEvents(): array
{
return [
CampaignEvents::CAMPAIGN_ON_BUILD => ['onCampaignBuild', 0],
];
}
}
- public function onCampaignBuild(CampaignBuilderEvent $event): void
- {
- $event->addCondition(
self::TYPE, [
‘label’ => ‘helloworld.campaign.event.decision’, ‘description’ => ‘helloworld.campaign.event.decision.descr’, ‘eventName’ => HelloWorldEvents::EVALUATE_CAMPAIGN_DECISION, ‘formType’ => TravelType::class,
]
);
}
}
Campaign Decision 定义
Key |
是否必需? |
Type |
Description |
|---|---|---|---|
|
yes |
string |
UI 显示名称。 |
|
yes |
string |
当联系人到达营销活动流程中的此点时,Campaign 引擎通过 |
|
no |
string |
作为此事件的工具提示显示。 |
|
no |
string |
Symfony form type class,用于配置事件。 |
|
no |
array |
传递给给定 Symfony 表单类型的选项数组。 |
|
no |
array |
由 |
|
no |
string |
PHP 模板,用于自定义给定表单类型的 UI。 |
|
no |
array |
定义此事件兼容的事件和锚点的限制数组。 |
|
no |
array |
此事件**不允许**连接到的事件锚点的数组。锚点的名称为 “action” 或 “TRUE” 路径的 |
|
no |
array[] |
键为事件类型(action、condition 和/或 decision)的数组,其值为允许连接到此事件顶部锚点的其他事件。 |
|
no |
array[] |
键为事件类型(action、condition 和/或 decision)的数组,其值为允许从此事件流出的其他事件。换句话说,连接到此事件的底部锚点。 |
|
no |
string |
PHP 模板,用于自定义联系人时间线中此事件的 UI。 |
执行或评估营销活动事件
实现一个监听器,用于监听 batchEventName 或 eventName 中定义的事件名称,以执行或评估 Campaign Event。
执行 Campaign Action
对事件的 batchEventName 的监听器接收到一个 MauticCampaignBundleEventPendingEvent 对象。该对象包含在当前旅程阶段中的联系人。监听器必须处理一批联系人,并标记其相应的 MauticCampaignBundleEntityLeadEventLog 为已通过或失败。您必须将每个 LeadEventLog 标记为已通过或失败。campaign_time_wait_on_event_false 配置选项决定了对失败事件的重新安排。
<?php
declare(strict_types=1);
namespace MauticPlugin\HelloWorldBundle\EventListener;
use Mautic\CampaignBundle\CampaignEvents;
use Mautic\CampaignBundle\Event\CampaignBuilderEvent;
use Mautic\CampaignBundle\Event\PendingEvent;
use MauticPlugin\HelloWorldBundle\HelloWorldEvents;
use MauticPlugin\HelloWorldBundle\Form\Type\TravelType;
use MauticPlugin\HelloWorldBundle\Helper\TravelService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Translation\TranslatorInterface;
class CampaignActionSubscriber implements EventSubscriberInterface
{
public const TYPE = 'helloworld.action';
private TranslatorInterface $translator;
private TravelService $travelService;
public function __construct(TranslatorInterface $translator, TravelService $travelService)
{
$this->translator = $translator;
$this->travelService = $travelService;
}
public static function getSubscribedEvents(): array
{
return [
CampaignEvents::CAMPAIGN_ON_BUILD => ['onCampaignBuild', 0],
HelloWorldEvents::EXECUTE_CAMPAIGN_ACTION => ['onExecuteCampaignAction', 0],
];
}
public function onCampaignBuild(CampaignBuilderEvent $event): void
{
$event->addAction(
self::TYPE,
[
'label' => 'helloworld.campaign.event.action',
'description' => 'helloworld.campaign.event.action.descr',
'batchEventName' => HelloWorldEvents::EXECUTE_CAMPAIGN_ACTION,
'formType' => TravelType::class,
]
);
}
public function onExecuteCampaignAction(PendingEvent $pendingEvent): void
{
$worldToVisit = $pendingEvent->getConfig()->getProperty('worldToVisit');
$pendingEvent->setChannel('world', $worldToVisit);
- $contacts = $pendingEvent->getContactsKeyedById();
$emails = []; foreach ($contacts as $contact) {
- if (!$contact->getEmail()) {
// Don’t reschedule these events $pendingEvent->passWithError(
$pendingEvent->findLogByContactId($contact->getId()), $this->translator->trans(‘helloworld.validation.email_required’, [], ‘validators’)
);
$emails[] = $contact->getEmail();
}
}
$this->travelService->doSomethingWithThese($emails, $worldToVisit);
$pendingEvent->passRemaining();
}
}
- class Mautic\CampaignBundle\Events\Mautic\CampaignBundle\Events\PendingEvent
- public checkContext(string $eventType)
Checks if the given Event type matches the Event executed or evaluated. This is useful if listeners for different Campaign Events are listening to the same name defined as
batchEventNamein the Event’s definition.- Returns:
TRUEif the context matches.- Return type:
bool
- public fail(\Mautic\CampaignBundle\Entity\LeadEventLog $log, string $reason)
Mark a specific LeadEventLog object as failed and retry again later.
- Parameters:
$log (
\Mautic\CampaignBundle\Entity\LeadEventLog) – Event log to fail.$reason (
string) – Reason the Event failed.
- Return type:
void
- public failAll(string $reason)
Fail the entire batch of LeadEventLog objects and retry again later.
- Parameters:
$reason (
string) – Reason the Events failed.
- Return type:
void
- public failLogs(\Doctrine\Common\Collections\ArrayCollection $logs, string $reason)
Fail a collection of LeadEventLog objects and try again later.
- Parameters:
\Doctrine\Common\Collections\ArrayCollection (
string $logs) – Collection to mark as failed.$reason (
string) – Reason the Events failed.
- Return type:
void
- public failRemaining(string $reason)
Fail all remaining LeadEventLog objects that are not marked as passed.
- Parameters:
$reason (
string) – Reason the Events failed.
- Return type:
void
- public findLogByContactId(int $id)
Returns a LeadEventLog object for the given contact ID.
- Parameters:
$id (
int)
- Returns:
Event log for the given contact.
- Return type:
\Mautic\CampaignBundle\Entity\LeadEventLog
- public getConfig()
Use the returned
AbstractEventAccessorobject to access properties configured for this Event.- Returns:
Object to fetch the configuration options for the Campaign Event.
- Return type:
\Mautic\CampaignBundle\EventCollector\Accessor\Event\AbstractEventAccessor
- public getContactIds()
- return:
- 用于当前批次中需要处理的 LeadEventLog 对象的联系人 ID 数组。
- returntype:
array
- public Mautic\CampaignBundle\Events\Mautic\CampaignBundle\Events\PendingEvent::getContacts()
返回所有联系人在当前批次中需要处理的 LeadEventLog 对象对应的 Lead 对象。
- Returns:
Lead 对象的集合。
- Return type:
\Doctrine\Common\Collections\ArrayCollection
- public Mautic\CampaignBundle\Events\Mautic\CampaignBundle\Events\PendingEvent::getContactsKeyedById()
与
getContacts相同,但按联系人 ID 排序。- Returns:
Lead 对象的集合。
- Return type:
\Doctrine\Common\Collections\ArrayCollection
- public Mautic\CampaignBundle\Events\Mautic\CampaignBundle\Events\PendingEvent::getEvent()
返回当前的 Event 实体。
- Returns:
Event 实体。
- Return type:
\Mautic\CampaignBundle\Entity\Event
- public Mautic\CampaignBundle\Events\Mautic\CampaignBundle\Events\PendingEvent::pass(\Mautic\CampaignBundle\Entity\LeadEventLog $log)
将特定的 LeadEventLog 对象标记为成功。
- Parameters:
$log (
\Mautic\CampaignBundle\Entity\LeadEventLog) – 要通过的事件日志。
- Return type:
void
- public Mautic\CampaignBundle\Events\Mautic\CampaignBundle\Events\PendingEvent::passAll()
将当前批次中的所有 LeadEventLog 对象标记为成功。
- Return type:
void
- public Mautic\CampaignBundle\Events\Mautic\CampaignBundle\Events\PendingEvent::passAllWithError(string $reason)
将所有 LeadEventLog 对象标记为出现错误,并且**不会**稍后重试。
- Return type:
void
- public Mautic\CampaignBundle\Events\Mautic\CampaignBundle\Events\PendingEvent::passLogs(\Doctrine\Common\Collections\ArrayCollection $logs)
将一组 LeadEventLog 对象的集合标记为成功。
- Parameters:
\Doctrine\Common\Collections\ArrayCollection (
string $logs) – 要标记为成功的集合。
- Return type:
void
- public Mautic\CampaignBundle\Events\Mautic\CampaignBundle\Events\PendingEvent::passRemaining()
标记尚未标记为失败的剩余 LeadEventLog 对象。
- Return type:
void
- public Mautic\CampaignBundle\Events\Mautic\CampaignBundle\Events\PendingEvent::passRemainingWithError(string $reason)
标记尚未标记为失败的剩余 LeadEventLog 对象。
- Parameters:
$reason (
string) – 错误消息。
- Return type:
void
- public Mautic\CampaignBundle\Events\Mautic\CampaignBundle\Events\PendingEvent::passWithError(\Mautic\CampaignBundle\Entity\LeadEventLog $log, string $reason)
将特定的 LeadEventLog 对象标记为出现错误,并且不要再次尝试。
- Parameters:
$log (
\Mautic\CampaignBundle\Entity\LeadEventLog) – 要通过的事件日志。$reason (
string) – 错误消息。
- Return type:
void
- public Mautic\CampaignBundle\Events\Mautic\CampaignBundle\Events\PendingEvent::setChannel(string $channel[, $channelId = null)
设置要分配给 Event 的 Channel。
- Parameters:
$channel (
string) – 此 Event 相关的 Channel 名称。例如,email、page、form等。$channelId (
mixed) – Channel 实体的 ID。
- Return type:
void
评估 Campaign 条件
监听器接收到事件的 eventName 会收到一个 MauticCampaignBundleEventConditionEvent 对象。该对象包含用于评估此条件的单个 LeadEventLog 对象。监听器必须在评估条件后调用 ConditionEvent::pass() 或 ConditionEvent::fail() 方法。
<?php
declare(strict_types=1);
namespace MauticPlugin\HelloWorldBundle\EventListener;
use Mautic\CampaignBundle\CampaignEvents;
use Mautic\CampaignBundle\Event\CampaignBuilderEvent;
use Mautic\CampaignBundle\Event\ConditionEvent;
use MauticPlugin\HelloWorldBundle\HelloWorldEvents;
use MauticPlugin\HelloWorldBundle\Form\Type\TravelType;
use MauticPlugin\HelloWorldBundle\Helper\TravelService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class CampaignConditionSubscriber implements EventSubscriberInterface
{
public const TYPE = 'helloworld.condition';
private TravelService $travelService;
public function __construct(TravelService $travelService): void
{
$this->travelService = $travelService;
}
public static function getSubscribedEvents(): array
{
return [
CampaignEvents::CAMPAIGN_ON_BUILD => ['onCampaignBuild', 0],
HelloWorldEvents::EVALUATE_CAMPAIGN_CONDITION => ['onEvaluateCampaignCondition', 0],
];
}
public function onCampaignBuild(CampaignBuilderEvent $event): void
{
$event->addCondition(
self::TYPE,
[
'label' => 'helloworld.campaign.event.condition',
'description' => 'helloworld.campaign.event.condition.descr',
'eventName' => HelloWorldEvents::EVALUATE_CAMPAIGN_CONDITION,
'formType' => TravelType::class,
]
);
}
public function onEvaluateCampaignCondition(ConditionEvent $event): void
{
$leadEventLog = $event->getLog();
$contact = $leadEventLog->getLead();
$world = $event->getEventConfig()->getProperty('world');
if ($this->travelService->hasTraveledTo($contact, $world)) {
$event->pass();
} else {
$event->fail();
}
}
}
- class Mautic\CampaignBundle\Events\Mautic\CampaignBundle\Events\ConditionEvent
- public checkContext(string $eventType)
检查给定的事件类型是否与执行或评估的事件匹配。如果不同的 Campaign Events 的监听器正在监听相同的名称,该名称在 Event 的定义中定义为 eventName,则此方法很有用。
- Returns:
如果上下文匹配,则返回
TRUE。- Return type:
bool
- public fail()
将此条件评估为
FALSE。- Return type:
void
- public Mautic\CampaignBundle\Events\Mautic\CampaignBundle\Events\ConditionEvent::getEventConfig()
使用返回的
AbstractEventAccessor对象来访问为此 Event 配置的属性。- return:
用于获取 Campaign Event 的配置选项的对象。
- returntype:
\Mautic\CampaignBundle\EventCollector\Accessor\Event\AbstractEventAccessor
- public Mautic\CampaignBundle\Events\Mautic\CampaignBundle\Events\ConditionEvent::getLog()
- Returns:
Condition 对应的
LeadEventLog对象。- Return type:
\Mautic\CampaignBundle\Entity\LeadEventLog
- public Mautic\CampaignBundle\Events\Mautic\CampaignBundle\Events\ConditionEvent::pass()
将此 Condition 评估为
TRUE。- Return type:
void
- public Mautic\CampaignBundle\Events\Mautic\CampaignBundle\Events\ConditionEvent::setChannel(string $channel[, $channelId = null)
设置要分配给 Event 的 Channel。
- Parameters:
$channel (
string) – 此 Event 相关的 Channel 名称。例如,email、page、form等。$channelId (
mixed) – Channel 实体的 ID。
- Return type:
void
评估 Campaign Decision
Decision 指的是联系人在采取某种直接行动时所做出的决定。处理决策逻辑的代码还需要通知 Campaign Engine 评估给定类型的 Campaign Decision,方法是调用 Mautic\CampaignBundle\Executioner\RealTimeExecutioner::execute(),该方法已注册为 mautic.campaign.executioner.realtime 服务。
然后,Campaign Engine 会分发 Decision Event 的 eventName,其中监听器会接收到 \Mautic\CampaignBundle\Event\DecisionEvent 对象。此对象包含用于评估此决策的单个 LeadEventLog 对象。监听器必须调用 DecisionEvent::setAsApplicable(),以指示 Campaign Engine 执行或安排附加在决策的“action”(左侧)路径上的 Event。
<?php
declare(strict_types=1);
namespace MauticPlugin\HelloWorldBundle\EventListener;
use Mautic\CampaignBundle\CampaignEvents;
use Mautic\CampaignBundle\Event\CampaignBuilderEvent;
use Mautic\CampaignBundle\Event\DecisionEvent;
use Mautic\CampaignBundle\Executioner\RealTimeExecutioner;
use MauticPlugin\HelloWorldBundle\HelloWorldEvents;
use MauticPlugin\HelloWorldBundle\Event\TravelDocumentEvent;
use MauticPlugin\HelloWorldBundle\Form\Type\TravelType;
use MauticPlugin\HelloWorldBundle\Helper\TravelService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class CampaignDecisionSubscriber implements EventSubscriberInterface
{
public const TYPE = 'helloworld.decision';
private TravelService $travelService;
private RealTimeExecutioner $realTimeExecutioner;
public function __construct(TravelService $travelService, RealTimeExecutioner $realTimeExecutioner)
{
$this->travelService = $travelService;
$this->realTimeExecutioner = $realTimeExecutioner;
}
- public static function getSubscribedEvents()
- {
- return [
CampaignEvents::CAMPAIGN_ON_BUILD => [‘onCampaignBuild’, 0], HelloWorldEvents::EVALUATE_CAMPAIGN_DECISION => [‘onEvaluateCampaignDecision’, 0], HelloWorldEvents::CONTACT_TRAVEL_DOCUMENTS_CREATED => [‘onContactTravelDocumentsCreated’, 0],
];
}
public function onCampaignBuild(CampaignBuilderEvent $event) {
- $event->addDecision(
self::TYPE, [
‘label’ => ‘helloworld.campaign.event.Decision’, ‘description’ => ‘helloworld.campaign.event.Decision.descr’, ‘eventName’ => HelloWorldEvents::EVALUATE_CAMPAIGN_DECISION, ‘formType’ => TravelType::class,
]
);
}
public function onContactTravelDocumentsCreated(TravelDocumentEvent $event) {
$this->realTimeExecutioner->execute(self::TYPE, $event, ‘world’, $event->getWorldId());
}
public function onEvaluateCampaignDecision(DecisionEvent $event) {
$applicableWorld = $event->getEventConfig()->getProperty(‘world’); $travelDocumentEvent = $event->getPassthrough();
- if ($applicableWorld !== $travelDocumentEvent->getWorldId()) {
return;
}
$event->setAsApplicable(); $event->setChannel(‘world’, $travelDocumentEvent->getWorldId());
}
}
- class Mautic\CampaignBundle\Events\Mautic\CampaignBundle\Events\DecisionEvent
- public checkContext(string $eventType)
检查给定的事件类型是否与执行或评估的事件匹配。如果不同的 Campaign Events 的监听器正在监听相同的名称,该名称在 Event 的定义中指定为
eventName,则此方法很有用。- Returns:
如果上下文匹配,则返回
TRUE。- Return type:
bool
- public getEventConfig()
使用返回的
AbstractEventAccessor对象来访问为此 Event 配置的属性。- Returns:
用于获取 Campaign Event 的配置选项的对象。
- Return type:
\Mautic\CampaignBundle\EventCollector\Accessor\Event\AbstractEventAccessor
- public getLog()
- Returns:
Condition 对应的
LeadEventLog对象。- Return type:
\Mautic\CampaignBundle\Entity\LeadEventLog
- public getPassthrough()
访问由
RealTimeExecutioner::execute()设置的上下文数据。- Returns:
返回作为
RealTimeExecutioner::execute()的第二个参数设置的内容。- Return type:
mixed
- public setAsApplicable()
Call this if the Decision is applicable to the action taken by the Contact which instructs the Campaign Engine to execute or schedule Events connected into this Decision’s “action” (left) path.
- returntype:
void
- public Mautic\CampaignBundle\Events\Mautic\CampaignBundle\Events\DecisionEvent::setChannel(string $channel[, $channelId = null)
Set the Channel to attribute to the Event.
- Parameters:
$channel (
string) – Name of the Channel this Event relates to. For example,page,form, and so forth.$channelId (
mixed) – ID of the Channel entity.
- returntype:
void
Exporting a Campaign
Mautic 的导出功能提供可以轻松使用导入工具重新导入到 Mautic 的营销活动结构,格式为可导入的格式。 这有助于确保您的营销资产保持可移植性和持久性,尤其是在您在多个 Mautic 实例和域之间工作时。
Mautic 将与您的营销活动相关的所有数据导出到一个结构化的 JSON 文件中,其中包含任何必需的文件和资源。 导出过程将生成的归档文件压缩到 ZIP 文件中,并将其保存到您的浏览器。
您可以从命令行或通过 API 以及 Mautic 用户界面调用导出命令。
通过命令行导出
首先,将营销活动的 ZIP 文件复制到正确的位置,以便将其导入到 Mautic 中。
Note
以下命令假定您已通过 Docker Compose 安装,并且正在本地运行 Mautic。 请使用适合您的环境的适当文件复制机制。 例如,安全文件传输协议 - SFTP 或安全复制协议 - SCP。
docker cp ./campaign_data.zip ddev-mautic-web:/tmp/entity_data.zip
然后,运行导入命令:
bin/console mautic:entity:import --entity=campaign --file=/tmp/entity_data.zip --user=*{<user_id>}*
选项
Option |
Description |
|---|---|
|
Specifies the entity type to import. For example, Campaign |
|
Path to the ZIP file you want to import |
|
User ID to associate with the import process. For example, 1 - admin |
通过 API 导出
端点
POST https://{your-mautic-domain}/api/campaigns/export/{*<campaign_id>*}
URL 的最后部分,{*<campaign_id>*},指定要导出的营销活动的 ID。
请参阅 REST API Authentication* 以获取身份验证详细信息。
Note
* 较旧的页面包含过时且可能不准确的信息。
如果您有兴趣帮助开发此页面的新内容以及其他内容,请考虑加入文档工作。
请阅读 Contributing Guidelines 和 Contributing to Mautic’s documentation 以开始您的贡献。
示例请求 - CURL:
```markdown curl –location ‘https://{your-mautic-domain}/api/campaigns/export/{<campaign_id>}’
–data ‘’
Example Campaign JSON file
导入活动
Mautic 允许您使用之前导出的 JSON 文件导入活动。此功能可帮助您在 Mautic 实例之间传输活动。
在导入过程中,Mautic 执行以下操作:
验证正在导入的用户是否具有必要的权限以及访问所有相关实体的权限。
检查活动所需的插件和其他依赖项是否存在于当前的 Mautic 实例中。
识别与现有实体可能存在的任何 ID 冲突。如果存在冲突,Mautic 会提示您选择更新现有实体或创建新实体。
创建活动以及所有相关的实体,以确保其在导入后能够正常运行。
您可以从命令行或通过 API 触发导入命令。
通过命令行进行导入
首先,将活动数据 ZIP 文件复制到您的 DDEV 容器或适合您环境的位置。
Note
以下命令假定您已使用 Docker Compose 安装。对于您的环境,您可能需要 SFTP 或 SCP。
docker cp ./campaign_data.zip ddev-mautic-web:/tmp/entity_data.zip
然后,运行导入命令:
ddev exec bin/console mautic:entity:import --entity=campaign --file=/tmp/entity_data.zip --user=*{<user_id>}*
选项
Option |
Description |
|---|---|
|
Specifies the entity type to import. For example, Campaign |
|
Path to the ZIP file you want to import |
|
User ID to associate with the import process. For example, 1 - admin |
通过 API 进行导入
端点
POST https://mautic.example.com/api/campaigns/import
请参阅 REST API Authentication* 以获取身份验证详细信息。
Note
* 该旧页面包含过时且可能不准确的信息。
如果您有兴趣帮助开发此页面的新内容以及其他内容,请考虑加入文档编写工作。
请阅读 Contributing Guidelines 和 Contributing to Mautic’s documentation 以开始您的贡献。
Headers
Header |
Description |
|---|---|
|
|
Request body
If sending JSON data: provide the raw JSON payload directly in the request body.
If sending a ZIP file: upload the ZIP file using form-data.