|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Instant Analytics plugin for Craft CMS |
|
4
|
|
|
* |
|
5
|
|
|
* Instant Analytics brings full Google Analytics support to your Twig templates |
|
6
|
|
|
* |
|
7
|
|
|
* @link https://nystudio107.com |
|
|
|
|
|
|
8
|
|
|
* @copyright Copyright (c) 2022 nystudio107 |
|
|
|
|
|
|
9
|
|
|
*/ |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace nystudio107\instantanalyticsGa4\services; |
|
12
|
|
|
|
|
13
|
|
|
use nystudio107\instantanalyticsGa4\assetbundles\instantanalytics\InstantAnalyticsAsset; |
|
14
|
|
|
use nystudio107\instantanalyticsGa4\services\Commerce as CommerceService; |
|
15
|
|
|
use nystudio107\pluginvite\services\VitePluginService; |
|
16
|
|
|
use yii\base\InvalidConfigException; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
|
|
|
|
|
19
|
|
|
* @author nystudio107 |
|
|
|
|
|
|
20
|
|
|
* @package InstantAnalytics |
|
|
|
|
|
|
21
|
|
|
* @since 4.0.0 |
|
|
|
|
|
|
22
|
|
|
* |
|
23
|
|
|
* @property Ga4 $ga4 |
|
24
|
|
|
* @property CommerceService $commerce |
|
25
|
|
|
* @property VitePluginService $vite |
|
26
|
|
|
*/ |
|
|
|
|
|
|
27
|
|
|
trait ServicesTrait |
|
28
|
|
|
{ |
|
29
|
|
|
// Public Static Methods |
|
30
|
|
|
// ========================================================================= |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
|
|
|
|
|
33
|
|
|
* @inheritdoc |
|
34
|
|
|
*/ |
|
|
|
|
|
|
35
|
|
|
public static function config(): array |
|
36
|
|
|
{ |
|
37
|
|
|
// Constants aren't allowed in traits until PHP >= 8.2, and config() is called before __construct(), |
|
38
|
|
|
// so we can't extract it from the passed in $config |
|
39
|
|
|
$majorVersion = '4'; |
|
40
|
|
|
// Dev server container name & port are based on the major version of this plugin |
|
41
|
|
|
$devPort = 3000 + (int)$majorVersion; |
|
42
|
|
|
$versionName = 'v' . $majorVersion; |
|
43
|
|
|
return [ |
|
44
|
|
|
'components' => [ |
|
45
|
|
|
'ga4' => Ga4::class, |
|
46
|
|
|
'commerce' => CommerceService::class, |
|
47
|
|
|
// Register the vite service |
|
48
|
|
|
'vite' => [ |
|
49
|
|
|
'assetClass' => InstantAnalyticsAsset::class, |
|
50
|
|
|
'checkDevServer' => true, |
|
51
|
|
|
'class' => VitePluginService::class, |
|
52
|
|
|
'devServerInternal' => 'http://craft-instantanalytics-ga4-' . $versionName . '-buildchain-dev:' . $devPort, |
|
53
|
|
|
'devServerPublic' => 'http://localhost:' . $devPort, |
|
54
|
|
|
'errorEntry' => 'src/js/app.ts', |
|
55
|
|
|
'useDevServer' => true, |
|
56
|
|
|
], |
|
57
|
|
|
], |
|
58
|
|
|
]; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
// Public Methods |
|
62
|
|
|
// ========================================================================= |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Returns the GA4 service |
|
66
|
|
|
* |
|
67
|
|
|
* @return Ga4 The GA4 service |
|
68
|
|
|
* @throws InvalidConfigException |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getGa4(): Ga4 |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->get('ga4'); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Returns the commerce service |
|
77
|
|
|
* |
|
78
|
|
|
* @return CommerceService The commerce service |
|
79
|
|
|
* @throws InvalidConfigException |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getCommerce(): CommerceService |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->get('commerce'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Returns the vite service |
|
88
|
|
|
* |
|
89
|
|
|
* @return VitePluginService The vite service |
|
90
|
|
|
* @throws InvalidConfigException |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getVite(): VitePluginService |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->get('vite'); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|