diff --git a/src/services/trackingcode/GA4TrackingCode.php b/src/services/trackingcode/GA4TrackingCode.php new file mode 100644 index 0000000..8f37f96 --- /dev/null +++ b/src/services/trackingcode/GA4TrackingCode.php @@ -0,0 +1,23 @@ +handle', {'$experiment->handle':'$variant->name'}); + EOD; + } +} diff --git a/src/services/trackingcode/MixpanelTrackingCode.php b/src/services/trackingcode/MixpanelTrackingCode.php new file mode 100644 index 0000000..375e096 --- /dev/null +++ b/src/services/trackingcode/MixpanelTrackingCode.php @@ -0,0 +1,27 @@ +handle', + 'Variant Name': '$variant->name' +}); +EOD; + } +} + diff --git a/src/services/trackingcode/TrackingCode.php b/src/services/trackingcode/TrackingCode.php new file mode 100644 index 0000000..a7bfa8e --- /dev/null +++ b/src/services/trackingcode/TrackingCode.php @@ -0,0 +1,20 @@ +getSettings(); + + if ($settings->fireEvent !== null) { + return ($settings->fireEvent)($experiment, $variant); + } + + $trackingPlatform = $settings->trackingPlatform; + + switch ($trackingPlatform) { + case 'ga4': + $trackingCode = new GA4TrackingCode(); + break; + case 'mixpanel': + $trackingCode = new MixpanelTrackingCode(); + break; + default: + throw new \InvalidArgumentException("Unsupported tracking platform: $trackingPlatform. Use the `fireEvent` config setting to specify a custom function."); + } + + return $trackingCode->generate($experiment, $variant); + } +}