nystudio107 /
craft-instantanalytics
| 1 | <?php |
||||
| 2 | /** |
||||
| 3 | * Instant Analytics plugin for Craft CMS |
||||
| 4 | * |
||||
| 5 | * @author nystudio107 |
||||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
|
|||||
| 6 | * @copyright Copyright (c) 2017 nystudio107 |
||||
|
0 ignored issues
–
show
|
|||||
| 7 | * @link http://nystudio107.com |
||||
|
0 ignored issues
–
show
|
|||||
| 8 | * @package InstantAnalytics |
||||
|
0 ignored issues
–
show
|
|||||
| 9 | * @since 1.0.0 |
||||
| 10 | */ |
||||
|
0 ignored issues
–
show
|
|||||
| 11 | |||||
| 12 | namespace nystudio107\instantanalytics\helpers; |
||||
| 13 | |||||
| 14 | use nystudio107\instantanalytics\InstantAnalytics; |
||||
| 15 | use nystudio107\instantanalytics\models\Settings; |
||||
| 16 | |||||
| 17 | use Craft; |
||||
| 18 | |||||
| 19 | use \TheIconic\Tracking\GoogleAnalytics\Analytics; |
||||
|
0 ignored issues
–
show
The type
\TheIconic\Tracking\GoogleAnalytics\Analytics was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 20 | use \TheIconic\Tracking\GoogleAnalytics\AnalyticsResponseInterface; |
||||
|
0 ignored issues
–
show
The type
\TheIconic\Tracking\Goog...lyticsResponseInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 21 | |||||
| 22 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 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 IAnalytics extends Analytics |
||||
| 28 | { |
||||
| 29 | |||||
| 30 | protected $shouldSendAnalytics = null; |
||||
| 31 | |||||
| 32 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 33 | * @inheritdoc |
||||
| 34 | */ |
||||
| 35 | public function __construct($isSsl = false, $isDisabled = false, array $options = []) |
||||
| 36 | { |
||||
| 37 | // Store whether or not we should be sending Analytics data |
||||
| 38 | $this->shouldSendAnalytics = InstantAnalytics::$settings->sendAnalyticsData; |
||||
| 39 | |||||
| 40 | parent::__construct($isSsl, $isDisabled, $options); |
||||
| 41 | } |
||||
| 42 | |||||
| 43 | /** |
||||
| 44 | * Turn an empty value so the twig tags {{ }} can be used |
||||
| 45 | * |
||||
| 46 | * @return string '' |
||||
| 47 | */ |
||||
| 48 | public function __toString() |
||||
| 49 | { |
||||
| 50 | return ''; |
||||
| 51 | } |
||||
| 52 | |||||
| 53 | /** |
||||
| 54 | * Add a product impression to the Analytics object |
||||
| 55 | * |
||||
| 56 | * @param string $productVariant |
||||
|
0 ignored issues
–
show
|
|||||
| 57 | * @param int $index |
||||
|
0 ignored issues
–
show
|
|||||
| 58 | * @param string $listName |
||||
|
0 ignored issues
–
show
|
|||||
| 59 | * @param int $listIndex |
||||
|
0 ignored issues
–
show
|
|||||
| 60 | */ |
||||
|
0 ignored issues
–
show
|
|||||
| 61 | public function addCommerceProductImpression( |
||||
| 62 | $productVariant = null, |
||||
| 63 | $index = 0, |
||||
| 64 | $listName = 'default', |
||||
| 65 | $listIndex = 1 |
||||
| 66 | ) { |
||||
| 67 | |||||
| 68 | if (InstantAnalytics::$commercePlugin) { |
||||
| 69 | if ($productVariant) { |
||||
| 70 | InstantAnalytics::$plugin->commerce->addCommerceProductImpression( |
||||
| 71 | $this, |
||||
| 72 | $productVariant, |
||||
|
0 ignored issues
–
show
$productVariant of type string is incompatible with the type craft\commerce\elements\...mmerce\elements\Variant expected by parameter $productVariant of nystudio107\instantanaly...erceProductImpression().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 73 | $index, |
||||
| 74 | $listName, |
||||
| 75 | $listIndex |
||||
| 76 | ); |
||||
| 77 | } |
||||
| 78 | } else { |
||||
| 79 | Craft::warning( |
||||
| 80 | Craft::t( |
||||
| 81 | 'instant-analytics', |
||||
| 82 | 'Craft Commerce is not installed' |
||||
| 83 | ), |
||||
| 84 | __METHOD__ |
||||
| 85 | ); |
||||
| 86 | } |
||||
| 87 | } |
||||
| 88 | |||||
| 89 | /** |
||||
| 90 | * Add a product detail view to the Analytics object |
||||
| 91 | * |
||||
| 92 | * @param string $productVariant |
||||
|
0 ignored issues
–
show
|
|||||
| 93 | */ |
||||
|
0 ignored issues
–
show
|
|||||
| 94 | public function addCommerceProductDetailView($productVariant = null) |
||||
| 95 | { |
||||
| 96 | if (InstantAnalytics::$commercePlugin) { |
||||
| 97 | if ($productVariant) { |
||||
| 98 | InstantAnalytics::$plugin->commerce->addCommerceProductDetailView($this, $productVariant); |
||||
|
0 ignored issues
–
show
$productVariant of type string is incompatible with the type craft\commerce\elements\...mmerce\elements\Variant expected by parameter $productVariant of nystudio107\instantanaly...erceProductDetailView().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 99 | } |
||||
| 100 | } else { |
||||
| 101 | Craft::warning( |
||||
| 102 | Craft::t( |
||||
| 103 | 'instant-analytics', |
||||
| 104 | 'Craft Commerce is not installed' |
||||
| 105 | ), |
||||
| 106 | __METHOD__ |
||||
| 107 | ); |
||||
| 108 | } |
||||
| 109 | } |
||||
| 110 | |||||
| 111 | /** |
||||
| 112 | * Add a checkout step to the Analytics object |
||||
| 113 | * |
||||
| 114 | * @param $orderModel |
||||
|
0 ignored issues
–
show
|
|||||
| 115 | * @param int $step |
||||
|
0 ignored issues
–
show
|
|||||
| 116 | * @param string $option |
||||
|
0 ignored issues
–
show
|
|||||
| 117 | */ |
||||
|
0 ignored issues
–
show
|
|||||
| 118 | public function addCommerceCheckoutStep($orderModel = null, $step = 1, $option = "") |
||||
| 119 | { |
||||
| 120 | if (InstantAnalytics::$commercePlugin) { |
||||
| 121 | if ($orderModel) { |
||||
| 122 | InstantAnalytics::$plugin->commerce->addCommerceCheckoutStep($this, $orderModel, $step, $option); |
||||
| 123 | } |
||||
| 124 | } else { |
||||
| 125 | Craft::warning( |
||||
| 126 | Craft::t( |
||||
| 127 | 'instant-analytics', |
||||
| 128 | 'Craft Commerce is not installed' |
||||
| 129 | ), |
||||
| 130 | __METHOD__ |
||||
| 131 | ); |
||||
| 132 | } |
||||
| 133 | } |
||||
| 134 | |||||
| 135 | /** |
||||
| 136 | * Override sendHit() so that we can prevent Analytics data from being sent |
||||
| 137 | * |
||||
| 138 | * @param $methodName |
||||
|
0 ignored issues
–
show
|
|||||
| 139 | * |
||||
| 140 | * @return AnalyticsResponseInterface|null |
||||
| 141 | */ |
||||
| 142 | protected function sendHit($methodName) |
||||
| 143 | { |
||||
| 144 | $requestIp = $_SERVER['REMOTE_ADDR']; |
||||
| 145 | if ($this->shouldSendAnalytics) { |
||||
| 146 | if ($this->getClientId() !== null || $this->getUserId() !== null) { |
||||
| 147 | try { |
||||
| 148 | Craft::info( |
||||
| 149 | 'Send hit for IAnalytics object: ' . print_r($this, true), |
||||
|
0 ignored issues
–
show
Are you sure
print_r($this, true) of type string|true can be used in concatenation?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 150 | __METHOD__ |
||||
| 151 | ); |
||||
| 152 | |||||
| 153 | return parent::sendHit($methodName); |
||||
| 154 | } catch (\Exception $e) { |
||||
| 155 | if (InstantAnalytics::$settings->logExcludedAnalytics) { |
||||
| 156 | Craft::info( |
||||
| 157 | '*** sendHit(): error sending analytics: ' . $e->getMessage(), |
||||
| 158 | __METHOD__ |
||||
| 159 | ); |
||||
| 160 | } |
||||
| 161 | } |
||||
| 162 | } elseif (InstantAnalytics::$settings->logExcludedAnalytics) { |
||||
| 163 | Craft::info( |
||||
| 164 | '*** sendHit(): analytics not sent for '.$requestIp. ' because no clientId or userId is set', |
||||
| 165 | __METHOD__ |
||||
| 166 | ); |
||||
| 167 | } |
||||
| 168 | } elseif (InstantAnalytics::$settings->logExcludedAnalytics) { |
||||
| 169 | Craft::info( |
||||
| 170 | '*** sendHit(): analytics not sent for '.$requestIp, |
||||
| 171 | __METHOD__ |
||||
| 172 | ); |
||||
| 173 | } |
||||
| 174 | |||||
| 175 | return null; |
||||
| 176 | } |
||||
| 177 | } |
||||
| 178 |