Points
Note
The content for this page requires a major update. The legacy page contains outdated and potentially inaccurate information. You can still access it in the Mautic Developer Documentation archived repository.
If you’re interested in helping develop the new content for this page and others, consider joining the documentation efforts.
Please read the Contributing Guidelines and Contributing to Mautic’s documentation to get started.
Point Actions
In Mautic, custom Point Actions give a Contact x Points for doing a certain action.
Mautic dispatches the Event \Mautic\PointBundle\PointEvents::POINT_ON_BUILD for Plugins to register their custom Point Action. Listeners receive a Mautic\PointBundle\Event\PointBuilderEvent object. Register the Event using the addAction method as described below.
- class Mautic\PointBundle\Event\PointBuilderEvent
PointBuilderEvent class
- public addAction(string $key, array $action)
- Parameters:
$key (
string) – Unique key for the Action.$action (
array) – Action definition.
- public getActions()
- Returns:
Array of registered Actions.
- Return type:
array
Registering a Custom Point Action
<?php
declare(strict_types=1);
namespace MauticPlugin\HelloWorldBundle\EventListener;
use Mautic\PointBundle\Event\PointBuilderEvent;
use Mautic\PointBundle\PointEvents;
use MauticPlugin\HelloWorldBundle\Form\Type\PointActionsType;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class PointSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
PointEvents::POINT_ON_BUILD => ['onPointBuild', 0],
];
}
public function onPointBuild(PointBuilderEvent $event)
{
$action = [
'group' => 'helloworld.points.actions',
'label' => 'helloworld.points.actions.action',
'callback' => [self::class, 'addPointTriggerCallback'],
'formType' => PointActionsType::class,
];
$event->addAction('helloworld.action', $action);
}
public static function addPointTriggerCallback(array $action, array $eventDetails): bool
{
// .. Add logic to weigh the action.
}
}
In order for the custom Point Action to work, add something like the following in the code logic when the Contact executes the custom action:
<?php
$this->getModel('point')->triggerAction('helloworld.action', $event->getHit());
This triggers the custom Point Action for the currently tracked Contact. If you need to perform the Point Action on another Contact you have to pass the Contact’s object when invoking triggerAction:
<?php
$this->getModel('point')->triggerAction('helloworld.action', $event->getHit(), null, $someOtherLead);
Custom Point Action definition
Key |
Required |
Type |
Description |
|---|---|---|---|
|
REQUIRED |
string |
The language string for the option in the dropdown |
|
OPTIONAL |
string |
The alias of a custom Form type used to set config options. |
|
OPTIONAL |
array[] |
Array of options to include into the |
|
OPTIONAL |
array[] |
Array of input masks to clean a values from |
|
OPTIONAL |
string |
Theme to customize elements for |
|
OPTIONAL |
string |
View template used to render the |
|
OPTIONAL |
mixed |
Static callback function used to validate the action. Return true to add the Points to the Contact. |
Point Triggers
A custom Point Trigger used to execute a specific action once a Contact reaches X number of Points.
Mautic dispatches the Event \Mautic\PointBundle\PointEvents::TRIGGER_ON_BUILD for Plugins to register their custom Point Triggers. Listeners receive a Mautic\PointBundle\Event\TriggerBuilderEvent object. Register the Event using the addEvent method as described below.
- class Mautic\PointBundle\Event\Mautic\PointBundle\Event\TriggerBuilderEvent
- public function addEvent(string $key, array $action)
- Parameters:
$key (
string) – Unique key for the Action.$action (
array) – Action definition.
- public getEvents()
- Returns:
Array of registered Events.
- Return type:
array
Registering a Custom Point Trigger
<?php
declare(strict_types=1);
namespace MauticPlugin\HelloWorldBundle\EventListener;
use Mautic\CoreBundle\Factory\MauticFactory;
use Mautic\HelloWorldBundle\Form\Type\TriggerChoiceType;
use Mautic\PointBundle\Event\TriggerBuilderEvent;
use Mautic\PointBundle\PointEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
```markdown class PointSubscriber implements EventSubscriberInterface
- {
public static function getSubscribedEvents(): array {
- return [
PointEvents::TRIGGER_ON_BUILD => [‘onTriggerBuild’, 0],
];
}
public function onTriggerBuild(TriggerBuilderEvent $event) {
- $changeLists = [
‘group’ => ‘mautic.campaign.point.trigger’, ‘label’ => ‘mautic.campaign.point.trigger.changecampaigns’, ‘callback’ => [self::class, ‘updatePointsOnBuild’], ‘formType’ => TriggerChoiceType::class,
];
$event->addEvent(‘campaign.changecampaign’, $changeLists);
}
public static function updatePointsOnBuild($config, $lead, MauticFactory $factory): bool {
// Add custom code to do some action.
}
}
自定义积分触发器定义
Key |
Required |
Type |
Description |
|---|---|---|---|
|
REQUIRED |
string |
下拉菜单中选项的语言字符串 |
|
OPTIONAL |
string |
用于设置配置选项的自定义表单类型的别名。 |
|
OPTIONAL |
array[] |
包含在 formType 的 $options 参数中的选项数组。 |
|
OPTIONAL |
array[] |
用于清理 formType 中值的输入掩码数组。 |
|
OPTIONAL |
string |
用于自定义 formType 元素的的主题。 |
|
OPTIONAL |
string |
用于渲染 formType 的视图模板。 |
|
OPTIONAL |
mixed |
用于执行自定义操作的静态回调函数。 |