InstantAnalyticsVariable   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
c 2
b 0
f 0
dl 0
loc 78
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A pageViewEvent() 0 3 1
A pageViewTrackingUrl() 0 3 1
A addCommerceProductView() 0 3 1
A simpleEvent() 0 3 1
A ga4() 0 3 1
A eventTrackingUrl() 0 6 1
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
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @copyright Copyright (c) 2017 nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
9
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
10
11
namespace nystudio107\instantanalyticsGa4\variables;
12
13
use Br33f\Ga4\MeasurementProtocol\Dto\Event\BaseEvent;
14
use craft\commerce\elements\Product;
15
use craft\commerce\elements\Variant;
16
use craft\helpers\Template;
17
use nystudio107\instantanalyticsGa4\ga4\Analytics;
18
use nystudio107\instantanalyticsGa4\ga4\events\PageViewEvent;
19
use nystudio107\instantanalyticsGa4\helpers\Analytics as AnalyticsHelper;
20
use nystudio107\instantanalyticsGa4\InstantAnalytics;
21
use nystudio107\pluginvite\variables\ViteVariableInterface;
22
use nystudio107\pluginvite\variables\ViteVariableTrait;
23
use Twig\Markup;
24
use yii\base\Exception;
25
26
/**
27
 * Instant Analytics Variable
28
 *
29
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
30
 * @package   InstantAnalytics
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
31
 * @since     1.0.0
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
Coding Style introduced by
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
32
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
33
class InstantAnalyticsVariable implements ViteVariableInterface
34
{
35
    use ViteVariableTrait;
36
37
    // Public Methods
38
    // =========================================================================
39
40
    /**
41
     * Get a PageView Event
42
     *
43
     * @param string $url
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
44
     * @param string $title
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
45
     *
46
     * @return PageViewEvent
47
     */
48
    public function pageViewEvent(string $url = '', string $title = ''): PageViewEvent
49
    {
50
        return InstantAnalytics::$plugin->ga4->getPageViewEvent($url, $title);
51
    }
52
53
    /**
54
     * Get a simple event
55
     *
56
     * @param string $eventName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
57
     * @return BaseEvent
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
58
     */
59
    public function simpleEvent(string $eventName = ''): BaseEvent
60
    {
61
        return InstantAnalytics::$plugin->ga4->getSimpleEvent($eventName);
62
    }
63
64
    /**
65
     * Return the GA4 Analytics object
66
     *
67
     * @return Analytics
68
     */
69
    public function ga4(): Analytics
70
    {
71
        return InstantAnalytics::$plugin->ga4->getAnalytics();
72
    }
73
74
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
75
     * @param Product|Variant $productVariant the Product or Variant
76
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
77
    public function addCommerceProductView($productVariant): void
78
    {
79
        InstantAnalytics::$plugin->commerce->addCommerceProductImpression($productVariant);
80
    }
81
82
    /**
83
     * Get a PageView tracking URL
84
     *
85
     * @param $url
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
86
     * @param $title
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
87
     *
88
     * @return Markup
89
     * @throws Exception
90
     */
91
    public function pageViewTrackingUrl($url, $title): Markup
92
    {
93
        return Template::raw(AnalyticsHelper::getPageViewTrackingUrl($url, $title));
94
    }
95
96
    /**
97
     * Get an Event tracking URL
98
     *
99
     * @param string $url
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
100
     * @param string $eventName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
101
     * @param array $params
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
102
     * @return Markup
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
103
     * @throws Exception
0 ignored issues
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
104
     */
105
    public function eventTrackingUrl(
106
        string $url,
107
        string $eventName = '',
108
        array  $params = [],
109
    ): Markup {
110
        return Template::raw(AnalyticsHelper::getEventTrackingUrl($url, $eventName, $params));
111
    }
112
}
113