1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Instant Analytics plugin for Craft CMS 3.x |
4
|
|
|
* |
5
|
|
|
* Instant Analytics brings full Google Analytics support to your Twig templates |
6
|
|
|
* |
7
|
|
|
* @link https://nystudio107.com |
|
|
|
|
8
|
|
|
* @copyright Copyright (c) 2017 nystudio107 |
|
|
|
|
9
|
|
|
*/ |
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace nystudio107\instantanalytics\variables; |
12
|
|
|
|
13
|
|
|
use nystudio107\instantanalytics\InstantAnalytics; |
14
|
|
|
use nystudio107\instantanalytics\helpers\IAnalytics; |
15
|
|
|
|
16
|
|
|
use craft\helpers\Template; |
17
|
|
|
|
18
|
|
|
use \Twig\Markup; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Instant Analytics Variable |
22
|
|
|
* |
23
|
|
|
* @author nystudio107 |
|
|
|
|
24
|
|
|
* @package InstantAnalytics |
|
|
|
|
25
|
|
|
* @since 1.0.0 |
|
|
|
|
26
|
|
|
*/ |
|
|
|
|
27
|
|
|
class InstantAnalyticsVariable extends ManifestVariable |
28
|
|
|
{ |
29
|
|
|
// Public Methods |
30
|
|
|
// ========================================================================= |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get a PageView analytics object |
34
|
|
|
* |
35
|
|
|
* @param string $url |
|
|
|
|
36
|
|
|
* @param string $title |
|
|
|
|
37
|
|
|
* |
38
|
|
|
* @return null|IAnalytics object |
39
|
|
|
*/ |
40
|
|
|
public function pageViewAnalytics($url = '', $title = '') |
41
|
|
|
{ |
42
|
|
|
return InstantAnalytics::$plugin->ia->pageViewAnalytics($url, $title); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Get an Event analytics object |
47
|
|
|
* |
48
|
|
|
* @param string $eventCategory |
|
|
|
|
49
|
|
|
* @param string $eventAction |
|
|
|
|
50
|
|
|
* @param string $eventLabel |
|
|
|
|
51
|
|
|
* @param int $eventValue |
|
|
|
|
52
|
|
|
* |
53
|
|
|
* @return null|IAnalytics |
54
|
|
|
*/ |
55
|
|
|
public function eventAnalytics($eventCategory = '', $eventAction = '', $eventLabel = '', $eventValue = 0) |
56
|
|
|
{ |
57
|
|
|
return InstantAnalytics::$plugin->ia->eventAnalytics($eventCategory, $eventAction, $eventLabel, $eventValue); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Return an Analytics object |
62
|
|
|
* |
63
|
|
|
* @return null|IAnalytics |
64
|
|
|
*/ |
65
|
|
|
public function analytics() |
66
|
|
|
{ |
67
|
|
|
return InstantAnalytics::$plugin->ia->analytics(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get a PageView tracking URL |
72
|
|
|
* |
73
|
|
|
* @param $url |
|
|
|
|
74
|
|
|
* @param $title |
|
|
|
|
75
|
|
|
* |
76
|
|
|
* @return Markup |
77
|
|
|
* @throws \yii\base\Exception |
78
|
|
|
*/ |
79
|
|
|
public function pageViewTrackingUrl($url, $title): Markup |
80
|
|
|
{ |
81
|
|
|
return Template::raw(InstantAnalytics::$plugin->ia->pageViewTrackingUrl($url, $title)); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get an Event tracking URL |
86
|
|
|
* |
87
|
|
|
* @param $url |
|
|
|
|
88
|
|
|
* @param string $eventCategory |
|
|
|
|
89
|
|
|
* @param string $eventAction |
|
|
|
|
90
|
|
|
* @param string $eventLabel |
|
|
|
|
91
|
|
|
* @param int $eventValue |
|
|
|
|
92
|
|
|
* |
93
|
|
|
* @return Markup |
94
|
|
|
* @throws \yii\base\Exception |
95
|
|
|
*/ |
96
|
|
|
public function eventTrackingUrl( |
97
|
|
|
$url, |
98
|
|
|
$eventCategory = '', |
99
|
|
|
$eventAction = '', |
100
|
|
|
$eventLabel = '', |
101
|
|
|
$eventValue = 0 |
102
|
|
|
): Markup { |
103
|
|
|
return Template::raw(InstantAnalytics::$plugin->ia->eventTrackingUrl( |
|
|
|
|
104
|
|
|
$url, |
105
|
|
|
$eventCategory, |
106
|
|
|
$eventAction, |
107
|
|
|
$eventLabel, |
108
|
|
|
$eventValue |
109
|
|
|
)); |
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Return whether we are running Craft 3.1 or later |
114
|
|
|
* |
115
|
|
|
* @return bool |
116
|
|
|
*/ |
117
|
|
|
public function craft31(): bool |
118
|
|
|
{ |
119
|
|
|
return InstantAnalytics::$craft31; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|