1 | <?php |
||
21 | class GoogleAnalytics extends AbstractTracker |
||
22 | { |
||
23 | const TRACKER_URL_ONE = 'https://www.google-analytics.com/collect'; |
||
24 | |||
25 | const TRACKER_URL_MANY = 'https://www.google-analytics.com/batch'; |
||
26 | |||
27 | //const DEFAULT_PARAMS = array( |
||
|
|||
28 | private $DEFAULT_PARAMS = array( |
||
29 | 'v' => 1, // API Version |
||
30 | 'tid' => null, // Tracking/Property (required) ID e.g. UA-XX-XX |
||
31 | 'cid' => null, // Anonymous Client ID UUIDv4 |
||
32 | // see http://www.ietf.org/rfc/rfc4122.txt |
||
33 | 'ds' => __NAMESPACE__, // Data Source |
||
34 | 't' => null, // Hit type (required) |
||
35 | ); |
||
36 | |||
37 | /** |
||
38 | * Constructor. |
||
39 | * |
||
40 | * @param array $params Array of Google Analytics parameters |
||
41 | */ |
||
42 | 48 | public function __construct( |
|
43 | array $params, LogEmitter $emitter = null, LogFormatter $formatter = null |
||
44 | ) { |
||
45 | 48 | if (!isset($params['tid'])) { |
|
46 | 4 | throw new InvalidArgumentException(sprintf( |
|
47 | 4 | '%s expects `tid` to bet provided, got: %s.', |
|
48 | 4 | __CLASS__, json_encode($params) |
|
49 | 3 | )); |
|
50 | } |
||
51 | |||
52 | 48 | if (!isset($params['cid'])) { |
|
53 | 4 | $params['cid'] = self::generateUuid(); |
|
54 | 3 | } |
|
55 | 48 | $this->uuid = $params['cid']; |
|
56 | |||
57 | 48 | $this->setEmitter( |
|
58 | 48 | $emitter ? $emitter : new Emitter\Async(), |
|
59 | 48 | $formatter ? $formatter : new LogFormatter\QueryString() |
|
60 | 36 | ); |
|
61 | 48 | $this->emitter->setParams($this->DEFAULT_PARAMS); |
|
62 | |||
63 | 48 | if (isset($_SERVER['HTTP_USER_AGENT']) && !isset($params['ua'])) { |
|
64 | 4 | $params['ua'] = $_SERVER['HTTP_USER_AGENT']; |
|
65 | 3 | } |
|
66 | |||
67 | 48 | if (isset($_SERVER['HTTP_REFERER']) && !isset($params['dr'])) { |
|
68 | 4 | $params['dr'] = $_SERVER['HTTP_REFERER']; |
|
69 | 3 | } |
|
70 | |||
71 | 48 | if (isset($_SERVER['REMOTE_ADDR']) && !isset($params['uip'])) { |
|
72 | 4 | $params['uip'] = $_SERVER['REMOTE_ADDR']; |
|
73 | 3 | } |
|
74 | |||
75 | 48 | $this->emitter->addParams($params); |
|
76 | 48 | } |
|
77 | |||
78 | /** |
||
79 | * Returns a Page Tracking dataset. |
||
80 | * |
||
81 | * @param string $url The full URL for ht page document |
||
82 | * @param string $title The title of the page / document |
||
83 | * @param string $location Document location URL |
||
84 | * |
||
85 | * @return array |
||
86 | */ |
||
87 | 12 | public function getPage($url, $title = null, $location = null) |
|
113 | |||
114 | /** |
||
115 | * Returns an Event Tracking dataset. |
||
116 | * |
||
117 | * @param string $category |
||
118 | * @param string $action |
||
119 | * @param string $label |
||
120 | * @param string $value |
||
121 | * |
||
122 | * @return array |
||
123 | */ |
||
124 | 12 | public function getEvent($category, $action, $label = null, $value = null) |
|
143 | |||
144 | /** |
||
145 | * Returns a Social Interactions dataset. |
||
146 | * |
||
147 | * @param string $action Social Action (e.g. like) |
||
148 | * @param string $label Social Network (e.g. facebook) |
||
149 | * @param string $value Social Target. (e.g. /home) |
||
150 | * |
||
151 | * @return array |
||
152 | */ |
||
153 | 4 | public function getSocial($action, $network, $target) |
|
163 | |||
164 | /** |
||
165 | * Returns an Exception Tracking dataset. |
||
166 | * |
||
167 | * @param string $description Exception description |
||
168 | * @param string $isFatal Specifies whether the exception was fatal |
||
169 | * |
||
170 | * @return array |
||
171 | */ |
||
172 | 4 | public function getException($description, $isFatal = true) |
|
181 | |||
182 | /** |
||
183 | * Returns an App / Screen Tracking dataset. |
||
184 | * |
||
185 | * @param string $name App name |
||
186 | * @param string $version App version |
||
187 | * @param string $id App Id |
||
188 | * @param string $iid App Installer Id |
||
189 | * |
||
190 | * @return array |
||
191 | */ |
||
192 | 4 | public function getApp($name, $version = null, $id = null, $iid = null) |
|
203 | |||
204 | /** |
||
205 | * Returns the named tracking dataset. |
||
206 | * |
||
207 | * @return array |
||
208 | */ |
||
209 | 32 | public function get($type, array $params) |
|
218 | } |
||
219 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.