Landing pages
Note
此页面的内容需要进行重大更新。旧页面包含过时且可能不准确的信息。您仍然可以在 Mautic Developer Documentation archived repository 中访问它。
如果您有兴趣帮助开发此页面和其他页面的新内容,请考虑加入文档编写工作。
请阅读 Contributing Guidelines 和 Contributing to Mautic’s documentation 以开始您的贡献。
有两种方法可以扩展 Landing Pages: - 用于在 Landing Page 中插入动态内容的 Landing Page tokens - A/B 测试的胜出标准
两者都利用 \Mautic\PageBundle\PageEvents::PAGE_ON_BUILD 事件。 更多关于 Event listeners 的信息。
Landing Page tokens
Landing Page tokens 的处理方式与 Email tokens 完全相同。
Page A/B Test Winner Criteria
自定义 Landing Page A/B 测试胜出标准的处理方式与 Email A/B test winner criteria 相同,唯一的区别是 callback 函数会传递 MauticPageBundleEntityPage $page 和 MauticPageBundleEntityPage $parent 对象。
$children 也是一个包含 Page 实体的 ArrayCollection。
以下是一个 Landing Page Tokens 和 Landing Page A/B Test Winner Criteria 的示例。
<?php
// plugins/HelloWorldBundle/EventListener/PageSubscriber.php
declare(strict_types=1);
namespace MauticPlugin\HelloWorldBundle\EventListener;
use Mautic\CoreBundle\Helper\TemplatingHelper;
use Mautic\PageBundle\PageEvents;
use Mautic\PageBundle\Event\PageBuilderEvent;
use Mautic\PageBundle\Event\PageDisplayEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class PageSubscriber implements EventSubscriberInterface
{
private TemplatingHelper $templating;
public function __construct(TemplatingHelper $templating)
{
$this->templating = $templating;
}
static public function getSubscribedEvents()
{
return [
PageEvents::PAGE_ON_BUILD => ['onPageBuild', 0],
PageEvents::PAGE_ON_DISPLAY => ['onPageDisplay', 0]
];
}
/**
* Register the tokens and a custom A/B test winner
*/
public function onPageBuild(PageBuilderEvent $event)
{
// Add page token
$event->addToken('{helloworld.token}', 'Helloworld token');
- // Add AB Test Winner Criteria
- $event->addAbTestWinnerCriteria(
‘helloworld.planetvisits’, array(
// Label to group by ‘group’ => ‘plugin.helloworld.header’,
// Label for this specific a/b test winning criteria ‘label’ => ‘plugin.helloworld.pagetokens.’,
// Static callback function that will be used to determine the winner ‘callback’ => ‘MauticPluginHelloWorldBundleHelperAbTestHelper::determinePlanetVisitWinner’
)
);
}
/** * Search and replace tokens with content */ public function onPageDisplay(PageDisplayEvent $event) {
// Get content $content = $event->getContent();
// Search and replace tokens $content = str_replace(
‘{helloworld.token}’, $this->templating->render(‘HelloWorldBundle:SubscribedEventsPageToken:token.html.php’);, $content
);
// Set updated content $event->setContent($content);
}
}