nystudio107 /
craft-instantanalytics
| 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
Loading history...
|
|||
| 8 | * @copyright Copyright (c) 2017 nystudio107 |
||
|
0 ignored issues
–
show
|
|||
| 9 | */ |
||
|
0 ignored issues
–
show
|
|||
| 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 |
||
|
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
|
|||
| 24 | * @package InstantAnalytics |
||
|
0 ignored issues
–
show
|
|||
| 25 | * @since 1.0.0 |
||
|
0 ignored issues
–
show
|
|||
| 26 | */ |
||
|
0 ignored issues
–
show
|
|||
| 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 |
||
|
0 ignored issues
–
show
|
|||
| 38 | * @param string $title |
||
|
0 ignored issues
–
show
|
|||
| 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 |
||
|
0 ignored issues
–
show
|
|||
| 51 | * @param string $eventAction |
||
|
0 ignored issues
–
show
|
|||
| 52 | * @param string $eventLabel |
||
|
0 ignored issues
–
show
|
|||
| 53 | * @param int $eventValue |
||
|
0 ignored issues
–
show
|
|||
| 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 |
||
|
0 ignored issues
–
show
|
|||
| 76 | * @param $title |
||
|
0 ignored issues
–
show
|
|||
| 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 |
||
|
0 ignored issues
–
show
|
|||
| 90 | * @param string $eventCategory |
||
|
0 ignored issues
–
show
|
|||
| 91 | * @param string $eventAction |
||
|
0 ignored issues
–
show
|
|||
| 92 | * @param string $eventLabel |
||
|
0 ignored issues
–
show
|
|||
| 93 | * @param int $eventValue |
||
|
0 ignored issues
–
show
|
|||
| 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 | { |
||
|
0 ignored issues
–
show
|
|||
| 106 | return Template::raw(InstantAnalytics::$plugin->ia->eventTrackingUrl( |
||
|
0 ignored issues
–
show
|
|||
| 107 | $url, |
||
| 108 | $eventCategory, |
||
| 109 | $eventAction, |
||
| 110 | $eventLabel, |
||
| 111 | $eventValue |
||
| 112 | )); |
||
|
0 ignored issues
–
show
For multi-line function calls, the closing parenthesis should be on a new line.
If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line: someFunctionCall(
$firstArgument,
$secondArgument,
$thirdArgument
); // Closing parenthesis on a new line.
Loading history...
|
|||
| 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 |