Points
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;
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.
}
}
Custom Point Trigger 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 execute the custom action. |