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\models; |
||
| 12 | |||
| 13 | use craft\base\Model; |
||
| 14 | use craft\behaviors\EnvAttributeParserBehavior; |
||
| 15 | use craft\validators\ArrayValidator; |
||
| 16 | use nystudio107\instantanalytics\InstantAnalytics; |
||
| 17 | use yii\behaviors\AttributeTypecastBehavior; |
||
| 18 | |||
| 19 | /** |
||
|
0 ignored issues
–
show
|
|||
| 20 | * @author nystudio107 |
||
|
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
|
|||
| 21 | * @package InstantAnalytics |
||
|
0 ignored issues
–
show
|
|||
| 22 | * @since 1.0.0 |
||
|
0 ignored issues
–
show
|
|||
| 23 | */ |
||
|
0 ignored issues
–
show
|
|||
| 24 | class Settings extends Model |
||
| 25 | { |
||
| 26 | // Public Properties |
||
| 27 | // ========================================================================= |
||
| 28 | |||
| 29 | /** |
||
| 30 | * The default Google Analytics tracking ID |
||
| 31 | * |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | public $googleAnalyticsTracking = ''; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Should the query string be stripped from the page tracking URL? |
||
| 38 | * |
||
| 39 | * @var bool |
||
| 40 | */ |
||
| 41 | public $stripQueryString = true; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Should page views be sent automatically when a page view happens? |
||
| 45 | * |
||
| 46 | * @var bool |
||
| 47 | */ |
||
| 48 | public $autoSendPageView = true; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * If you plan to use Instant Analytics in conjunction with frontend JavaScript, this setting should be on, so that Instant Analytics requires a `clientId` from the frontend-set GA cookie before it will send analytics data. |
||
| 52 | * @var bool |
||
|
0 ignored issues
–
show
|
|||
| 53 | */ |
||
| 54 | public $requireGaCookieClientId = true; |
||
| 55 | |||
| 56 | /** |
||
|
0 ignored issues
–
show
|
|||
| 57 | * @var bool Should the GCLID cookie be created if it doesn't exist? |
||
| 58 | */ |
||
| 59 | public $createGclidCookie = true; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * The field in a Commerce Product Variant that should be used for the |
||
| 63 | * category |
||
| 64 | * |
||
| 65 | * @var string |
||
| 66 | */ |
||
| 67 | public $productCategoryField = ''; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * The field in a Commerce Product Variant that should be used for the brand |
||
| 71 | * |
||
| 72 | * @var string |
||
| 73 | */ |
||
| 74 | public $productBrandField = ''; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Whether add to cart events should be automatically sent |
||
| 78 | * |
||
| 79 | * @var bool |
||
| 80 | */ |
||
| 81 | public $autoSendAddToCart = true; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Whether remove from cart events should be automatically sent |
||
| 85 | * |
||
| 86 | * @var bool |
||
| 87 | */ |
||
| 88 | public $autoSendRemoveFromCart = true; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Whether purchase complete events should be automatically sent |
||
| 92 | * |
||
| 93 | * @var bool |
||
| 94 | */ |
||
| 95 | public $autoSendPurchaseComplete = true; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Controls whether Instant Analytics will send analytics data. |
||
| 99 | * |
||
| 100 | * @var bool |
||
| 101 | */ |
||
| 102 | public $sendAnalyticsData = true; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Controls whether Instant Analytics will send analytics data when |
||
| 106 | * `devMode` is on. |
||
| 107 | * |
||
| 108 | * @var bool |
||
| 109 | */ |
||
| 110 | public $sendAnalyticsInDevMode = true; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Controls whether we should filter out bot UserGents. |
||
| 114 | * |
||
| 115 | * @var bool |
||
| 116 | */ |
||
| 117 | public $filterBotUserAgents = true; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Controls whether we should exclude users logged into an admin account |
||
| 121 | * from Analytics tracking. |
||
| 122 | * |
||
| 123 | * @var bool |
||
| 124 | */ |
||
| 125 | public $adminExclude = false; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Controls whether analytics that blocked from being sent should be logged |
||
| 129 | * to storage/logs/web.log These are always logged if `devMode` is on |
||
| 130 | * |
||
| 131 | * @var bool |
||
| 132 | */ |
||
| 133 | public $logExcludedAnalytics = true; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Contains an array of Craft user group handles to exclude from Analytics |
||
| 137 | * tracking. If there's a match for any of them, analytics data is not |
||
| 138 | * sent. |
||
| 139 | * |
||
| 140 | * @var array |
||
| 141 | */ |
||
| 142 | public $groupExcludes = [ |
||
| 143 | ]; |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Contains an array of keys that correspond to $_SERVER[] super-global |
||
| 147 | * array keys to test against. Each item in the sub-array is tested against |
||
| 148 | * the $_SERVER[] super-global key via RegEx; if there's a match for any of |
||
| 149 | * them, analytics data is not sent. This allows you to filter based on |
||
| 150 | * whatever information you want. Reference: |
||
| 151 | * http://php.net/manual/en/reserved.variables.server.php RegEx tester: |
||
| 152 | * http://regexr.com |
||
| 153 | * |
||
| 154 | * @var array |
||
| 155 | */ |
||
| 156 | public $serverExcludes = [ |
||
| 157 | 'REMOTE_ADDR' => [ |
||
| 158 | '/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/', |
||
| 159 | ], |
||
| 160 | ]; |
||
| 161 | |||
| 162 | // Public Methods |
||
| 163 | // ========================================================================= |
||
| 164 | |||
| 165 | /** @noinspection ReturnTypeCanBeDeclaredInspection */ |
||
|
0 ignored issues
–
show
|
|||
| 166 | /** |
||
|
0 ignored issues
–
show
|
|||
| 167 | * @return array |
||
| 168 | */ |
||
| 169 | public function rules() |
||
| 170 | { |
||
| 171 | return [ |
||
| 172 | [ |
||
| 173 | [ |
||
| 174 | 'stripQueryString', |
||
| 175 | 'autoSendPageView', |
||
| 176 | 'requireGaCookieClientId', |
||
| 177 | 'createGclidCookie', |
||
| 178 | 'autoSendAddToCart', |
||
| 179 | 'autoSendRemoveFromCart', |
||
| 180 | 'autoSendPurchaseComplete', |
||
| 181 | 'sendAnalyticsData', |
||
| 182 | 'sendAnalyticsInDevMode', |
||
| 183 | 'filterBotUserAgents', |
||
| 184 | 'adminExclude', |
||
| 185 | 'logExcludedAnalytics', |
||
| 186 | ], |
||
| 187 | 'boolean', |
||
| 188 | ], |
||
| 189 | [ |
||
| 190 | [ |
||
| 191 | 'googleAnalyticsTracking', |
||
| 192 | 'productCategoryField', |
||
| 193 | 'productBrandField', |
||
| 194 | 'googleAnalyticsTracking', |
||
| 195 | ], |
||
| 196 | 'string', |
||
| 197 | ], |
||
| 198 | [ |
||
| 199 | [ |
||
| 200 | 'groupExcludes', |
||
| 201 | 'serverExcludes', |
||
| 202 | ], |
||
| 203 | ArrayValidator::class, |
||
| 204 | ], |
||
| 205 | ]; |
||
| 206 | } |
||
| 207 | |||
| 208 | /** |
||
|
0 ignored issues
–
show
|
|||
| 209 | * @return array |
||
| 210 | */ |
||
| 211 | public function behaviors() |
||
| 212 | { |
||
| 213 | $craft31Behaviors = []; |
||
| 214 | if (InstantAnalytics::$craft31) { |
||
| 215 | $craft31Behaviors = [ |
||
| 216 | 'parser' => [ |
||
| 217 | 'class' => EnvAttributeParserBehavior::class, |
||
| 218 | 'attributes' => [ |
||
| 219 | 'googleAnalyticsTracking', |
||
| 220 | ], |
||
| 221 | ], |
||
| 222 | ]; |
||
| 223 | } |
||
| 224 | |||
| 225 | return array_merge($craft31Behaviors, [ |
||
|
0 ignored issues
–
show
|
|||
| 226 | 'typecast' => [ |
||
| 227 | 'class' => AttributeTypecastBehavior::class, |
||
| 228 | // 'attributeTypes' will be composed automatically according to `rules()` |
||
| 229 | ], |
||
| 230 | ]); |
||
|
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...
|
|||
| 231 | } |
||
| 232 | } |
||
| 233 |