Files
Alexandre Gain dce849610c Merge the Smartlinks plugin (SmartlinksBundle 0.6.0) into the bundle as the Smart Links domain (0.18.0)
Two domains, one MT3S bundle: Marketing Programs (unchanged) and the
imported Smart Links (smart links + UTM taxonomies), each keeping its
own menu, tables, routes and translations.

- Code moved from MauticPlugin\SmartlinksBundle\ to
  MauticPlugin\MT3SMarketingProgramBundle\; template namespace
  @Smartlinks/ -> @MT3SMarketingProgram/; smartlinks.js ->
  Assets/js/mt3s-mp-smartlinks.js; icon -> Assets/img/smartlinks-icon.svg.
- Incoming migrations renamed Version_0_X_0_SmartLinks.php to avoid
  the class-name collision; schema untouched, data intact.
- Permissions folded into MT3SMarketingProgramPermissions:
  smart_links + taxonomies under the mt3smarketingprogram: base
  (roles that had the old smartlinks: grants must be re-granted).
- config.php: Smart Links routes + menu group, public /l/{slug},
  SmartlinksIntegration services, smartlinks_* parameters (legacy
  utm_manager_* keys still readable), version 0.18.0. The 0.17.0
  placeholder /s/marketing-program-utm-taxonomies is replaced by the
  real /s/utm-taxonomies.
- Translations merged (en_US) and added (fr_FR); Tests/ + phpunit moved
  in; readme documents both domains and the 0.18.0 merge history.

Verified live: menus, both config tabs, both lists + forms, program
pages, public redirect with taxonomy UTM values, host + unknown-slug
404s, 90/90 unit tests, full php -l, all ini catalogs parse.
2026-11-16 13:48:13 +01:00

110 lines
3.9 KiB
PHP

<?php
declare(strict_types=1);
namespace MauticPlugin\MT3SMarketingProgramBundle\Catalog;
/**
* System catalog of the parameters offered by UTM Manager. Administrators can't edit it;
* they can only configure each entry and add custom parameters next to it.
*/
final class UtmParameterCatalog
{
public const GROUP_STANDARD = 'standard';
public const GROUP_PLATFORM = 'platform';
public const GROUP_CUSTOM = 'custom';
public const CUSTOM_KEY_PATTERN = '/^[a-z][a-z0-9_]{1,40}$/';
/** Query keys used by Mautic itself (ct = click-through tracking). */
private const RESERVED_KEYS = ['ct'];
/** "utm" is reserved for catalog entries, "mtc_" for Mautic tracking parameters. */
private const RESERVED_PREFIXES = ['utm', 'mtc_'];
/**
* Standard Google Analytics / GA4 parameters: key => [default mode, suggested values].
*/
private const STANDARD = [
'utm_source' => [UtmParameterMode::DROPDOWN, ['newsletter', 'linkedin', 'facebook', 'instagram', 'google', 'youtube', 'x', 'tiktok', 'partner', 'direct']],
'utm_medium' => [UtmParameterMode::DROPDOWN, ['email', 'cpc', 'social', 'social_paid', 'display', 'affiliate', 'referral', 'qr', 'sms', 'print', 'event']],
'utm_campaign' => [UtmParameterMode::FREE, []],
'utm_term' => [UtmParameterMode::FREE, []],
'utm_content' => [UtmParameterMode::FREE, []],
'utm_id' => [UtmParameterMode::FREE, []],
'utm_source_platform' => [UtmParameterMode::DROPDOWN, ['google_ads', 'meta_ads', 'linkedin_ads', 'microsoft_ads', 'tiktok_ads']],
'utm_creative_format' => [UtmParameterMode::DROPDOWN, ['banner', 'video', 'carousel', 'text', 'native']],
'utm_marketing_tactic' => [UtmParameterMode::DROPDOWN, ['prospecting', 'remarketing', 'retargeting', 'brand', 'nurturing']],
];
/**
* Click IDs appended automatically by ad platforms. Disabled by default.
*/
private const PLATFORM = ['gclid', 'gbraid', 'wbraid', 'dclid', 'fbclid', 'msclkid', 'ttclid', 'li_fat_id', 'twclid', 'epik'];
/**
* @var array<string, UtmParameterDefinition>
*/
private array $definitions = [];
public function __construct()
{
foreach (self::STANDARD as $key => [$mode, $suggestions]) {
$this->definitions[$key] = new UtmParameterDefinition($key, self::GROUP_STANDARD, $mode, false, $suggestions);
}
foreach (self::PLATFORM as $key) {
$this->definitions[$key] = new UtmParameterDefinition($key, self::GROUP_PLATFORM, UtmParameterMode::DISABLED, true);
}
}
/**
* @return array<string, UtmParameterDefinition> In display order
*/
public function all(): array
{
return $this->definitions;
}
/**
* @return array<string, UtmParameterDefinition>
*/
public function getByGroup(string $group): array
{
return array_filter($this->definitions, fn (UtmParameterDefinition $definition): bool => $definition->group === $group);
}
public function has(string $key): bool
{
return isset($this->definitions[$key]);
}
public function get(string $key): ?UtmParameterDefinition
{
return $this->definitions[$key] ?? null;
}
/**
* Keys that a custom parameter can't use: catalog keys, Mautic query keys and reserved prefixes.
*/
public function isReservedKey(string $key): bool
{
if ($this->has($key) || in_array($key, self::RESERVED_KEYS, true)) {
return true;
}
foreach (self::RESERVED_PREFIXES as $prefix) {
if (str_starts_with($key, $prefix)) {
return true;
}
}
return false;
}
public function isValidCustomKey(string $key): bool
{
return 1 === preg_match(self::CUSTOM_KEY_PATTERN, $key) && !$this->isReservedKey($key);
}
}