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) 2017 nystudio107 |
|
|
|
|
9
|
|
|
*/ |
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace nystudio107\instantanalytics\variables; |
12
|
|
|
|
13
|
|
|
use craft\helpers\Template; |
14
|
|
|
use nystudio107\instantanalytics\helpers\IAnalytics; |
15
|
|
|
use nystudio107\instantanalytics\InstantAnalytics; |
16
|
|
|
use nystudio107\pluginvite\variables\ViteVariableInterface; |
17
|
|
|
use nystudio107\pluginvite\variables\ViteVariableTrait; |
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 implements ViteVariableInterface |
28
|
|
|
{ |
29
|
|
|
use ViteVariableTrait; |
30
|
|
|
|
31
|
|
|
// Public Methods |
32
|
|
|
// ========================================================================= |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Get a PageView analytics object |
36
|
|
|
* |
37
|
|
|
* @param string $url |
|
|
|
|
38
|
|
|
* @param string $title |
|
|
|
|
39
|
|
|
* |
40
|
|
|
* @return null|IAnalytics object |
41
|
|
|
*/ |
42
|
|
|
public function pageViewAnalytics($url = '', $title = '') |
43
|
|
|
{ |
44
|
|
|
return InstantAnalytics::$plugin->ia->pageViewAnalytics($url, $title); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get an Event analytics object |
49
|
|
|
* |
50
|
|
|
* @param string $eventCategory |
|
|
|
|
51
|
|
|
* @param string $eventAction |
|
|
|
|
52
|
|
|
* @param string $eventLabel |
|
|
|
|
53
|
|
|
* @param int $eventValue |
|
|
|
|
54
|
|
|
* |
55
|
|
|
* @return null|IAnalytics |
56
|
|
|
*/ |
57
|
|
|
public function eventAnalytics($eventCategory = '', $eventAction = '', $eventLabel = '', $eventValue = 0) |
58
|
|
|
{ |
59
|
|
|
return InstantAnalytics::$plugin->ia->eventAnalytics($eventCategory, $eventAction, $eventLabel, $eventValue); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Return an Analytics object |
64
|
|
|
* |
65
|
|
|
* @return null|IAnalytics |
66
|
|
|
*/ |
67
|
|
|
public function analytics() |
68
|
|
|
{ |
69
|
|
|
return InstantAnalytics::$plugin->ia->analytics(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Get a PageView tracking URL |
74
|
|
|
* |
75
|
|
|
* @param $url |
|
|
|
|
76
|
|
|
* @param $title |
|
|
|
|
77
|
|
|
* |
78
|
|
|
* @return Markup |
79
|
|
|
* @throws \yii\base\Exception |
80
|
|
|
*/ |
81
|
|
|
public function pageViewTrackingUrl($url, $title): Markup |
82
|
|
|
{ |
83
|
|
|
return Template::raw(InstantAnalytics::$plugin->ia->pageViewTrackingUrl($url, $title)); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get an Event tracking URL |
88
|
|
|
* |
89
|
|
|
* @param $url |
|
|
|
|
90
|
|
|
* @param string $eventCategory |
|
|
|
|
91
|
|
|
* @param string $eventAction |
|
|
|
|
92
|
|
|
* @param string $eventLabel |
|
|
|
|
93
|
|
|
* @param int $eventValue |
|
|
|
|
94
|
|
|
* |
95
|
|
|
* @return Markup |
96
|
|
|
* @throws \yii\base\Exception |
97
|
|
|
*/ |
98
|
|
|
public function eventTrackingUrl( |
99
|
|
|
$url, |
100
|
|
|
$eventCategory = '', |
101
|
|
|
$eventAction = '', |
102
|
|
|
$eventLabel = '', |
103
|
|
|
$eventValue = 0 |
104
|
|
|
): Markup |
105
|
|
|
{ |
|
|
|
|
106
|
|
|
return Template::raw(InstantAnalytics::$plugin->ia->eventTrackingUrl( |
|
|
|
|
107
|
|
|
$url, |
108
|
|
|
$eventCategory, |
109
|
|
|
$eventAction, |
110
|
|
|
$eventLabel, |
111
|
|
|
$eventValue |
112
|
|
|
)); |
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Return whether we are running Craft 3.1 or later |
117
|
|
|
* |
118
|
|
|
* @return bool |
119
|
|
|
*/ |
120
|
|
|
public function craft31(): bool |
121
|
|
|
{ |
122
|
|
|
return InstantAnalytics::$craft31; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|