Skip to content

Commit

Permalink
added tracking platform setting
Browse files Browse the repository at this point in the history
  • Loading branch information
matfish3 committed Sep 21, 2024
1 parent 4a1e036 commit 41dd270
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 6 additions & 8 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<<EOD
gtag('event','$experiment->handle', {'$experiment->handle':'$variant->name'});
EOD;
};
return [
['trackingPlatform', 'string'],
['fireEvent', 'safe'],
];
}
}
5 changes: 3 additions & 2 deletions src/twig/OptimumExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 41dd270

Please sign in to comment.