1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Instant Analytics plugin for Craft CMS |
4
|
|
|
* |
5
|
|
|
* @author nystudio107 |
|
|
|
|
6
|
|
|
* @copyright Copyright (c) 2017 nystudio107 |
|
|
|
|
7
|
|
|
* @link http://nystudio107.com |
|
|
|
|
8
|
|
|
* @package InstantAnalytics |
|
|
|
|
9
|
|
|
* @since 1.0.0 |
10
|
|
|
*/ |
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace nystudio107\instantanalyticsGa4\ga4; |
13
|
|
|
|
14
|
|
|
use Br33f\Ga4\MeasurementProtocol\Dto\Event\AddPaymentInfoEvent; |
15
|
|
|
use Br33f\Ga4\MeasurementProtocol\Dto\Event\AddShippingInfoEvent; |
16
|
|
|
use Br33f\Ga4\MeasurementProtocol\Dto\Event\AddToCartEvent; |
17
|
|
|
use Br33f\Ga4\MeasurementProtocol\Dto\Event\BaseEvent; |
18
|
|
|
use Br33f\Ga4\MeasurementProtocol\Dto\Event\BeginCheckoutEvent; |
19
|
|
|
use Br33f\Ga4\MeasurementProtocol\Dto\Event\LoginEvent; |
20
|
|
|
use Br33f\Ga4\MeasurementProtocol\Dto\Event\PurchaseEvent; |
21
|
|
|
use Br33f\Ga4\MeasurementProtocol\Dto\Event\RefundEvent; |
22
|
|
|
use Br33f\Ga4\MeasurementProtocol\Dto\Event\RemoveFromCartEvent; |
23
|
|
|
use Br33f\Ga4\MeasurementProtocol\Dto\Event\SearchEvent; |
24
|
|
|
use Br33f\Ga4\MeasurementProtocol\Dto\Event\SelectItemEvent; |
25
|
|
|
use Br33f\Ga4\MeasurementProtocol\Dto\Event\SignUpEvent; |
26
|
|
|
use Br33f\Ga4\MeasurementProtocol\Dto\Event\ViewCartEvent; |
27
|
|
|
use Br33f\Ga4\MeasurementProtocol\Dto\Event\ViewItemEvent; |
28
|
|
|
use Br33f\Ga4\MeasurementProtocol\Dto\Event\ViewItemListEvent; |
29
|
|
|
use Br33f\Ga4\MeasurementProtocol\Dto\Event\ViewSearchResultsEvent; |
30
|
|
|
use Br33f\Ga4\MeasurementProtocol\Dto\Parameter\ItemParameter; |
31
|
|
|
use Craft; |
32
|
|
|
use nystudio107\instantanalyticsGa4\ga4\events\PageViewEvent; |
33
|
|
|
|
34
|
|
|
/** |
|
|
|
|
35
|
|
|
* @author nystudio107 |
|
|
|
|
36
|
|
|
* @package InstantAnalytics |
|
|
|
|
37
|
|
|
* @since 1.2.0 |
|
|
|
|
38
|
|
|
* |
39
|
|
|
* @method ItemParameter ItemParameter() |
40
|
|
|
* @method AddPaymentInfoEvent AddPaymentInfoEvent() |
41
|
|
|
* @method AddToCartEvent AddToCartEvent() |
42
|
|
|
* @method AddShippingInfoEvent AddShippingInfoEvent() |
43
|
|
|
* @method BaseEvent BaseEvent() |
44
|
|
|
* @method BeginCheckoutEvent BeginCheckoutEvent() |
45
|
|
|
* @method LoginEvent LoginEvent() |
46
|
|
|
* @method PageViewEvent PageViewEvent() |
47
|
|
|
* @method PurchaseEvent PurchaseEvent() |
48
|
|
|
* @method RefundEvent RefundEvent() |
49
|
|
|
* @method RemoveFromCartEvent RemoveFromCartEvent() |
50
|
|
|
* @method SearchEvent SearchEvent() |
51
|
|
|
* @method SelectItemEvent SelectItemEvent() |
52
|
|
|
* @method SignUpEvent SignUpEvent() |
53
|
|
|
* @method ViewCartEvent ViewCartEvent() |
54
|
|
|
* @method ViewItemEvent ViewItemEvent() |
55
|
|
|
* @method ViewItemListEvent ViewItemListEvent() |
56
|
|
|
* @method ViewSearchResultsEvent ViewSearchResultsEvent() |
57
|
|
|
*/ |
|
|
|
|
58
|
|
|
class ComponentFactory |
59
|
|
|
{ |
60
|
|
|
public function __call(string $componentName, $args) |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
$componentMap = [ |
63
|
|
|
'ItemParameter' => ItemParameter::class, |
64
|
|
|
'AddPaymentInfoEvent' => AddPaymentInfoEvent::class, |
65
|
|
|
'AddShippingInfoEvent' => AddShippingInfoEvent::class, |
66
|
|
|
'AddToCartEvent' => AddToCartEvent::class, |
67
|
|
|
'BaseEvent' => BaseEvent::class, |
68
|
|
|
'BeginCheckoutEvent' => BeginCheckoutEvent::class, |
69
|
|
|
'LoginEvent' => LoginEvent::class, |
70
|
|
|
'PageViewEvent' => PageViewEvent::class, |
71
|
|
|
'PurchaseEvent' => PurchaseEvent::class, |
72
|
|
|
'RefundEvent' => RefundEvent::class, |
73
|
|
|
'RemoveFromCartEvent' => RemoveFromCartEvent::class, |
74
|
|
|
'SearchEvent' => SearchEvent::class, |
75
|
|
|
'SelectItemEvent' => SelectItemEvent::class, |
76
|
|
|
'SignUpEvent' => SignUpEvent::class, |
77
|
|
|
'ViewCartEvent' => ViewCartEvent::class, |
78
|
|
|
'ViewItemEvent' => ViewItemEvent::class, |
79
|
|
|
'ViewItemListEvent' => ViewItemListEvent::class, |
80
|
|
|
'ViewSearchResultsEvent' => ViewSearchResultsEvent::class, |
81
|
|
|
]; |
82
|
|
|
|
83
|
|
|
if (!array_key_exists($componentName, $componentMap)) { |
84
|
|
|
throw new \InvalidArgumentException(Craft::t('instant-analytics-ga4', 'Unknown event type - ' . $componentName)); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return new $componentMap[$componentName](); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|