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 |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
8 | * @copyright Copyright (c) 2017 nystudio107 |
||
0 ignored issues
–
show
|
|||
9 | */ |
||
0 ignored issues
–
show
|
|||
10 | |||
11 | namespace nystudio107\instantanalytics\controllers; |
||
12 | |||
13 | use craft\web\Controller; |
||
14 | use nystudio107\instantanalytics\InstantAnalytics; |
||
15 | |||
16 | /** |
||
17 | * TrackController |
||
18 | * |
||
19 | * @author nystudio107 |
||
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
![]() |
|||
20 | * @package InstantAnalytics |
||
0 ignored issues
–
show
|
|||
21 | * @since 1.0.0 |
||
0 ignored issues
–
show
|
|||
22 | */ |
||
0 ignored issues
–
show
|
|||
23 | class TrackController extends Controller |
||
24 | { |
||
25 | |||
26 | // Protected Properties |
||
27 | // ========================================================================= |
||
28 | |||
29 | /** |
||
0 ignored issues
–
show
|
|||
30 | * @var bool|array Allows anonymous access to this controller's actions. |
||
31 | * The actions must be in 'kebab-case' |
||
32 | * @access protected |
||
33 | */ |
||
34 | protected $allowAnonymous = [ |
||
35 | 'track-page-view-url', |
||
36 | 'track-event-url' |
||
37 | ]; |
||
38 | |||
39 | // Public Methods |
||
40 | // ========================================================================= |
||
41 | |||
42 | /** |
||
0 ignored issues
–
show
|
|||
43 | * @param string $url |
||
0 ignored issues
–
show
|
|||
44 | * @param string $title |
||
0 ignored issues
–
show
|
|||
45 | */ |
||
0 ignored issues
–
show
|
|||
46 | public function actionTrackPageViewUrl(string $url, string $title) |
||
47 | { |
||
48 | $analytics = InstantAnalytics::$plugin->ia->pageViewAnalytics($url, $title); |
||
49 | if ($analytics !== null) { |
||
50 | $analytics->sendPageview(); |
||
51 | } |
||
52 | $this->redirect($url, 200); |
||
53 | } |
||
54 | |||
55 | /** |
||
0 ignored issues
–
show
|
|||
56 | * @param string $url |
||
0 ignored issues
–
show
|
|||
57 | * @param string $eventCategory |
||
0 ignored issues
–
show
|
|||
58 | * @param string $eventAction |
||
0 ignored issues
–
show
|
|||
59 | * @param string $eventLabel |
||
0 ignored issues
–
show
|
|||
60 | * @param int $eventValue |
||
0 ignored issues
–
show
|
|||
61 | */ |
||
0 ignored issues
–
show
|
|||
62 | public function actionTrackEventUrl( |
||
63 | string $url, |
||
64 | string $eventCategory, |
||
65 | string $eventAction, |
||
66 | string $eventLabel, |
||
67 | int $eventValue |
||
68 | ) |
||
69 | { |
||
0 ignored issues
–
show
|
|||
70 | $analytics = InstantAnalytics::$plugin->ia->eventAnalytics( |
||
71 | $eventCategory, |
||
72 | $eventAction, |
||
73 | $eventLabel, |
||
74 | $eventValue |
||
75 | ); |
||
76 | // Get the file name |
||
77 | $path = parse_url($url, PHP_URL_PATH); |
||
78 | if ($analytics !== null) { |
||
79 | $analytics->setDocumentPath($path) |
||
80 | ->sendEvent(); |
||
81 | } |
||
82 | $this->redirect($url, 200); |
||
83 | } |
||
84 | } |
||
85 |