diff --git a/CHANGELOG.md b/CHANGELOG.md index 71841c1..5ce02fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Optimum +## 1.6.1 - 2024-09-21 +### Added +- Added `trackingPlatform` setting + ## 1.6.0 - 2024-09-21 ### Improved - Pass Experiment and Variant objects to `fireEvent` closure to allow for more complex tracking logic diff --git a/src/models/Settings.php b/src/models/Settings.php index 7cd3ce8..9db7a3b 100644 --- a/src/models/Settings.php +++ b/src/models/Settings.php @@ -5,14 +5,12 @@ class Settings extends Model { public ?\Closure $fireEvent = null; - - public function __construct() + public string $trackingPlatform = 'ga4'; + public function rules(): array { - parent::__construct(); - $this->fireEvent = static function ($experiment, $variant) { - return <<handle', {'$experiment->handle':'$variant->name'}); -EOD; - }; + return [ + ['trackingPlatform', 'string'], + ['fireEvent', 'safe'], + ]; } } diff --git a/src/twig/OptimumExtension.php b/src/twig/OptimumExtension.php index 7a4e4b7..eace962 100644 --- a/src/twig/OptimumExtension.php +++ b/src/twig/OptimumExtension.php @@ -9,6 +9,7 @@ use Twig\Extension\AbstractExtension; use Twig\TwigFunction; use yii\web\Cookie; +use matfish\Optimum\services\trackingcode\TrackingCodeRetriever; class OptimumExtension extends AbstractExtension { @@ -59,8 +60,8 @@ public function fireEvent(string $experiment): string $variant = $e->getVariants()->where("handle='$variantName'")->one(); - $closure = Plugin::getInstance()?->getSettings()?->fireEvent; + $trackingCodeRetriever = new TrackingCodeRetriever(); - return $closure($e, $variant); + return $trackingCodeRetriever->getTrackingCode($e, $variant); } } \ No newline at end of file