From e0087a62436e8a48d50018a6dd391edee80751cd Mon Sep 17 00:00:00 2001 From: Mat Fish Date: Sat, 21 Sep 2024 22:44:48 +0300 Subject: [PATCH] add setting --- src/services/trackingcode/GA4TrackingCode.php | 23 +++++++++++ .../trackingcode/MixpanelTrackingCode.php | 27 ++++++++++++ src/services/trackingcode/TrackingCode.php | 20 +++++++++ .../trackingcode/TrackingCodeRetriever.php | 41 +++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 src/services/trackingcode/GA4TrackingCode.php create mode 100644 src/services/trackingcode/MixpanelTrackingCode.php create mode 100644 src/services/trackingcode/TrackingCode.php create mode 100644 src/services/trackingcode/TrackingCodeRetriever.php 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); + } +}