sluice_connect - Version 0.1.0

Version Notes

- Track add to cart event (via google analitics)
- Give Magento data access to Sluice HQ (via Web Services)

Download this release

Release Info

Developer Shavrukov Konstantin
Extension sluice_connect
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

Files changed (28) hide show
  1. app/code/local/Sluice/Connect/Helper/Data.php +6 -0
  2. app/code/local/Sluice/Connect/Model/Observer.php +91 -0
  3. app/code/local/Sluice/Connect/etc/config.xml +84 -0
  4. app/code/local/Sluice/Connect/etc/system.xml +41 -0
  5. app/code/local/Sluice/Connect/lib/GoogleAnalytics/Campaign.php +378 -0
  6. app/code/local/Sluice/Connect/lib/GoogleAnalytics/Config.php +295 -0
  7. app/code/local/Sluice/Connect/lib/GoogleAnalytics/CustomVariable.php +180 -0
  8. app/code/local/Sluice/Connect/lib/GoogleAnalytics/Event.php +169 -0
  9. app/code/local/Sluice/Connect/lib/GoogleAnalytics/Exception.php +39 -0
  10. app/code/local/Sluice/Connect/lib/GoogleAnalytics/Internals/ParameterHolder.php +536 -0
  11. app/code/local/Sluice/Connect/lib/GoogleAnalytics/Internals/Request/EventRequest.php +109 -0
  12. app/code/local/Sluice/Connect/lib/GoogleAnalytics/Internals/Request/HttpRequest.php +239 -0
  13. app/code/local/Sluice/Connect/lib/GoogleAnalytics/Internals/Request/ItemRequest.php +106 -0
  14. app/code/local/Sluice/Connect/lib/GoogleAnalytics/Internals/Request/PageviewRequest.php +108 -0
  15. app/code/local/Sluice/Connect/lib/GoogleAnalytics/Internals/Request/Request.php +363 -0
  16. app/code/local/Sluice/Connect/lib/GoogleAnalytics/Internals/Request/SocialInteractionRequest.php +82 -0
  17. app/code/local/Sluice/Connect/lib/GoogleAnalytics/Internals/Request/TransactionRequest.php +108 -0
  18. app/code/local/Sluice/Connect/lib/GoogleAnalytics/Internals/Util.php +105 -0
  19. app/code/local/Sluice/Connect/lib/GoogleAnalytics/Internals/X10.php +331 -0
  20. app/code/local/Sluice/Connect/lib/GoogleAnalytics/Item.php +180 -0
  21. app/code/local/Sluice/Connect/lib/GoogleAnalytics/Page.php +172 -0
  22. app/code/local/Sluice/Connect/lib/GoogleAnalytics/Session.php +161 -0
  23. app/code/local/Sluice/Connect/lib/GoogleAnalytics/SocialInteraction.php +123 -0
  24. app/code/local/Sluice/Connect/lib/GoogleAnalytics/Tracker.php +344 -0
  25. app/code/local/Sluice/Connect/lib/GoogleAnalytics/Transaction.php +252 -0
  26. app/code/local/Sluice/Connect/lib/GoogleAnalytics/Visitor.php +463 -0
  27. app/etc/modules/Sluice_Connect.xml +9 -0
  28. package.xml +19 -0
app/code/local/Sluice/Connect/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sluice_Connect_Helper_Data extends Mage_Core_Helper_Abstract{
4
+ }
5
+
6
+ ?>
app/code/local/Sluice/Connect/Model/Observer.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use UnitedPrototype\GoogleAnalytics;
4
+
5
+ class Sluice_Connect_Model_Observer {
6
+
7
+ // Add to cartd trecking
8
+ public function hookToAddToCart($observer) {
9
+ if (!Mage::helper('googleanalytics')->isGoogleAnalyticsAvailable()) {
10
+ Mage::log("Google analytics doesn't install", 3, $errorLog);
11
+ return;
12
+ }
13
+ $accountId = Mage::getStoreConfig(Mage_GoogleAnalytics_Helper_Data::XML_PATH_ACCOUNT);
14
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
15
+ if (empty($baseUrl)) {
16
+ Mage::log("Base url is empty", 3, $errorLog);
17
+ return;
18
+ }
19
+
20
+ $tracker = new GoogleAnalytics\Tracker($accountId, $baseUrl);
21
+ $event = new GoogleAnalytics\Event("Cart", "Add", "Product");
22
+ $tracker->trackEvent($event, null, null);
23
+ }
24
+
25
+ //config save hook
26
+ public function hookSavePluginConfig($observer) {
27
+ $errorLog = 'sluice_error.log';
28
+ $sluiceEmail = 'knight@sluicehq.com';
29
+ $sluiceApiUrl = 'http://sluicehq.com/api/v.php?version=2&method=SetMagentoApi';
30
+ $userName = 'sluice-connect';
31
+ $roleName = 'sluice-connect-role';
32
+
33
+ $token = Mage::getStoreConfig('sluice_section/sluice_group/sluice_field', Mage::app()->getStore());
34
+ if (empty($token)) {
35
+ Mage::log("Empty token", 3, $errorLog);
36
+ Mage::getSingleton('core/session')->addError("Empty token");
37
+ return;
38
+ }
39
+
40
+ if (strlen(trim($token)) != 32) {
41
+ Mage::log("Whrong token", 3, $errorLog);
42
+ Mage::getSingleton('core/session')->addError("Whrong token");
43
+ return;
44
+ }
45
+
46
+ try {
47
+ $user = Mage::getModel('api/user')->setUsername($userName)->loadByUsername();
48
+ if (!$user->userExists()) {
49
+ $role = Mage::getModel("api/roles")->setName($roleName)->setRoleType('G')->save();
50
+ Mage::getModel("api/rules")->setRoleId($role->getId())->setResources(array("all"))->saveRel();
51
+
52
+ $apiKey = md5(uniqid(rand(), true));
53
+ $user = Mage::getModel('api/user');
54
+ $user->setData(array(
55
+ 'username' => $userName,
56
+ 'firstname' => $userName,
57
+ 'lastname' => $userName,
58
+ 'email' => $sluiceEmail,
59
+ 'api_key' => $apiKey,
60
+ 'api_key_confirmation' => $apiKey,
61
+ 'is_active' => 1,
62
+ 'user_roles' => '',
63
+ 'assigned_user_role' => '',
64
+ 'role_name' => '',
65
+ 'roles' => array($role->getId())
66
+ ));
67
+ $user->save()->load($user->getId());
68
+ $user->setRoleIds(array($role->getId()))->setRoleUserId($user->getUserId())->saveRelations();
69
+ }
70
+ $apiKey = $user->getApiKey();
71
+ } catch (Exception $ex) {
72
+ Mage::log("User/Role saving error" . $ex->getMessage(), 3, $errorLog);
73
+ Mage::getSingleton('core/session')->addError("User/Role saving error");
74
+ return;
75
+ }
76
+
77
+ try {
78
+ $data = $arrayName = array(
79
+ 'username' => $userName,
80
+ 'apiKey' => $apiKey,
81
+ 'token' => trim($token));
82
+ $sluiceApiUrl = $sluiceApiUrl . '&' . http_build_query($data);
83
+ file_get_contents($sluiceApiUrl);
84
+ } catch (Exception $ex) {
85
+ Mage::log("Error is request to sluice " . $ex->getMessage(), 3, $errorLog);
86
+ Mage::getSingleton('core/session')->addError("Error is request to sluice " . $ex->getMessage());
87
+ return;
88
+ }
89
+ }
90
+ }
91
+ ?>
app/code/local/Sluice/Connect/etc/config.xml ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <sluice_connect>
5
+ <version>0.1.0</version>
6
+ </sluice_connect>
7
+ </modules>
8
+
9
+ <global>
10
+ <models>
11
+ <sluice_connect>
12
+ <class>Sluice_Connect_Model</class>
13
+ </sluice_connect>
14
+ </models>
15
+
16
+ <helpers>
17
+ <sluice_connect>
18
+ <class>Sluice_Connect_Helper</class>
19
+ </sluice_connect>
20
+ </helpers>
21
+
22
+ <events>
23
+ <admin_system_config_changed_section_sluice_section>
24
+ <observers>
25
+ <config_change_ob>
26
+ <type>singleton</type>
27
+ <class>Sluice_Connect_Model_Observer</class>
28
+ <method>hookSavePluginConfig</method>
29
+ </config_change_ob>
30
+ </observers>
31
+ </admin_system_config_changed_section_sluice_section>
32
+ </events>
33
+ </global>
34
+
35
+ <frontend>
36
+ <events>
37
+ <!-- Hooking to our own event "checkout_cart_product_add_after" -->
38
+ <checkout_cart_product_add_after>
39
+ <observers>
40
+ <Sluice_Connect_Model_Observer>
41
+ <type>singleton</type>
42
+ <class>Sluice_Connect_Model_Observer</class>
43
+ <method>hookToAddToCart</method>
44
+ </Sluice_Connect_Model_Observer>
45
+ </observers>
46
+ </checkout_cart_product_add_after>
47
+
48
+ <admin_system_config_changed_section_sluice_section>
49
+ <observers>
50
+ <config_change_ob>
51
+ <type>singleton</type>
52
+ <class>Sluice_Connect_Model_Observer</class>
53
+ <method>hookSavePluginConfig</method>
54
+ </config_change_ob>
55
+ </observers>
56
+ </admin_system_config_changed_section_sluice_section>
57
+ </events>
58
+ </frontend>
59
+
60
+ <adminhtml>
61
+ <acl>
62
+ <resources>
63
+ <all>
64
+ <title>Allow Everything</title>
65
+ </all>
66
+ <admin>
67
+ <children>
68
+ <system>
69
+ <children>
70
+ <config>
71
+ <children>
72
+ <sluice_section translate="title" module="sluice_connect">
73
+ <title>My Section</title>
74
+ </sluice_section>
75
+ </children>
76
+ </config>
77
+ </children>
78
+ </system>
79
+ </children>
80
+ </admin>
81
+ </resources>
82
+ </acl>
83
+ </adminhtml>
84
+ </config>
app/code/local/Sluice/Connect/etc/system.xml ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" ?>
2
+ <config>
3
+ <tabs>
4
+ <sluice_tab module="sluice_connect" translate="label">
5
+ <label>Sluice Connect</label>
6
+ <sort_order>100</sort_order>
7
+ </sluice_tab>
8
+ </tabs>
9
+
10
+ <sections>
11
+ <sluice_section module="sluice_connect" translate="label">
12
+ <label>Settings</label>
13
+ <sort_order>200</sort_order>
14
+ <show_in_default>1</show_in_default>
15
+ <show_in_website>1</show_in_website>
16
+ <show_in_store>1</show_in_store>
17
+ <tab>sluice_tab</tab>
18
+ <groups>
19
+ <sluice_group translate="label">
20
+ <label>Token Settings</label>
21
+ <sort_order>10</sort_order>
22
+ <show_in_default>1</show_in_default>
23
+ <show_in_website>1</show_in_website>
24
+ <show_in_store>1</show_in_store>
25
+ <fields>
26
+ <sluice_field translate="label">
27
+ <label>Token:</label>
28
+ <comment>Token from sluice</comment>
29
+ <show_in_default>1</show_in_default>
30
+ <show_in_website>1</show_in_website>
31
+ <show_in_store>1</show_in_store>
32
+ <frontend_type>text</frontend_type>
33
+ </sluice_field>
34
+ </fields>
35
+ </sluice_group>
36
+ </groups>
37
+ </sluice_section>
38
+ </sections>
39
+
40
+
41
+ </config>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/Campaign.php ADDED
@@ -0,0 +1,378 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics;
30
+
31
+ use UnitedPrototype\GoogleAnalytics\Internals\Util;
32
+
33
+ use DateTime;
34
+
35
+ /**
36
+ * You should serialize this object and store it in e.g. the user database to keep it
37
+ * persistent for the same user permanently (similar to the "__umtz" cookie of
38
+ * the GA Javascript client).
39
+ */
40
+ class Campaign {
41
+
42
+ /**
43
+ * See self::TYPE_* constants, will be mapped to "__utmz" parameter.
44
+ *
45
+ * @see Internals\ParameterHolder::$__utmz
46
+ * @var string
47
+ */
48
+ protected $type;
49
+
50
+ /**
51
+ * Time of the creation of this campaign, will be mapped to "__utmz" parameter.
52
+ *
53
+ * @see Internals\ParameterHolder::$__utmz
54
+ * @var DateTime
55
+ */
56
+ protected $creationTime;
57
+
58
+ /**
59
+ * Response Count, will be mapped to "__utmz" parameter.
60
+ *
61
+ * Is also used to determine whether the campaign is new or repeated,
62
+ * which will be mapped to "utmcn" and "utmcr" parameters.
63
+ *
64
+ * @see Internals\ParameterHolder::$__utmz
65
+ * @see Internals\ParameterHolder::$utmcn
66
+ * @see Internals\ParameterHolder::$utmcr
67
+ * @var int
68
+ */
69
+ protected $responseCount = 0;
70
+
71
+ /**
72
+ * Campaign ID, a.k.a. "utm_id" query parameter for ga.js
73
+ * Will be mapped to "__utmz" parameter.
74
+ *
75
+ * @see Internals\ParameterHolder::$__utmz
76
+ * @var int
77
+ */
78
+ protected $id;
79
+
80
+ /**
81
+ * Source, a.k.a. "utm_source" query parameter for ga.js.
82
+ * Will be mapped to "utmcsr" key in "__utmz" parameter.
83
+ *
84
+ * @see Internals\ParameterHolder::$__utmz
85
+ * @var string
86
+ */
87
+ protected $source;
88
+
89
+ /**
90
+ * Google AdWords Click ID, a.k.a. "gclid" query parameter for ga.js.
91
+ * Will be mapped to "utmgclid" key in "__utmz" parameter.
92
+ *
93
+ * @see Internals\ParameterHolder::$__utmz
94
+ * @var string
95
+ */
96
+ protected $gClickId;
97
+
98
+ /**
99
+ * DoubleClick (?) Click ID. Will be mapped to "utmdclid" key in "__utmz" parameter.
100
+ *
101
+ * @see Internals\ParameterHolder::$__utmz
102
+ * @var string
103
+ */
104
+ protected $dClickId;
105
+
106
+ /**
107
+ * Name, a.k.a. "utm_campaign" query parameter for ga.js.
108
+ * Will be mapped to "utmccn" key in "__utmz" parameter.
109
+ *
110
+ * @see Internals\ParameterHolder::$__utmz
111
+ * @var string
112
+ */
113
+ protected $name;
114
+
115
+ /**
116
+ * Medium, a.k.a. "utm_medium" query parameter for ga.js.
117
+ * Will be mapped to "utmcmd" key in "__utmz" parameter.
118
+ *
119
+ * @see Internals\ParameterHolder::$__utmz
120
+ * @var string
121
+ */
122
+ protected $medium;
123
+
124
+ /**
125
+ * Terms/Keywords, a.k.a. "utm_term" query parameter for ga.js.
126
+ * Will be mapped to "utmctr" key in "__utmz" parameter.
127
+ *
128
+ * @see Internals\ParameterHolder::$__utmz
129
+ * @var string
130
+ */
131
+ protected $term;
132
+
133
+ /**
134
+ * Ad Content Description, a.k.a. "utm_content" query parameter for ga.js.
135
+ * Will be mapped to "utmcct" key in "__utmz" parameter.
136
+ *
137
+ * @see Internals\ParameterHolder::$__utmz
138
+ * @var string
139
+ */
140
+ protected $content;
141
+
142
+
143
+ /**
144
+ * @const string
145
+ */
146
+ const TYPE_DIRECT = 'direct';
147
+ /**
148
+ * @const string
149
+ */
150
+ const TYPE_ORGANIC = 'organic';
151
+ /**
152
+ * @const string
153
+ */
154
+ const TYPE_REFERRAL = 'referral';
155
+
156
+
157
+ /**
158
+ * @see createFromReferrer
159
+ * @param string $type See TYPE_* constants
160
+ */
161
+ public function __construct($type) {
162
+ if(!in_array($type, array(self::TYPE_DIRECT, self::TYPE_ORGANIC, self::TYPE_REFERRAL))) {
163
+ Tracker::_raiseError('Campaign type has to be one of the Campaign::TYPE_* constant values.', __METHOD__);
164
+ }
165
+
166
+ $this->type = $type;
167
+
168
+ switch($type) {
169
+ // See http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/campaign/CampaignManager.as#375
170
+ case self::TYPE_DIRECT:
171
+ $this->name = '(direct)';
172
+ $this->source = '(direct)';
173
+ $this->medium = '(none)';
174
+ break;
175
+ // See http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/campaign/CampaignManager.as#340
176
+ case self::TYPE_REFERRAL:
177
+ $this->name = '(referral)';
178
+ $this->medium = 'referral';
179
+ break;
180
+ // See http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/campaign/CampaignManager.as#280
181
+ case self::TYPE_ORGANIC:
182
+ $this->name = '(organic)';
183
+ $this->medium = 'organic';
184
+ break;
185
+ }
186
+
187
+ $this->creationTime = new DateTime();
188
+ }
189
+
190
+ /**
191
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/campaign/CampaignManager.as#333
192
+ * @param string $url
193
+ * @return \UnitedPrototype\GoogleAnalytics\Campaign
194
+ */
195
+ public static function createFromReferrer($url) {
196
+ $instance = new static(self::TYPE_REFERRAL);
197
+ $urlInfo = parse_url($url);
198
+ $instance->source = $urlInfo['host'];
199
+ $instance->content = $urlInfo['path'];
200
+
201
+ return $instance;
202
+ }
203
+
204
+ /**
205
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/campaign/CampaignTracker.as#153
206
+ */
207
+ public function validate() {
208
+ // NOTE: gaforflash states that id and gClickId must also be specified,
209
+ // but that doesn't seem to be correct
210
+ if(!$this->source) {
211
+ Tracker::_raiseError('Campaigns need to have at least the "source" attribute defined.', __METHOD__);
212
+ }
213
+ }
214
+
215
+ /**
216
+ * @param string $type
217
+ */
218
+ public function setType($type) {
219
+ $this->type = $type;
220
+ }
221
+
222
+ /**
223
+ * @return string
224
+ */
225
+ public function getType() {
226
+ return $this->type;
227
+ }
228
+
229
+ /**
230
+ * @param DateTime $creationTime
231
+ */
232
+ public function setCreationTime(DateTime $creationTime) {
233
+ $this->creationTime = $creationTime;
234
+ }
235
+
236
+ /**
237
+ * @return DateTime
238
+ */
239
+ public function getCreationTime() {
240
+ return $this->creationTime;
241
+ }
242
+
243
+ /**
244
+ * @param int $esponseCount
245
+ */
246
+ public function setResponseCount($responseCount) {
247
+ $this->responseCount = (int)$responseCount;
248
+ }
249
+
250
+ /**
251
+ * @return int
252
+ */
253
+ public function getResponseCount() {
254
+ return $this->responseCount;
255
+ }
256
+
257
+ /**
258
+ * @param int $byAmount
259
+ */
260
+ public function increaseResponseCount($byAmount = 1) {
261
+ $this->responseCount += $byAmount;
262
+ }
263
+
264
+ /**
265
+ * @param int $id
266
+ */
267
+ public function setId($id) {
268
+ $this->id = $id;
269
+ }
270
+
271
+ /**
272
+ * @return int
273
+ */
274
+ public function getId() {
275
+ return $this->id;
276
+ }
277
+
278
+ /**
279
+ * @param string $source
280
+ */
281
+ public function setSource($source) {
282
+ $this->source = $source;
283
+ }
284
+
285
+ /**
286
+ * @return string
287
+ */
288
+ public function getSource() {
289
+ return $this->source;
290
+ }
291
+
292
+ /**
293
+ * @param string $gClickId
294
+ */
295
+ public function setGClickId($gClickId) {
296
+ $this->gClickId = $gClickId;
297
+ }
298
+
299
+ /**
300
+ * @return string
301
+ */
302
+ public function getGClickId() {
303
+ return $this->gClickId;
304
+ }
305
+
306
+ /**
307
+ * @param string $dClickId
308
+ */
309
+ public function setDClickId($dClickId) {
310
+ $this->dClickId = $dClickId;
311
+ }
312
+
313
+ /**
314
+ * @return string
315
+ */
316
+ public function getDClickId() {
317
+ return $this->dClickId;
318
+ }
319
+
320
+ /**
321
+ * @param string $name
322
+ */
323
+ public function setName($name) {
324
+ $this->name = $name;
325
+ }
326
+
327
+ /**
328
+ * @return string
329
+ */
330
+ public function getName() {
331
+ return $this->name;
332
+ }
333
+
334
+ /**
335
+ * @param string $medium
336
+ */
337
+ public function setMedium($medium) {
338
+ $this->medium = $medium;
339
+ }
340
+
341
+ /**
342
+ * @return string
343
+ */
344
+ public function getMedium() {
345
+ return $this->medium;
346
+ }
347
+
348
+ /**
349
+ * @param string $term
350
+ */
351
+ public function setTerm($term) {
352
+ $this->term = $term;
353
+ }
354
+
355
+ /**
356
+ * @return string
357
+ */
358
+ public function getTerm() {
359
+ return $this->term;
360
+ }
361
+
362
+ /**
363
+ * @param string $content
364
+ */
365
+ public function setContent($content) {
366
+ $this->content = $content;
367
+ }
368
+
369
+ /**
370
+ * @return string
371
+ */
372
+ public function getContent() {
373
+ return $this->content;
374
+ }
375
+
376
+ }
377
+
378
+ ?>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/Config.php ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics;
30
+
31
+ /**
32
+ * Note: Doesn't necessarily have to be consistent across requests, as it doesn't
33
+ * alter the actual tracking result.
34
+ *
35
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/core/GIFRequest.as
36
+ */
37
+ class Config {
38
+
39
+ /**
40
+ * How strict should errors get handled? After all, we do just do some
41
+ * tracking stuff here, and errors shouldn't break an application's
42
+ * functionality in production.
43
+ * RECOMMENDATION: Exceptions during deveopment, warnings in production.
44
+ *
45
+ * Assign any value of the self::ERROR_SEVERITY_* constants.
46
+ *
47
+ * @see Tracker::_raiseError()
48
+ * @var int
49
+ */
50
+ protected $errorSeverity = self::ERROR_SEVERITY_EXCEPTIONS;
51
+
52
+ /**
53
+ * Ignore all errors completely.
54
+ */
55
+ const ERROR_SEVERITY_SILENCE = 0;
56
+ /**
57
+ * Trigger PHP errors with a E_USER_WARNING error level.
58
+ */
59
+ const ERROR_SEVERITY_WARNINGS = 1;
60
+ /**
61
+ * Throw UnitedPrototype\GoogleAnalytics\Exception exceptions.
62
+ */
63
+ const ERROR_SEVERITY_EXCEPTIONS = 2;
64
+
65
+ /**
66
+ * Whether to just queue all requests on HttpRequest::fire() and actually send
67
+ * them on PHP script shutdown after all other tasks are done.
68
+ *
69
+ * This has two advantages:
70
+ * 1) It effectively doesn't affect app performance
71
+ * 2) It can e.g. handle custom variables that were set after scheduling a request
72
+ *
73
+ * @see Internals\Request\HttpRequest::fire()
74
+ * @var bool
75
+ */
76
+ protected $sendOnShutdown = false;
77
+
78
+ /**
79
+ * Whether to make asynchronous requests to GA without waiting for any
80
+ * response (speeds up doing requests).
81
+ *
82
+ * @see Internals\Request\HttpRequest::send()
83
+ * @var bool
84
+ */
85
+ protected $fireAndForget = false;
86
+
87
+ /**
88
+ * Logging callback, registered via setLoggingCallback(). Will be fired
89
+ * whenever a request gets sent out and receives the full HTTP request
90
+ * as the first and the full HTTP response (or null if the "fireAndForget"
91
+ * option or simulation mode are used) as the second argument.
92
+ *
93
+ * @var \Closure
94
+ */
95
+ protected $loggingCallback;
96
+
97
+ /**
98
+ * Seconds (float allowed) to wait until timeout when connecting to the
99
+ * Google analytics endpoint host
100
+ *
101
+ * @see Internals\Request\HttpRequest::send()
102
+ * @var float
103
+ */
104
+ protected $requestTimeout = 1;
105
+
106
+ // FIXME: Add SSL support, https://ssl.google-analytics.com
107
+
108
+ /**
109
+ * Google Analytics tracking request endpoint host. Can be set to null to
110
+ * silently simulate (and log) requests without actually sending them.
111
+ *
112
+ * @see Internals\Request\HttpRequest::send()
113
+ * @var string
114
+ */
115
+ protected $endPointHost = 'www.google-analytics.com';
116
+
117
+ /**
118
+ * Google Analytics tracking request endpoint path
119
+ *
120
+ * @see Internals\Request\HttpRequest::send()
121
+ * @var string
122
+ */
123
+ protected $endPointPath = '/__utm.gif';
124
+
125
+ /**
126
+ * Whether to anonymize IP addresses within Google Analytics by stripping
127
+ * the last IP address block, will be mapped to "aip" parameter
128
+ *
129
+ * @see Internals\ParameterHolder::$aip
130
+ * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApi_gat.html#_gat._anonymizeIp
131
+ * @var bool
132
+ */
133
+ protected $anonymizeIpAddresses = false;
134
+
135
+ /**
136
+ * Defines a new sample set size (0-100) for Site Speed data collection.
137
+ * By default, a fixed 1% sampling of your site visitors make up the data pool from which
138
+ * the Site Speed metrics are derived.
139
+ *
140
+ * @see Page::$loadTime
141
+ * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html#_gat.GA_Tracker_._setSiteSpeedSampleRate
142
+ * @var int
143
+ */
144
+ protected $sitespeedSampleRate = 1;
145
+
146
+
147
+ /**
148
+ * @param array $properties
149
+ */
150
+ public function __construct(array $properties = array()) {
151
+ foreach($properties as $property => $value) {
152
+ // PHP doesn't care about case in method names
153
+ $setterMethod = 'set' . $property;
154
+
155
+ if(method_exists($this, $setterMethod)) {
156
+ $this->$setterMethod($value);
157
+ } else {
158
+ return Tracker::_raiseError('There is no setting "' . $property . '".', __METHOD__);
159
+ }
160
+ }
161
+ }
162
+
163
+ /**
164
+ * @return int See self::ERROR_SEVERITY_* constants
165
+ */
166
+ public function getErrorSeverity() {
167
+ return $this->errorSeverity;
168
+ }
169
+
170
+ /**
171
+ * @param int $errorSeverity See self::ERROR_SEVERITY_* constants
172
+ */
173
+ public function setErrorSeverity($errorSeverity) {
174
+ $this->errorSeverity = $errorSeverity;
175
+ }
176
+
177
+ /**
178
+ * @return bool
179
+ */
180
+ public function getSendOnShutdown() {
181
+ return $this->sendOnShutdown;
182
+ }
183
+
184
+ /**
185
+ * @param bool $sendOnShutdown
186
+ */
187
+ public function setSendOnShutdown($sendOnShutdown) {
188
+ $this->sendOnShutdown = $sendOnShutdown;
189
+ }
190
+
191
+ /**
192
+ * @return bool
193
+ */
194
+ public function getFireAndForget() {
195
+ return $this->fireAndForget;
196
+ }
197
+
198
+ /**
199
+ * @param bool $fireAndForget
200
+ */
201
+ public function setFireAndForget($fireAndForget) {
202
+ $this->fireAndForget = (bool)$fireAndForget;
203
+ }
204
+
205
+ /**
206
+ * @return \Closure|null
207
+ */
208
+ public function getLoggingCallback() {
209
+ return $this->loggingCallback;
210
+ }
211
+
212
+ /**
213
+ * @param \Closure $callback
214
+ */
215
+ public function setLoggingCallback(\Closure $callback) {
216
+ $this->loggingCallback = $callback;
217
+ }
218
+
219
+ /**
220
+ * @return float
221
+ */
222
+ public function getRequestTimeout() {
223
+ return $this->requestTimeout;
224
+ }
225
+
226
+ /**
227
+ * @param float $requestTimeout
228
+ */
229
+ public function setRequestTimeout($requestTimeout) {
230
+ $this->requestTimeout = (float)$requestTimeout;
231
+ }
232
+
233
+ /**
234
+ * @return string|null
235
+ */
236
+ public function getEndPointHost() {
237
+ return $this->endPointHost;
238
+ }
239
+
240
+ /**
241
+ * @param string|null $endPointHost
242
+ */
243
+ public function setEndPointHost($endPointHost) {
244
+ $this->endPointHost = $endPointHost;
245
+ }
246
+
247
+ /**
248
+ * @return string
249
+ */
250
+ public function getEndPointPath() {
251
+ return $this->endPointPath;
252
+ }
253
+
254
+ /**
255
+ * @param string $endPointPath
256
+ */
257
+ public function setEndPointPath($endPointPath) {
258
+ $this->endPointPath = $endPointPath;
259
+ }
260
+
261
+ /**
262
+ * @return bool
263
+ */
264
+ public function getAnonymizeIpAddresses() {
265
+ return $this->anonymizeIpAddresses;
266
+ }
267
+
268
+ /**
269
+ * @param bool $anonymizeIpAddresses
270
+ */
271
+ public function setAnonymizeIpAddresses($anonymizeIpAddresses) {
272
+ $this->anonymizeIpAddresses = $anonymizeIpAddresses;
273
+ }
274
+
275
+ /**
276
+ * @return int
277
+ */
278
+ public function getSitespeedSampleRate() {
279
+ return $this->sitespeedSampleRate;
280
+ }
281
+
282
+ /**
283
+ * @param int $sitespeedSampleRate
284
+ */
285
+ public function setSitespeedSampleRate($sitespeedSampleRate) {
286
+ if((int)$sitespeedSampleRate != (float)$sitespeedSampleRate || $sitespeedSampleRate < 0 || $sitespeedSampleRate > 100) {
287
+ return Tracker::_raiseError('For consistency with ga.js, sample rates must be specified as a number between 0 and 100.', __METHOD__);
288
+ }
289
+
290
+ $this->sitespeedSampleRate = (int)$sitespeedSampleRate;
291
+ }
292
+
293
+ }
294
+
295
+ ?>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/CustomVariable.php ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics;
30
+
31
+ use UnitedPrototype\GoogleAnalytics\Internals\Util;
32
+
33
+ /**
34
+ * @link http://code.google.com/apis/analytics/docs/tracking/gaTrackingCustomVariables.html
35
+ */
36
+ class CustomVariable {
37
+
38
+ /**
39
+ * @var int
40
+ */
41
+ protected $index;
42
+
43
+ /**
44
+ * WATCH OUT: It's a known issue that GA will not decode URL-encoded characters
45
+ * in custom variable names and values properly, so spaces will show up
46
+ * as "%20" in the interface etc.
47
+ *
48
+ * @link http://www.google.com/support/forum/p/Google%20Analytics/thread?tid=2cdb3ec0be32e078
49
+ * @var string
50
+ */
51
+ protected $name;
52
+
53
+ /**
54
+ * WATCH OUT: It's a known issue that GA will not decode URL-encoded characters
55
+ * in custom variable names and values properly, so spaces will show up
56
+ * as "%20" in the interface etc.
57
+ *
58
+ * @link http://www.google.com/support/forum/p/Google%20Analytics/thread?tid=2cdb3ec0be32e078
59
+ * @var mixed
60
+ */
61
+ protected $value;
62
+
63
+ /**
64
+ * See SCOPE_* constants
65
+ *
66
+ * @var int
67
+ */
68
+ protected $scope = self::SCOPE_PAGE;
69
+
70
+
71
+ /**
72
+ * @const int
73
+ */
74
+ const SCOPE_VISITOR = 1;
75
+ /**
76
+ * @const int
77
+ */
78
+ const SCOPE_SESSION = 2;
79
+ /**
80
+ * @const int
81
+ */
82
+ const SCOPE_PAGE = 3;
83
+
84
+
85
+ /**
86
+ * @param int $index
87
+ * @param string $name
88
+ * @param mixed $value
89
+ * @param int $scope See SCOPE_* constants
90
+ */
91
+ public function __construct($index = null, $name = null, $value = null, $scope = null) {
92
+ if($index !== null) $this->setIndex($index);
93
+ if($name !== null) $this->setName($name);
94
+ if($value !== null) $this->setValue($value);
95
+ if($scope !== null) $this->setScope($scope);
96
+ }
97
+
98
+ public function validate() {
99
+ // According to the GA documentation, there is a limit to the combined size of
100
+ // name and value of 64 bytes after URL encoding,
101
+ // see http://code.google.com/apis/analytics/docs/tracking/gaTrackingCustomVariables.html#varTypes
102
+ // and http://xahlee.org/js/google_analytics_tracker_2010-07-01_expanded.js line 563
103
+ // This limit was increased to 128 bytes BEFORE encoding with the 2012-01 release of ga.js however,
104
+ // see http://code.google.com/apis/analytics/community/gajs_changelog.html
105
+ if(strlen($this->name . $this->value) > 128) {
106
+ Tracker::_raiseError('Custom Variable combined name and value length must not be larger than 128 bytes.', __METHOD__);
107
+ }
108
+ }
109
+
110
+ /**
111
+ * @return int
112
+ */
113
+ public function getIndex() {
114
+ return $this->index;
115
+ }
116
+
117
+ /**
118
+ * @link http://code.google.com/intl/de-DE/apis/analytics/docs/tracking/gaTrackingCustomVariables.html#usage
119
+ * @param int $index
120
+ */
121
+ public function setIndex($index) {
122
+ // Custom Variables are limited to five slots officially, but there seems to be a
123
+ // trick to allow for more of them which we could investigate at a later time (see
124
+ // http://analyticsimpact.com/2010/05/24/get-more-than-5-custom-variables-in-google-analytics/)
125
+ if($index < 1 || $index > 5) {
126
+ Tracker::_raiseError('Custom Variable index has to be between 1 and 5.', __METHOD__);
127
+ }
128
+
129
+ $this->index = (int)$index;
130
+ }
131
+
132
+ /**
133
+ * @return string
134
+ */
135
+ public function getName() {
136
+ return $this->name;
137
+ }
138
+
139
+ /**
140
+ * @param string $name
141
+ */
142
+ public function setName($name) {
143
+ $this->name = $name;
144
+ }
145
+
146
+ /**
147
+ * @return mixed
148
+ */
149
+ public function getValue() {
150
+ return $this->value;
151
+ }
152
+
153
+ /**
154
+ * @param mixed $value
155
+ */
156
+ public function setValue($value) {
157
+ $this->value = $value;
158
+ }
159
+
160
+ /**
161
+ * @return int
162
+ */
163
+ public function getScope() {
164
+ return $this->scope;
165
+ }
166
+
167
+ /**
168
+ * @param int $scope
169
+ */
170
+ public function setScope($scope) {
171
+ if(!in_array($scope, array(self::SCOPE_PAGE, self::SCOPE_SESSION, self::SCOPE_VISITOR))) {
172
+ Tracker::_raiseError('Custom Variable scope has to be one of the CustomVariable::SCOPE_* constant values.', __METHOD__);
173
+ }
174
+
175
+ $this->scope = (int)$scope;
176
+ }
177
+
178
+ }
179
+
180
+ ?>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/Event.php ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics;
30
+
31
+ /**
32
+ * @link http://code.google.com/apis/analytics/docs/tracking/eventTrackerOverview.html
33
+ * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEventTracking.html
34
+ */
35
+ class Event {
36
+
37
+ /**
38
+ * The general event category (e.g. "Videos").
39
+ *
40
+ * @var string
41
+ */
42
+ protected $category;
43
+
44
+ /**
45
+ * The action for the event (e.g. "Play").
46
+ *
47
+ * @var string
48
+ */
49
+ protected $action;
50
+
51
+ /**
52
+ * An optional descriptor for the event (e.g. the video's title).
53
+ *
54
+ * @var string
55
+ */
56
+ protected $label;
57
+
58
+ /**
59
+ * An optional value associated with the event. You can see your event values in the Overview,
60
+ * Categories, and Actions reports, where they are listed by event or aggregated across events,
61
+ * depending upon your report view.
62
+ *
63
+ * @var int
64
+ */
65
+ protected $value;
66
+
67
+ /**
68
+ * Default value is false. By default, event hits will impact a visitor's bounce rate.
69
+ * By setting this parameter to true, this event hit will not be used in bounce rate calculations.
70
+ *
71
+ * @var bool
72
+ */
73
+ protected $noninteraction = false;
74
+
75
+
76
+ /**
77
+ * @param string $category
78
+ * @param string $action
79
+ * @param string $label
80
+ * @param int $value
81
+ * @param bool $noninteraction
82
+ */
83
+ public function __construct($category = null, $action = null, $label = null, $value = null, $noninteraction = null) {
84
+ if($category !== null) $this->setCategory($category);
85
+ if($action !== null) $this->setAction($action);
86
+ if($label !== null) $this->setLabel($label);
87
+ if($value !== null) $this->setValue($value);
88
+ if($noninteraction !== null) $this->setNoninteraction($noninteraction);
89
+ }
90
+
91
+ public function validate() {
92
+ if($this->category === null || $this->action === null) {
93
+ Tracker::_raiseError('Events need at least to have a category and action defined.', __METHOD__);
94
+ }
95
+ }
96
+
97
+ /**
98
+ * @return string
99
+ */
100
+ public function getCategory() {
101
+ return $this->category;
102
+ }
103
+
104
+ /**
105
+ * @param string $category
106
+ */
107
+ public function setCategory($category) {
108
+ $this->category = $category;
109
+ }
110
+
111
+ /**
112
+ * @return string
113
+ */
114
+ public function getAction() {
115
+ return $this->action;
116
+ }
117
+
118
+ /**
119
+ * @param string $action
120
+ */
121
+ public function setAction($action) {
122
+ $this->action = $action;
123
+ }
124
+
125
+ /**
126
+ * @return string
127
+ */
128
+ public function getLabel() {
129
+ return $this->label;
130
+ }
131
+
132
+ /**
133
+ * @param string $label
134
+ */
135
+ public function setLabel($label) {
136
+ $this->label = $label;
137
+ }
138
+
139
+ /**
140
+ * @return int
141
+ */
142
+ public function getValue() {
143
+ return $this->value;
144
+ }
145
+
146
+ /**
147
+ * @param int $value
148
+ */
149
+ public function setValue($value) {
150
+ $this->value = (int)$value;
151
+ }
152
+
153
+ /**
154
+ * @return bool
155
+ */
156
+ public function getNoninteraction() {
157
+ return $this->noninteraction;
158
+ }
159
+
160
+ /**
161
+ * @param bool $value
162
+ */
163
+ public function setNoninteraction($value) {
164
+ $this->noninteraction = (bool)$value;
165
+ }
166
+
167
+ }
168
+
169
+ ?>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/Exception.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics;
30
+
31
+ /**
32
+ * @see Config::$errorSeverity
33
+ * @see Tracker::_raiseError()
34
+ */
35
+ class Exception extends \Exception {
36
+
37
+ }
38
+
39
+ ?>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/Internals/ParameterHolder.php ADDED
@@ -0,0 +1,536 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics\Internals;
30
+
31
+ use UnitedPrototype\GoogleAnalytics\Tracker;
32
+
33
+ /**
34
+ * This simple class is mainly meant to be a well-documented overview of all
35
+ * possible GA tracking parameters.
36
+ *
37
+ * @link http://code.google.com/apis/analytics/docs/tracking/gaTrackingTroubleshooting.html#gifParameters
38
+ */
39
+ class ParameterHolder {
40
+
41
+ // - - - - - - - - - - - - - - - - - General parameters - - - - - - - - - - - - - - - - -
42
+
43
+ /**
44
+ * Google Analytics client version, e.g. "4.7.2"
45
+ * @var string
46
+ */
47
+ public $utmwv = Tracker::VERSION;
48
+
49
+ /**
50
+ * Google Analytics account ID, e.g. "UA-1234567-8"
51
+ * @var string
52
+ */
53
+ public $utmac;
54
+
55
+ /**
56
+ * Host Name, e.g. "www.example.com"
57
+ * @var string
58
+ */
59
+ public $utmhn;
60
+
61
+ /**
62
+ * Indicates the type of request, which is one of null (for page), "event",
63
+ * "tran", "item", "social", "var" (deprecated) or "error" (used by ga.js
64
+ * for internal client error logging).
65
+ * @var string
66
+ */
67
+ public $utmt;
68
+
69
+ /**
70
+ * Contains the amount of requests done in this session. Added in ga.js v4.9.2.
71
+ * @var int
72
+ */
73
+ public $utms;
74
+
75
+ /**
76
+ * Unique ID (random number) generated for each GIF request
77
+ * @var int
78
+ */
79
+ public $utmn;
80
+
81
+ /**
82
+ * Contains all cookie values, see below
83
+ * @var string
84
+ */
85
+ public $utmcc;
86
+
87
+ /**
88
+ * Extensible Parameter, used for events and custom variables
89
+ * @var string
90
+ */
91
+ public $utme;
92
+
93
+ /**
94
+ * Event "non-interaction" parameter. By default, the event hit will impact a visitor's bounce rate.
95
+ * By setting this parameter to 1, this event hit will not be used in bounce rate calculations.
96
+ * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEventTracking.html
97
+ * @var int
98
+ */
99
+ public $utmni;
100
+
101
+ /**
102
+ * Whether to anonymize IP addresses within Google Analytics by stripping
103
+ * the last IP address block, either null or 1
104
+ * @var int
105
+ */
106
+ public $aip;
107
+
108
+ /**
109
+ * Used for GA-internal statistical client function usage and error tracking,
110
+ * not implemented in php-ga as of now, but here for documentation completeness.
111
+ * @link http://glucik.blogspot.com/2011/02/utmu-google-analytics-request-parameter.html
112
+ * @var string
113
+ */
114
+ public $utmu;
115
+
116
+
117
+ // - - - - - - - - - - - - - - - - - Page parameters - - - - - - - - - - - - - - - - -
118
+
119
+ /**
120
+ * Page request URI, e.g. "/path/page.html"
121
+ * @var string
122
+ */
123
+ public $utmp;
124
+
125
+ /**
126
+ * Page title
127
+ * @var string
128
+ */
129
+ public $utmdt;
130
+
131
+ /**
132
+ * Charset encoding (e.g. "UTF-8") or "-" as default
133
+ * @var string
134
+ */
135
+ public $utmcs = '-';
136
+
137
+ /**
138
+ * Referer URL, e.g. "http://www.example.com/path/page.html", "-" as default
139
+ * or "0" for internal referers
140
+ * @var string
141
+ */
142
+ public $utmr = '-';
143
+
144
+
145
+ // - - - - - - - - - - - - - - - - - Visitor parameters - - - - - - - - - - - - - - - - -
146
+
147
+ /**
148
+ * IP Address of the end user, e.g. "123.123.123.123", found in GA for Mobile examples,
149
+ * but sadly seems to be ignored in normal GA use
150
+ *
151
+ * @link http://github.com/mptre/php-ga/blob/master/ga.php
152
+ * @var string
153
+ */
154
+ public $utmip;
155
+
156
+ /**
157
+ * Visitor's locale string (all lower-case, country part optional), e.g. "de-de"
158
+ * @var string
159
+ */
160
+ public $utmul;
161
+
162
+ /**
163
+ * Visitor's Flash version, e.g. "9.0 r28" or "-" as default
164
+ * @var string
165
+ */
166
+ public $utmfl = '-';
167
+
168
+ /**
169
+ * Visitor's Java support, either 0 or 1 or "-" as default
170
+ * @var int|string
171
+ */
172
+ public $utmje = '-';
173
+
174
+ /**
175
+ * Visitor's screen color depth, e.g. "32-bit"
176
+ * @var string
177
+ */
178
+ public $utmsc;
179
+
180
+ /**
181
+ * Visitor's screen resolution, e.g. "1024x768"
182
+ * @var string
183
+ */
184
+ public $utmsr;
185
+
186
+ /**
187
+ * Visitor tracking cookie parameter.
188
+ *
189
+ * This cookie is typically written to the browser upon the first visit to your site from that web browser.
190
+ * If the cookie has been deleted by the browser operator, and the browser subsequently visits your site,
191
+ * a new __utma cookie is written with a different unique ID.
192
+ *
193
+ * This cookie is used to determine unique visitors to your site and it is updated with each page view.
194
+ * Additionally, this cookie is provided with a unique ID that Google Analytics uses to ensure both the
195
+ * validity and accessibility of the cookie as an extra security measure.
196
+ *
197
+ * Expiration:
198
+ * 2 years from set/update.
199
+ *
200
+ * Format:
201
+ * __utma=<domainHash>.<uniqueId>.<firstTime>.<lastTime>.<currentTime>.<sessionCount>
202
+ *
203
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/data/UTMA.as
204
+ * @var int
205
+ */
206
+ public $__utma;
207
+
208
+
209
+ // - - - - - - - - - - - - - - - - - Session parameters - - - - - - - - - - - - - - - - -
210
+
211
+ /**
212
+ * Hit id for revenue per page tracking for AdSense, a random per-session ID
213
+ *
214
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/core/DocumentInfo.as#117
215
+ * @var int
216
+ */
217
+ public $utmhid;
218
+
219
+ /**
220
+ * Session timeout cookie parameter.
221
+ * Will never be sent with requests, but stays here for documentation completeness.
222
+ *
223
+ * This cookie is used to establish and continue a user session with your site.
224
+ * When a user views a page on your site, the Google Analytics code attempts to update this cookie.
225
+ * If it does not find the cookie, a new one is written and a new session is established.
226
+ *
227
+ * Each time a user visits a different page on your site, this cookie is updated to expire in 30 minutes,
228
+ * thus continuing a single session for as long as user activity continues within 30-minute intervals.
229
+ *
230
+ * This cookie expires when a user pauses on a page on your site for longer than 30 minutes.
231
+ * You can modify the default length of a user session with the setSessionTimeout() method.
232
+ *
233
+ * Expiration:
234
+ * 30 minutes from set/update.
235
+ *
236
+ * Format:
237
+ * __utmb=<domainHash>.<trackCount>.<token>.<lastTime>
238
+ *
239
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/data/UTMB.as
240
+ * @var string
241
+ */
242
+ public $__utmb;
243
+
244
+ /**
245
+ * Session tracking cookie parameter.
246
+ * Will never be sent with requests, but stays here for documentation completeness.
247
+ *
248
+ * This cookie operates in conjunction with the __utmb cookie to determine whether or not
249
+ * to establish a new session for the user.
250
+ * In particular, this cookie is not provided with an expiration date,
251
+ * so it expires when the user exits the browser.
252
+ *
253
+ * Should a user visit your site, exit the browser and then return to your website within 30 minutes,
254
+ * the absence of the __utmc cookie indicates that a new session needs to be established,
255
+ * despite the fact that the __utmb cookie has not yet expired.
256
+ *
257
+ * Expiration:
258
+ * Not set.
259
+ *
260
+ * Format:
261
+ * __utmc=<domainHash>
262
+ *
263
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/data/UTMC.as
264
+ * @var string
265
+ */
266
+ public $__utmc;
267
+
268
+
269
+ // - - - - - - - - - - - - - - - - - E-Commerce parameters - - - - - - - - - - - - - - - - -
270
+
271
+ /**
272
+ * Product Code. This is the sku code for a given product, e.g. "989898ajssi"
273
+ * @var string
274
+ */
275
+ public $utmipc;
276
+
277
+ /**
278
+ * Product Name, e.g. "T-Shirt"
279
+ * @var string
280
+ */
281
+ public $utmipn;
282
+
283
+ /**
284
+ * Unit Price. Value is set to numbers only, e.g. 19.95
285
+ * @var float
286
+ */
287
+ public $utmipr;
288
+
289
+ /**
290
+ * Unit Quantity, e.g. 4
291
+ * @var int
292
+ */
293
+ public $utmiqt;
294
+
295
+ /**
296
+ * Variations on an item, e.g. "white", "black", "green" etc.
297
+ * @var string
298
+ */
299
+ public $utmiva;
300
+
301
+ /**
302
+ * Order ID, e.g. "a2343898"
303
+ * @var string
304
+ */
305
+ public $utmtid;
306
+
307
+ /**
308
+ * Affiliation
309
+ * @var string
310
+ */
311
+ public $utmtst;
312
+
313
+ /**
314
+ * Total Cost, e.g. 20.00
315
+ * @var float
316
+ */
317
+ public $utmtto;
318
+
319
+ /**
320
+ * Tax Cost, e.g. 4.23
321
+ * @var float
322
+ */
323
+ public $utmttx;
324
+
325
+ /**
326
+ * Shipping Cost, e.g. 3.95
327
+ * @var float
328
+ */
329
+ public $utmtsp;
330
+
331
+ /**
332
+ * Billing City, e.g. "Cologne"
333
+ * @var string
334
+ */
335
+ public $utmtci;
336
+
337
+ /**
338
+ * Billing Region, e.g. "North Rhine-Westphalia"
339
+ * @var string
340
+ */
341
+ public $utmtrg;
342
+
343
+ /**
344
+ * Billing Country, e.g. "Germany"
345
+ * @var string
346
+ */
347
+ public $utmtco;
348
+
349
+
350
+ // - - - - - - - - - - - - - - - - - Campaign parameters - - - - - - - - - - - - - - - - -
351
+
352
+ /**
353
+ * Starts a new campaign session. Either utmcn or utmcr is present on any given request,
354
+ * but never both at the same time. Changes the campaign tracking data; but does not start
355
+ * a new session. Either 1 or not set.
356
+ *
357
+ * Found in gaforflash but not in ga.js, so we do not use it, but it will stay here for
358
+ * documentation completeness.
359
+ *
360
+ * @deprecated
361
+ * @var int
362
+ */
363
+ public $utmcn;
364
+
365
+ /**
366
+ * Indicates a repeat campaign visit. This is set when any subsequent clicks occur on the
367
+ * same link. Either utmcn or utmcr is present on any given request, but never both at the
368
+ * same time. Either 1 or not set.
369
+ *
370
+ * Found in gaforflash but not in ga.js, so we do not use it, but it will stay here for
371
+ * documentation completeness.
372
+ *
373
+ * @deprecated
374
+ * @var int
375
+ */
376
+ public $utmcr;
377
+
378
+ /**
379
+ * Campaign ID, a.k.a. "utm_id" query parameter for ga.js
380
+ * @var string
381
+ */
382
+ public $utmcid;
383
+
384
+ /**
385
+ * Source, a.k.a. "utm_source" query parameter for ga.js
386
+ * @var string
387
+ */
388
+ public $utmcsr;
389
+
390
+ /**
391
+ * Google AdWords Click ID, a.k.a. "gclid" query parameter for ga.js
392
+ * @var string
393
+ */
394
+ public $utmgclid;
395
+
396
+ /**
397
+ * Not known for sure, but expected to be a DoubleClick Ad Click ID.
398
+ * @var string
399
+ */
400
+ public $utmdclid;
401
+
402
+ /**
403
+ * Name, a.k.a. "utm_campaign" query parameter for ga.js
404
+ * @var string
405
+ */
406
+ public $utmccn;
407
+
408
+ /**
409
+ * Medium, a.k.a. "utm_medium" query parameter for ga.js
410
+ * @var string
411
+ */
412
+ public $utmcmd;
413
+
414
+ /**
415
+ * Terms/Keywords, a.k.a. "utm_term" query parameter for ga.js
416
+ * @var string
417
+ */
418
+ public $utmctr;
419
+
420
+ /**
421
+ * Ad Content Description, a.k.a. "utm_content" query parameter for ga.js
422
+ * @var string
423
+ */
424
+ public $utmcct;
425
+
426
+ /**
427
+ * Unknown so far. Found in ga.js.
428
+ * @var int
429
+ */
430
+ public $utmcvr;
431
+
432
+ /**
433
+ * Campaign tracking cookie parameter.
434
+ *
435
+ * This cookie stores the type of referral used by the visitor to reach your site,
436
+ * whether via a direct method, a referring link, a website search, or a campaign such as an ad or an email link.
437
+ *
438
+ * It is used to calculate search engine traffic, ad campaigns and page navigation within your own site.
439
+ * The cookie is updated with each page view to your site.
440
+ *
441
+ * Expiration:
442
+ * 6 months from set/update.
443
+ *
444
+ * Format:
445
+ * __utmz=<domainHash>.<campaignCreation>.<campaignSessions>.<responseCount>.<campaignTracking>
446
+ *
447
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/data/UTMZ.as
448
+ * @var string
449
+ */
450
+ public $__utmz;
451
+
452
+
453
+ // - - - - - - - - - - - - - - - - - Social Tracking parameters - - - - - - - - - - - - - - - - -
454
+
455
+ /**
456
+ * The network on which the action occurs (e.g. Facebook, Twitter).
457
+ * @var string
458
+ */
459
+ public $utmsn;
460
+
461
+ /**
462
+ * The type of action that happens (e.g. Like, Send, Tweet).
463
+ * @var string
464
+ */
465
+ public $utmsa;
466
+
467
+ /**
468
+ * The page URL from which the action occurred.
469
+ * @var string
470
+ */
471
+ public $utmsid;
472
+
473
+
474
+ // - - - - - - - - - - - - - - - - - Google Website Optimizer (GWO) parameters - - - - - - - - - - - - - - - - -
475
+
476
+ // TODO: Implementation needed
477
+ /**
478
+ * Website Optimizer cookie parameter.
479
+ *
480
+ * This cookie is used by Website Optimizer and only set when Website Optimizer is used in combination
481
+ * with GA. See the Google Website Optimizer Help Center for details.
482
+ *
483
+ * Expiration:
484
+ * 2 years from set/update.
485
+ *
486
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/data/UTMX.as
487
+ * @var string
488
+ */
489
+ public $__utmx;
490
+
491
+
492
+ // - - - - - - - - - - - - - - - - - Custom Variables parameters (deprecated) - - - - - - - - - - - - - - - - -
493
+
494
+ // TODO: Implementation needed?
495
+ /**
496
+ * Deprecated custom variables cookie parameter.
497
+ *
498
+ * This cookie parameter is no longer relevant as of migration from setVar() to
499
+ * setCustomVar() and hence not supported by this library, but will stay here for
500
+ * documentation completeness.
501
+ *
502
+ * The __utmv cookie passes the information provided via the setVar() method,
503
+ * which you use to create a custom user segment.
504
+ *
505
+ * Expiration:
506
+ * 2 years from set/update.
507
+ *
508
+ * Format:
509
+ * __utmv=<domainHash>.<value>
510
+ *
511
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/data/UTMV.as
512
+ * @deprecated
513
+ * @var string
514
+ */
515
+ public $__utmv;
516
+
517
+
518
+ /**
519
+ * Converts this parameter holder to a pure PHP array, filtering out all properties
520
+ * prefixed with an underscore ("_").
521
+ *
522
+ * @return array
523
+ */
524
+ public function toArray() {
525
+ $array = array();
526
+ foreach($this as $property => $value) {
527
+ if($property[0] != '_') {
528
+ $array[$property] = $value;
529
+ }
530
+ }
531
+ return $array;
532
+ }
533
+
534
+ }
535
+
536
+ ?>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/Internals/Request/EventRequest.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics\Internals\Request;
30
+
31
+ use UnitedPrototype\GoogleAnalytics\Event;
32
+
33
+ use UnitedPrototype\GoogleAnalytics\Internals\X10;
34
+
35
+ class EventRequest extends Request {
36
+
37
+ /**
38
+ * @var \UnitedPrototype\GoogleAnalytics\Event
39
+ */
40
+ protected $event;
41
+
42
+
43
+ /**
44
+ * @const int
45
+ */
46
+ const X10_EVENT_PROJECT_ID = 5;
47
+
48
+
49
+ /**
50
+ * @return string
51
+ */
52
+ protected function getType() {
53
+ return Request::TYPE_EVENT;
54
+ }
55
+
56
+ /**
57
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/v4/Tracker.as#1503
58
+ *
59
+ * @return \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder
60
+ */
61
+ protected function buildParameters() {
62
+ $p = parent::buildParameters();
63
+
64
+ $x10 = new X10();
65
+
66
+ $x10->clearKey(self::X10_EVENT_PROJECT_ID);
67
+ $x10->clearValue(self::X10_EVENT_PROJECT_ID);
68
+
69
+ // Object / Category
70
+ $x10->setKey(self::X10_EVENT_PROJECT_ID, X10::OBJECT_KEY_NUM, $this->event->getCategory());
71
+
72
+ // Event Type / Action
73
+ $x10->setKey(self::X10_EVENT_PROJECT_ID, X10::TYPE_KEY_NUM, $this->event->getAction());
74
+
75
+ if($this->event->getLabel() !== null) {
76
+ // Event Description / Label
77
+ $x10->setKey(self::X10_EVENT_PROJECT_ID, X10::LABEL_KEY_NUM, $this->event->getLabel());
78
+ }
79
+
80
+ if($this->event->getValue() !== null) {
81
+ $x10->setValue(self::X10_EVENT_PROJECT_ID, X10::VALUE_VALUE_NUM, $this->event->getValue());
82
+ }
83
+
84
+ $p->utme .= $x10->renderUrlString();
85
+
86
+ if($this->event->getNoninteraction()) {
87
+ $p->utmni = 1;
88
+ }
89
+
90
+ return $p;
91
+ }
92
+
93
+ /**
94
+ * @return \UnitedPrototype\GoogleAnalytics\Event
95
+ */
96
+ public function getEvent() {
97
+ return $this->event;
98
+ }
99
+
100
+ /**
101
+ * @param \UnitedPrototype\GoogleAnalytics\Event $event
102
+ */
103
+ public function setEvent(Event $event) {
104
+ $this->event = $event;
105
+ }
106
+
107
+ }
108
+
109
+ ?>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/Internals/Request/HttpRequest.php ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics\Internals\Request;
30
+
31
+ use UnitedPrototype\GoogleAnalytics\Config;
32
+
33
+ use UnitedPrototype\GoogleAnalytics\Internals\Util;
34
+
35
+ /**
36
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/core/GIFRequest.as
37
+ */
38
+ abstract class HttpRequest {
39
+
40
+ /**
41
+ * Indicates the type of request, will be mapped to "utmt" parameter
42
+ *
43
+ * @see ParameterHolder::$utmt
44
+ * @var string
45
+ */
46
+ protected $type;
47
+
48
+ /**
49
+ * @var \UnitedPrototype\GoogleAnalytics\Config
50
+ */
51
+ protected $config;
52
+
53
+ /**
54
+ * @var string
55
+ */
56
+ protected $xForwardedFor;
57
+
58
+ /**
59
+ * @var string
60
+ */
61
+ protected $userAgent;
62
+
63
+
64
+ /**
65
+ * @param \UnitedPrototype\GoogleAnalytics\Config $config
66
+ */
67
+ public function __construct(Config $config = null) {
68
+ $this->setConfig($config ? $config : new Config());
69
+ }
70
+
71
+ /**
72
+ * @return \UnitedPrototype\GoogleAnalytics\Config
73
+ */
74
+ public function getConfig() {
75
+ return $this->config;
76
+ }
77
+
78
+ /**
79
+ * @param \UnitedPrototype\GoogleAnalytics\Config $config
80
+ */
81
+ public function setConfig(Config $config) {
82
+ $this->config = $config;
83
+ }
84
+
85
+ /**
86
+ * @param string $value
87
+ */
88
+ protected function setXForwardedFor($value) {
89
+ $this->xForwardedFor = $value;
90
+ }
91
+
92
+ /**
93
+ * @param string $value
94
+ */
95
+ protected function setUserAgent($value) {
96
+ $this->userAgent = $value;
97
+ }
98
+
99
+ /**
100
+ * @return string
101
+ */
102
+ protected function buildHttpRequest() {
103
+ $parameters = $this->buildParameters();
104
+
105
+ // This constant is supported as the 4th argument of http_build_query()
106
+ // from PHP 5.3.6 on and will tell it to use rawurlencode() instead of urlencode()
107
+ // internally, see http://code.google.com/p/php-ga/issues/detail?id=3
108
+ if(defined('PHP_QUERY_RFC3986')) {
109
+ // http_build_query() does automatically skip all array entries
110
+ // with null values, exactly what we want here
111
+ $queryString = http_build_query($parameters->toArray(), '', '&', PHP_QUERY_RFC3986);
112
+ } else {
113
+ // Manually replace "+"s with "%20" for backwards-compatibility
114
+ $queryString = str_replace('+', '%20', http_build_query($parameters->toArray(), '', '&'));
115
+ }
116
+ // Mimic Javascript's encodeURIComponent() encoding for the query
117
+ // string just to be sure we are 100% consistent with GA's Javascript client
118
+ $queryString = Util::convertToUriComponentEncoding($queryString);
119
+
120
+ // Recent versions of ga.js use HTTP POST requests if the query string is too long
121
+ $usePost = strlen($queryString) > 2036;
122
+
123
+ if(!$usePost) {
124
+ $r = 'GET ' . $this->config->getEndpointPath() . '?' . $queryString . ' HTTP/1.0' . "\r\n";
125
+ } else {
126
+ // FIXME: The "/p" shouldn't be hardcoded here, instead we need a GET and a POST endpoint...
127
+ $r = 'POST /p' . $this->config->getEndpointPath() . ' HTTP/1.0' . "\r\n";
128
+ }
129
+ $r .= 'Host: ' . $this->config->getEndpointHost() . "\r\n";
130
+
131
+ if($this->userAgent) {
132
+ $r .= 'User-Agent: ' . str_replace(array("\n", "\r"), '', $this->userAgent) . "\r\n";
133
+ }
134
+
135
+ if($this->xForwardedFor) {
136
+ // Sadly "X-Fowarded-For" is not supported by GA so far,
137
+ // see e.g. http://www.google.com/support/forum/p/Google+Analytics/thread?tid=017691c9e71d4b24,
138
+ // but we include it nonetheless for the pure sake of correctness (and hope)
139
+ $r .= 'X-Forwarded-For: ' . str_replace(array("\n", "\r"), '', $this->xForwardedFor) . "\r\n";
140
+ }
141
+
142
+ if($usePost) {
143
+ // Don't ask me why "text/plain", but ga.js says so :)
144
+ $r .= 'Content-Type: text/plain' . "\r\n";
145
+ $r .= 'Content-Length: ' . strlen($queryString) . "\r\n";
146
+ }
147
+
148
+ $r .= 'Connection: close' . "\r\n";
149
+ $r .= "\r\n\r\n";
150
+
151
+ if($usePost) {
152
+ $r .= $queryString;
153
+ }
154
+
155
+ return $r;
156
+ }
157
+
158
+ /**
159
+ * @return \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder
160
+ */
161
+ protected abstract function buildParameters();
162
+
163
+ /**
164
+ * This method should only be called directly or indirectly by fire(), but must
165
+ * remain public as it can be called by a closure function.
166
+ *
167
+ * Sends either a normal HTTP request with response or an asynchronous request
168
+ * to Google Analytics without waiting for the response. Will always return
169
+ * null in the latter case, or false if any connection problems arise.
170
+ *
171
+ * @see HttpRequest::fire()
172
+ * @param string $request
173
+ * @return null|string|bool
174
+ */
175
+ public function _send() {
176
+ $request = $this->buildHttpRequest();
177
+ $response = null;
178
+
179
+ // Do not actually send the request if endpoint host is set to null
180
+ if($this->config->getEndpointHost() !== null) {
181
+ $timeout = $this->config->getRequestTimeout();
182
+
183
+ $socket = fsockopen($this->config->getEndpointHost(), 80, $errno, $errstr, $timeout);
184
+ if(!$socket) return false;
185
+
186
+ if($this->config->getFireAndForget()) {
187
+ stream_set_blocking($socket, false);
188
+ }
189
+
190
+ $timeoutS = intval($timeout);
191
+ $timeoutUs = ($timeout - $timeoutS) * 100000;
192
+ stream_set_timeout($socket, $timeoutS, $timeoutUs);
193
+
194
+ // Ensure that the full request is sent (see http://code.google.com/p/php-ga/issues/detail?id=11)
195
+ $sentData = 0;
196
+ $toBeSentData = strlen($request);
197
+ while($sentData < $toBeSentData) {
198
+ $sentData += fwrite($socket, $request);
199
+ }
200
+
201
+ if(!$this->config->getFireAndForget()) {
202
+ while(!feof($socket)) {
203
+ $response .= fgets($socket, 512);
204
+ }
205
+ }
206
+
207
+ fclose($socket);
208
+ }
209
+
210
+ if($loggingCallback = $this->config->getLoggingCallback()) {
211
+ $loggingCallback($request, $response);
212
+ }
213
+
214
+ return $response;
215
+ }
216
+
217
+ /**
218
+ * Simply delegates to send() if config option "sendOnShutdown" is disabled
219
+ * or enqueues the request by registering a PHP shutdown function.
220
+ */
221
+ public function fire() {
222
+ if($this->config->getSendOnShutdown()) {
223
+ // This dumb variable assignment is needed as PHP prohibits using
224
+ // $this in closure use statements
225
+ $instance = $this;
226
+ // We use a closure here to retain the current values/states of
227
+ // this instance and $request (as the use statement will copy them
228
+ // into its own scope)
229
+ register_shutdown_function(function() use($instance) {
230
+ $instance->_send();
231
+ });
232
+ } else {
233
+ $this->_send();
234
+ }
235
+ }
236
+
237
+ }
238
+
239
+ ?>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/Internals/Request/ItemRequest.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics\Internals\Request;
30
+
31
+ use UnitedPrototype\GoogleAnalytics\Item;
32
+
33
+ use UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder;
34
+
35
+ class ItemRequest extends Request {
36
+
37
+ /**
38
+ * @var \UnitedPrototype\GoogleAnalytics\Item
39
+ */
40
+ protected $item;
41
+
42
+
43
+ /**
44
+ * @return string
45
+ */
46
+ protected function getType() {
47
+ return Request::TYPE_ITEM;
48
+ }
49
+
50
+ /**
51
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/ecommerce/Item.as#61
52
+ *
53
+ * @return \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder
54
+ */
55
+ protected function buildParameters() {
56
+ $p = parent::buildParameters();
57
+
58
+ $p->utmtid = $this->item->getOrderId();
59
+ $p->utmipc = $this->item->getSku();
60
+ $p->utmipn = $this->item->getName();
61
+ $p->utmiva = $this->item->getVariation();
62
+ $p->utmipr = $this->item->getPrice();
63
+ $p->utmiqt = $this->item->getQuantity();
64
+
65
+ return $p;
66
+ }
67
+
68
+ /**
69
+ * The GA Javascript client doesn't send any visitor information for
70
+ * e-commerce requests, so we don't either.
71
+ *
72
+ * @param \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder $p
73
+ * @return \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder
74
+ */
75
+ protected function buildVisitorParameters(ParameterHolder $p) {
76
+ return $p;
77
+ }
78
+
79
+ /**
80
+ * The GA Javascript client doesn't send any custom variables for
81
+ * e-commerce requests, so we don't either.
82
+ *
83
+ * @param \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder $p
84
+ * @return \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder
85
+ */
86
+ protected function buildCustomVariablesParameter(ParameterHolder $p) {
87
+ return $p;
88
+ }
89
+
90
+ /**
91
+ * @return \UnitedPrototype\GoogleAnalytics\Item
92
+ */
93
+ public function getItem() {
94
+ return $this->item;
95
+ }
96
+
97
+ /**
98
+ * @param \UnitedPrototype\GoogleAnalytics\Item $item
99
+ */
100
+ public function setItem(Item $item) {
101
+ $this->item = $item;
102
+ }
103
+
104
+ }
105
+
106
+ ?>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/Internals/Request/PageviewRequest.php ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics\Internals\Request;
30
+
31
+ use UnitedPrototype\GoogleAnalytics\Page;
32
+
33
+ use UnitedPrototype\GoogleAnalytics\Internals\X10;
34
+
35
+ class PageviewRequest extends Request {
36
+
37
+ /**
38
+ * @var \UnitedPrototype\GoogleAnalytics\Page
39
+ */
40
+ protected $page;
41
+
42
+
43
+ /**
44
+ * @const int
45
+ */
46
+ const X10_SITESPEED_PROJECT_ID = 14;
47
+
48
+
49
+ /**
50
+ * @return string
51
+ */
52
+ protected function getType() {
53
+ return Request::TYPE_PAGE;
54
+ }
55
+
56
+ /**
57
+ * @return \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder
58
+ */
59
+ protected function buildParameters() {
60
+ $p = parent::buildParameters();
61
+
62
+ $p->utmp = $this->page->getPath();
63
+ $p->utmdt = $this->page->getTitle();
64
+ if($this->page->getCharset() !== null) {
65
+ $p->utmcs = $this->page->getCharset();
66
+ }
67
+ if($this->page->getReferrer() !== null) {
68
+ $p->utmr = $this->page->getReferrer();
69
+ }
70
+
71
+ if($this->page->getLoadTime() !== null) {
72
+ // Sample sitespeed measurements
73
+ if($p->utmn % 100 < $this->config->getSitespeedSampleRate()) {
74
+ $x10 = new X10();
75
+
76
+ $x10->clearKey(self::X10_SITESPEED_PROJECT_ID);
77
+ $x10->clearValue(self::X10_SITESPEED_PROJECT_ID);
78
+
79
+ // Taken from ga.js code
80
+ $key = max(min(floor($this->page->getLoadTime() / 100), 5000), 0) * 100;
81
+ $x10->setKey(self::X10_SITESPEED_PROJECT_ID, X10::OBJECT_KEY_NUM, $key);
82
+
83
+ $x10->setValue(self::X10_SITESPEED_PROJECT_ID, X10::VALUE_VALUE_NUM, $this->page->getLoadTime());
84
+
85
+ $p->utme .= $x10->renderUrlString();
86
+ }
87
+ }
88
+
89
+ return $p;
90
+ }
91
+
92
+ /**
93
+ * @return \UnitedPrototype\GoogleAnalytics\Page
94
+ */
95
+ public function getPage() {
96
+ return $this->page;
97
+ }
98
+
99
+ /**
100
+ * @param \UnitedPrototype\GoogleAnalytics\Page $page
101
+ */
102
+ public function setPage(Page $page) {
103
+ $this->page = $page;
104
+ }
105
+
106
+ }
107
+
108
+ ?>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/Internals/Request/Request.php ADDED
@@ -0,0 +1,363 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics\Internals\Request;
30
+
31
+ use UnitedPrototype\GoogleAnalytics\Tracker;
32
+ use UnitedPrototype\GoogleAnalytics\Visitor;
33
+ use UnitedPrototype\GoogleAnalytics\Session;
34
+ use UnitedPrototype\GoogleAnalytics\CustomVariable;
35
+
36
+ use UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder;
37
+ use UnitedPrototype\GoogleAnalytics\Internals\Util;
38
+ use UnitedPrototype\GoogleAnalytics\Internals\X10;
39
+
40
+ abstract class Request extends HttpRequest {
41
+
42
+ /**
43
+ * @var \UnitedPrototype\GoogleAnalytics\Tracker
44
+ */
45
+ protected $tracker;
46
+
47
+ /**
48
+ * @var \UnitedPrototype\GoogleAnalytics\Visitor
49
+ */
50
+ protected $visitor;
51
+
52
+ /**
53
+ * @var \UnitedPrototype\GoogleAnalytics\Session
54
+ */
55
+ protected $session;
56
+
57
+
58
+ /**
59
+ * @const string
60
+ */
61
+ const TYPE_PAGE = null;
62
+ /**
63
+ * @const string
64
+ */
65
+ const TYPE_EVENT = 'event';
66
+ /**
67
+ * @const string
68
+ */
69
+ const TYPE_TRANSACTION = 'tran';
70
+ /**
71
+ * @const string
72
+ */
73
+ const TYPE_ITEM = 'item';
74
+ /**
75
+ * @const string
76
+ */
77
+ const TYPE_SOCIAL = 'social';
78
+ /**
79
+ * This type of request is deprecated in favor of encoding custom variables
80
+ * within the "utme" parameter, but we include it here for completeness
81
+ *
82
+ * @see ParameterHolder::$__utmv
83
+ * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html#_gat.GA_Tracker_._setVar
84
+ * @deprecated
85
+ * @const string
86
+ */
87
+ const TYPE_CUSTOMVARIABLE = 'var';
88
+
89
+ /**
90
+ * @const int
91
+ */
92
+ const X10_CUSTOMVAR_NAME_PROJECT_ID = 8;
93
+ /**
94
+ * @const int
95
+ */
96
+ const X10_CUSTOMVAR_VALUE_PROJECT_ID = 9;
97
+ /**
98
+ * @const int
99
+ */
100
+ const X10_CUSTOMVAR_SCOPE_PROJECT_ID = 11;
101
+
102
+ /**
103
+ * @const string
104
+ */
105
+ const CAMPAIGN_DELIMITER = '|';
106
+
107
+
108
+ /**
109
+ * Indicates the type of request, will be mapped to "utmt" parameter
110
+ *
111
+ * @see ParameterHolder::$utmt
112
+ * @return string See Request::TYPE_* constants
113
+ */
114
+ protected abstract function getType();
115
+
116
+ /**
117
+ * @return string
118
+ */
119
+ protected function buildHttpRequest() {
120
+ $this->setXForwardedFor($this->visitor->getIpAddress());
121
+ $this->setUserAgent($this->visitor->getUserAgent());
122
+
123
+ // Increment session track counter for each request
124
+ $this->session->increaseTrackCount();
125
+
126
+ // See http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/v4/Configuration.as?r=237#48
127
+ // and http://code.google.com/intl/de-DE/apis/analytics/docs/tracking/eventTrackerGuide.html#implementationConsiderations
128
+ if($this->session->getTrackCount() > 500) {
129
+ Tracker::_raiseError('Google Analytics does not guarantee to process more than 500 requests per session.', __METHOD__);
130
+ }
131
+
132
+ if($this->tracker->getCampaign()) {
133
+ $this->tracker->getCampaign()->increaseResponseCount();
134
+ }
135
+
136
+ return parent::buildHttpRequest();
137
+ }
138
+
139
+ /**
140
+ * @return \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder
141
+ */
142
+ protected function buildParameters() {
143
+ $p = new ParameterHolder();
144
+
145
+ $p->utmac = $this->tracker->getAccountId();
146
+ $p->utmhn = $this->tracker->getDomainName();
147
+
148
+ $p->utmt = $this->getType();
149
+ $p->utmn = Util::generate32bitRandom();
150
+
151
+ // The "utmip" parameter is only relevant if a mobile analytics
152
+ // ID (MO-123456-7) was given,
153
+ // see http://code.google.com/p/php-ga/issues/detail?id=9
154
+ $p->utmip = $this->visitor->getIpAddress();
155
+
156
+ $p->aip = $this->tracker->getConfig()->getAnonymizeIpAddresses() ? 1 : null;
157
+ if($p->aip) {
158
+ // Anonymize last IP block
159
+ $p->utmip = substr($p->utmip, 0, strrpos($p->utmip, '.')) . '.0';
160
+ }
161
+
162
+ $p->utmhid = $this->session->getSessionId();
163
+ $p->utms = $this->session->getTrackCount();
164
+
165
+ $p = $this->buildVisitorParameters($p);
166
+ $p = $this->buildCustomVariablesParameter($p);
167
+ $p = $this->buildCampaignParameters($p);
168
+ $p = $this->buildCookieParameters($p);
169
+
170
+ return $p;
171
+ }
172
+
173
+ /**
174
+ * @param \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder $p
175
+ * @return \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder
176
+ */
177
+ protected function buildVisitorParameters(ParameterHolder $p) {
178
+ // Ensure correct locale format, see https://developer.mozilla.org/en/navigator.language
179
+ $p->utmul = strtolower(str_replace('_', '-', $this->visitor->getLocale()));
180
+
181
+ if($this->visitor->getFlashVersion() !== null) {
182
+ $p->utmfl = $this->visitor->getFlashVersion();
183
+ }
184
+ if($this->visitor->getJavaEnabled() !== null) {
185
+ $p->utmje = $this->visitor->getJavaEnabled();
186
+ }
187
+ if($this->visitor->getScreenColorDepth() !== null) {
188
+ $p->utmsc = $this->visitor->getScreenColorDepth() . '-bit';
189
+ }
190
+ $p->utmsr = $this->visitor->getScreenResolution();
191
+
192
+ return $p;
193
+ }
194
+
195
+ /**
196
+ * @link http://xahlee.org/js/google_analytics_tracker_2010-07-01_expanded.js line 575
197
+ * @param \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder $p
198
+ * @return \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder
199
+ */
200
+ protected function buildCustomVariablesParameter(ParameterHolder $p) {
201
+ $customVars = $this->tracker->getCustomVariables();
202
+ if($customVars) {
203
+ if(count($customVars) > 5) {
204
+ // See http://code.google.com/intl/de-DE/apis/analytics/docs/tracking/gaTrackingCustomVariables.html#usage
205
+ Tracker::_raiseError('The sum of all custom variables cannot exceed 5 in any given request.', __METHOD__);
206
+ }
207
+
208
+ $x10 = new X10();
209
+
210
+ $x10->clearKey(self::X10_CUSTOMVAR_NAME_PROJECT_ID);
211
+ $x10->clearKey(self::X10_CUSTOMVAR_VALUE_PROJECT_ID);
212
+ $x10->clearKey(self::X10_CUSTOMVAR_SCOPE_PROJECT_ID);
213
+
214
+ foreach($customVars as $customVar) {
215
+ // Name and value get encoded here,
216
+ // see http://xahlee.org/js/google_analytics_tracker_2010-07-01_expanded.js line 563
217
+ $name = Util::encodeUriComponent($customVar->getName());
218
+ $value = Util::encodeUriComponent($customVar->getValue());
219
+
220
+ $x10->setKey(self::X10_CUSTOMVAR_NAME_PROJECT_ID, $customVar->getIndex(), $name);
221
+ $x10->setKey(self::X10_CUSTOMVAR_VALUE_PROJECT_ID, $customVar->getIndex(), $value);
222
+ if($customVar->getScope() !== null && $customVar->getScope() != CustomVariable::SCOPE_PAGE) {
223
+ $x10->setKey(self::X10_CUSTOMVAR_SCOPE_PROJECT_ID, $customVar->getIndex(), $customVar->getScope());
224
+ }
225
+ }
226
+
227
+ $p->utme .= $x10->renderUrlString();
228
+ }
229
+
230
+ return $p;
231
+ }
232
+
233
+ /**
234
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/core/GIFRequest.as#123
235
+ * @param \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder $p
236
+ * @return \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder
237
+ */
238
+ protected function buildCookieParameters(ParameterHolder $p) {
239
+ $domainHash = $this->generateDomainHash();
240
+
241
+ $p->__utma = $domainHash . '.';
242
+ $p->__utma .= $this->visitor->getUniqueId() . '.';
243
+ $p->__utma .= $this->visitor->getFirstVisitTime()->format('U') . '.';
244
+ $p->__utma .= $this->visitor->getPreviousVisitTime()->format('U') . '.';
245
+ $p->__utma .= $this->visitor->getCurrentVisitTime()->format('U') . '.';
246
+ $p->__utma .= $this->visitor->getVisitCount();
247
+
248
+ $p->__utmb = $domainHash . '.';
249
+ $p->__utmb .= $this->session->getTrackCount() . '.';
250
+ // FIXME: What does "token" mean? I only encountered a value of 10 in my tests.
251
+ $p->__utmb .= 10 . '.';
252
+ $p->__utmb .= $this->session->getStartTime()->format('U');
253
+
254
+ $p->__utmc = $domainHash;
255
+
256
+ $cookies = array();
257
+ $cookies[] = '__utma=' . $p->__utma . ';';
258
+ if($p->__utmz) {
259
+ $cookies[] = '__utmz=' . $p->__utmz . ';';
260
+ }
261
+ if($p->__utmv) {
262
+ $cookies[] = '__utmv=' . $p->__utmv . ';';
263
+ }
264
+
265
+ $p->utmcc = implode('+', $cookies);
266
+
267
+ return $p;
268
+ }
269
+
270
+ /**
271
+ * @param \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder $p
272
+ * @return \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder
273
+ */
274
+ protected function buildCampaignParameters(ParameterHolder $p) {
275
+ $campaign = $this->tracker->getCampaign();
276
+ if($campaign) {
277
+ $p->__utmz = $this->generateDomainHash() . '.';
278
+ $p->__utmz .= $campaign->getCreationTime()->format('U') . '.';
279
+ $p->__utmz .= $this->visitor->getVisitCount() . '.';
280
+ $p->__utmz .= $campaign->getResponseCount() . '.';
281
+
282
+ // See http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/campaign/CampaignTracker.as#236
283
+ $data = array(
284
+ 'utmcid' => $campaign->getId(),
285
+ 'utmcsr' => $campaign->getSource(),
286
+ 'utmgclid' => $campaign->getGClickId(),
287
+ 'utmdclid' => $campaign->getDClickId(),
288
+ 'utmccn' => $campaign->getName(),
289
+ 'utmcmd' => $campaign->getMedium(),
290
+ 'utmctr' => $campaign->getTerm(),
291
+ 'utmcct' => $campaign->getContent(),
292
+ );
293
+ foreach($data as $key => $value) {
294
+ if($value !== null && $value !== '') {
295
+ // Only spaces and pluses get escaped in gaforflash and ga.js, so we do the same
296
+ $p->__utmz .= $key . '=' . str_replace(array('+', ' '), '%20', $value) . static::CAMPAIGN_DELIMITER;
297
+ }
298
+ }
299
+ $p->__utmz = rtrim($p->__utmz, static::CAMPAIGN_DELIMITER);
300
+ }
301
+
302
+ return $p;
303
+ }
304
+
305
+ /**
306
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/v4/Tracker.as#585
307
+ * @return string
308
+ */
309
+ protected function generateDomainHash() {
310
+ $hash = 1;
311
+
312
+ if($this->tracker->getAllowHash()) {
313
+ $hash = Util::generateHash($this->tracker->getDomainName());
314
+ }
315
+
316
+ return $hash;
317
+ }
318
+
319
+ /**
320
+ * @return \UnitedPrototype\GoogleAnalytics\Tracker
321
+ */
322
+ public function getTracker() {
323
+ return $this->tracker;
324
+ }
325
+
326
+ /**
327
+ * @param \UnitedPrototype\GoogleAnalytics\Tracker $tracker
328
+ */
329
+ public function setTracker(Tracker $tracker) {
330
+ $this->tracker = $tracker;
331
+ }
332
+
333
+ /**
334
+ * @return \UnitedPrototype\GoogleAnalytics\Visitor
335
+ */
336
+ public function getVisitor() {
337
+ return $this->visitor;
338
+ }
339
+
340
+ /**
341
+ * @param \UnitedPrototype\GoogleAnalytics\Visitor $visitor
342
+ */
343
+ public function setVisitor(Visitor $visitor) {
344
+ $this->visitor = $visitor;
345
+ }
346
+
347
+ /**
348
+ * @return \UnitedPrototype\GoogleAnalytics\Session
349
+ */
350
+ public function getSession() {
351
+ return $this->session;
352
+ }
353
+
354
+ /**
355
+ * @param \UnitedPrototype\GoogleAnalytics\Session $session
356
+ */
357
+ public function setSession(Session $session) {
358
+ $this->session = $session;
359
+ }
360
+
361
+ }
362
+
363
+ ?>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/Internals/Request/SocialInteractionRequest.php ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics\Internals\Request;
30
+
31
+ use UnitedPrototype\GoogleAnalytics\SocialInteraction;
32
+
33
+ class SocialinteractionRequest extends PageviewRequest {
34
+
35
+ /**
36
+ * @var \UnitedPrototype\GoogleAnalytics\SocialInteraction
37
+ */
38
+ protected $socialInteraction;
39
+
40
+
41
+ /**
42
+ * @return string
43
+ */
44
+ protected function getType() {
45
+ return Request::TYPE_SOCIAL;
46
+ }
47
+
48
+ /**
49
+ * @return \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder
50
+ */
51
+ protected function buildParameters() {
52
+ $p = parent::buildParameters();
53
+
54
+ $p->utmsn = $this->socialInteraction->getNetwork();
55
+ $p->utmsa = $this->socialInteraction->getAction();
56
+ $p->utmsid = $this->socialInteraction->getTarget();
57
+ if($p->utmsid === null) {
58
+ // Default to page path like ga.js,
59
+ // see http://code.google.com/apis/analytics/docs/tracking/gaTrackingSocial.html#settingUp
60
+ $p->utmsid = $this->page->getPath();
61
+ }
62
+
63
+ return $p;
64
+ }
65
+
66
+ /**
67
+ * @return \UnitedPrototype\GoogleAnalytics\SocialInteraction
68
+ */
69
+ public function getSocialInteraction() {
70
+ return $this->socialInteraction;
71
+ }
72
+
73
+ /**
74
+ * @param \UnitedPrototype\GoogleAnalytics\SocialInteraction $socialInteraction
75
+ */
76
+ public function setSocialInteraction(SocialInteraction $socialInteraction) {
77
+ $this->socialInteraction = $socialInteraction;
78
+ }
79
+
80
+ }
81
+
82
+ ?>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/Internals/Request/TransactionRequest.php ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics\Internals\Request;
30
+
31
+ use UnitedPrototype\GoogleAnalytics\Transaction;
32
+
33
+ use UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder;
34
+
35
+ class TransactionRequest extends Request {
36
+
37
+ /**
38
+ * @var \UnitedPrototype\GoogleAnalytics\Transaction
39
+ */
40
+ protected $transaction;
41
+
42
+
43
+ /**
44
+ * @return string
45
+ */
46
+ protected function getType() {
47
+ return Request::TYPE_TRANSACTION;
48
+ }
49
+
50
+ /**
51
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/ecommerce/Transaction.as#76
52
+ *
53
+ * @return \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder
54
+ */
55
+ protected function buildParameters() {
56
+ $p = parent::buildParameters();
57
+
58
+ $p->utmtid = $this->transaction->getOrderId();
59
+ $p->utmtst = $this->transaction->getAffiliation();
60
+ $p->utmtto = $this->transaction->getTotal();
61
+ $p->utmttx = $this->transaction->getTax();
62
+ $p->utmtsp = $this->transaction->getShipping();
63
+ $p->utmtci = $this->transaction->getCity();
64
+ $p->utmtrg = $this->transaction->getRegion();
65
+ $p->utmtco = $this->transaction->getCountry();
66
+
67
+ return $p;
68
+ }
69
+
70
+ /**
71
+ * The GA Javascript client doesn't send any visitor information for
72
+ * e-commerce requests, so we don't either.
73
+ *
74
+ * @param \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder $p
75
+ * @return \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder
76
+ */
77
+ protected function buildVisitorParameters(ParameterHolder $p) {
78
+ return $p;
79
+ }
80
+
81
+ /**
82
+ * The GA Javascript client doesn't send any custom variables for
83
+ * e-commerce requests, so we don't either.
84
+ *
85
+ * @param \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder $p
86
+ * @return \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder
87
+ */
88
+ protected function buildCustomVariablesParameter(ParameterHolder $p) {
89
+ return $p;
90
+ }
91
+
92
+ /**
93
+ * @return \UnitedPrototype\GoogleAnalytics\Transaction
94
+ */
95
+ public function getTransaction() {
96
+ return $this->transaction;
97
+ }
98
+
99
+ /**
100
+ * @param \UnitedPrototype\GoogleAnalytics\Transaction $transaction
101
+ */
102
+ public function setTransaction(Transaction $transaction) {
103
+ $this->transaction = $transaction;
104
+ }
105
+
106
+ }
107
+
108
+ ?>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/Internals/Util.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics\Internals;
30
+
31
+ /**
32
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/core/Utils.as
33
+ */
34
+ class Util {
35
+
36
+ /**
37
+ * This class does only have public static methods, no instantiation necessary
38
+ */
39
+ private function __construct() { }
40
+
41
+
42
+ /**
43
+ * Mimics Javascript's encodeURIComponent() function for consistency with the GA Javascript client.
44
+ *
45
+ * @param mixed $value
46
+ * @return string
47
+ */
48
+ public static function encodeUriComponent($value) {
49
+ return static::convertToUriComponentEncoding(rawurlencode($value));
50
+ }
51
+
52
+ /**
53
+ * Here as a separate method so it can also be applied to e.g. a http_build_query() result.
54
+ *
55
+ * @link http://stackoverflow.com/questions/1734250/what-is-the-equivalent-of-javascripts-encodeuricomponent-in-php/1734255#1734255
56
+ * @link http://devpro.it/examples/php_js_escaping.php
57
+ *
58
+ * @param string $encodedValue
59
+ * @return string
60
+ */
61
+ public static function convertToUriComponentEncoding($encodedValue) {
62
+ return str_replace(array('%21', '%2A', '%27', '%28', '%29'), array('!', '*', "'", '(', ')'), $encodedValue);
63
+ }
64
+
65
+ /**
66
+ * Generates a 32bit random number.
67
+ *
68
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/core/Utils.as#33
69
+ * @return int
70
+ */
71
+ public static function generate32bitRandom() {
72
+ return round((rand() / getrandmax()) * 0x7fffffff);
73
+ }
74
+
75
+ /**
76
+ * Generates a hash for input string.
77
+ *
78
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/core/Utils.as#44
79
+ * @param string $string
80
+ * @return int
81
+ */
82
+ public static function generateHash($string) {
83
+ $string = (string)$string;
84
+ $hash = 1;
85
+
86
+ if($string !== null && $string !== '') {
87
+ $hash = 0;
88
+
89
+ $length = strlen($string);
90
+ for($pos = $length - 1; $pos >= 0; $pos--) {
91
+ $current = ord($string[$pos]);
92
+ $hash = (($hash << 6) & 0xfffffff) + $current + ($current << 14);
93
+ $leftMost7 = $hash & 0xfe00000;
94
+ if($leftMost7 != 0) {
95
+ $hash ^= $leftMost7 >> 21;
96
+ }
97
+ }
98
+ }
99
+
100
+ return $hash;
101
+ }
102
+
103
+ }
104
+
105
+ ?>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/Internals/X10.php ADDED
@@ -0,0 +1,331 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics\Internals;
30
+
31
+ /**
32
+ * This is nearly a 1:1 PHP port of the gaforflash X10 class code.
33
+ *
34
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/data/X10.as
35
+ */
36
+ class X10 {
37
+
38
+ /**
39
+ * @var array
40
+ */
41
+ protected $projectData = array();
42
+
43
+
44
+ /**
45
+ * @var string
46
+ */
47
+ protected $KEY = 'k';
48
+
49
+ /**
50
+ * @var string
51
+ */
52
+ protected $VALUE = 'v';
53
+
54
+ /**
55
+ * @var array
56
+ */
57
+ protected $SET = array('k', 'v');
58
+
59
+ /**
60
+ * Opening delimiter for wrapping a set of values belonging to the same type.
61
+ * @var string
62
+ */
63
+ protected $DELIM_BEGIN = '(';
64
+
65
+ /**
66
+ * Closing delimiter for wrapping a set of values belonging to the same type.
67
+ * @var string
68
+ */
69
+ protected $DELIM_END = ')';
70
+
71
+ /**
72
+ * Delimiter between two consecutive num/value pairs.
73
+ * @var string
74
+ */
75
+ protected $DELIM_SET = '*';
76
+
77
+ /**
78
+ * Delimiter between a num and its corresponding value.
79
+ * @var string
80
+ */
81
+ protected $DELIM_NUM_VALUE = '!';
82
+
83
+ /**
84
+ * Mapping of escapable characters to their escaped forms.
85
+ *
86
+ * @var array
87
+ */
88
+ protected $ESCAPE_CHAR_MAP = array(
89
+ "'" => "'0",
90
+ ')' => "'1",
91
+ '*' => "'2",
92
+ '!' => "'3",
93
+ );
94
+
95
+ /**
96
+ * @var int
97
+ */
98
+ protected $MINIMUM = 1;
99
+
100
+
101
+ /**
102
+ * @const int
103
+ */
104
+ const OBJECT_KEY_NUM = 1;
105
+ /**
106
+ * @const int
107
+ */
108
+ const TYPE_KEY_NUM = 2;
109
+ /**
110
+ * @const int
111
+ */
112
+ const LABEL_KEY_NUM = 3;
113
+ /**
114
+ * @const int
115
+ */
116
+ const VALUE_VALUE_NUM = 1;
117
+
118
+
119
+ /**
120
+ * @param int $projectId
121
+ * @return bool
122
+ */
123
+ protected function hasProject($projectId) {
124
+ return isset($this->projectData[$projectId]);
125
+ }
126
+
127
+ /**
128
+ * @param int $projectId
129
+ * @param int $num
130
+ * @param mixed $value
131
+ */
132
+ public function setKey($projectId, $num, $value) {
133
+ $this->setInternal($projectId, $this->KEY, $num, $value);
134
+ }
135
+
136
+ /**
137
+ * @param int $projectId
138
+ * @param int $num
139
+ * @return mixed
140
+ */
141
+ public function getKey($projectId, $num) {
142
+ return $this->getInternal($projectId, $this->KEY, $num);
143
+ }
144
+
145
+ /**
146
+ * @param int $projectId
147
+ */
148
+ public function clearKey($projectId) {
149
+ $this->clearInternal($projectId, $this->KEY);
150
+ }
151
+
152
+ /**
153
+ * @param int $projectId
154
+ * @param int $num
155
+ * @param mixed $value
156
+ */
157
+ public function setValue($projectId, $num, $value) {
158
+ $this->setInternal($projectId, $this->VALUE, $num, $value);
159
+ }
160
+
161
+ /**
162
+ * @param int $projectId
163
+ * @param int $num
164
+ * @return mixed
165
+ */
166
+ public function getValue($projectId, $num) {
167
+ return $this->getInternal($projectId, $this->VALUE, $num);
168
+ }
169
+
170
+ /**
171
+ * @param int $projectId
172
+ */
173
+ public function clearValue($projectId) {
174
+ $this->clearInternal($projectId, $this->VALUE);
175
+ }
176
+
177
+ /**
178
+ * Shared internal implementation for setting an X10 data type.
179
+ *
180
+ * @param int $projectId
181
+ * @param string $type
182
+ * @param int $num
183
+ * @param mixed $value
184
+ */
185
+ protected function setInternal($projectId, $type, $num, $value) {
186
+ if(!isset($this->projectData[$projectId])) {
187
+ $this->projectData[$projectId] = array();
188
+ }
189
+ if(!isset($this->projectData[$projectId][$type])) {
190
+ $this->projectData[$projectId][$type] = array();
191
+ }
192
+
193
+ $this->projectData[$projectId][$type][$num] = $value;
194
+ }
195
+
196
+ /**
197
+ * Shared internal implementation for getting an X10 data type.
198
+ *
199
+ * @param int $projectId
200
+ * @param string $type
201
+ * @param int $num
202
+ * @return mixed
203
+ */
204
+ protected function getInternal($projectId, $type, $num) {
205
+ if(isset($this->projectData[$projectId][$type][$num])) {
206
+ return $this->projectData[$projectId][$type][$num];
207
+ } else {
208
+ return null;
209
+ }
210
+ }
211
+
212
+ /**
213
+ * Shared internal implementation for clearing all X10 data of a type from a
214
+ * certain project.
215
+ *
216
+ * @param int $projectId
217
+ * @param string $type
218
+ */
219
+ protected function clearInternal($projectId, $type) {
220
+ if(isset($this->projectData[$projectId]) && isset($this->projectData[$projectId][$type])) {
221
+ unset($this->projectData[$projectId][$type]);
222
+ }
223
+ }
224
+
225
+ /**
226
+ * Escape X10 string values to remove ambiguity for special characters.
227
+ *
228
+ * @see X10::$escapeCharMap
229
+ * @param string $value
230
+ * @return string
231
+ */
232
+ protected function escapeExtensibleValue($value) {
233
+ $result = '';
234
+
235
+ $value = (string)$value;
236
+ $length = strlen($value);
237
+ for($i = 0; $i < $length; $i++) {
238
+ $char = $value[$i];
239
+
240
+ if(isset($this->ESCAPE_CHAR_MAP[$char])) {
241
+ $result .= $this->ESCAPE_CHAR_MAP[$char];
242
+ } else {
243
+ $result .= $char;
244
+ }
245
+ }
246
+
247
+ return $result;
248
+ }
249
+
250
+ /**
251
+ * Given a data array for a certain type, render its string encoding.
252
+ *
253
+ * @param array $data
254
+ * @return string
255
+ */
256
+ protected function renderDataType(array $data) {
257
+ $result = array();
258
+
259
+ $lastI = 0;
260
+ ksort($data, SORT_NUMERIC);
261
+ foreach($data as $i => $entry) {
262
+ if(isset($entry)) {
263
+ $str = '';
264
+
265
+ // Check if we need to append the number. If the last number was
266
+ // outputted, or if this is the assumed minimum, then we don't.
267
+ if($i != $this->MINIMUM && $i - 1 != $lastI) {
268
+ $str .= $i;
269
+ $str .= $this->DELIM_NUM_VALUE;
270
+ }
271
+
272
+ $str .= $this->escapeExtensibleValue($entry);
273
+ $result[] = $str;
274
+ }
275
+
276
+ $lastI = $i;
277
+ }
278
+
279
+ return $this->DELIM_BEGIN . implode($this->DELIM_SET, $result) . $this->DELIM_END;
280
+ }
281
+
282
+ /**
283
+ * Given a project array, render its string encoding.
284
+ *
285
+ * @param array $project
286
+ * @return string
287
+ */
288
+ protected function renderProject(array $project) {
289
+ $result = '';
290
+
291
+ // Do we need to output the type string? As an optimization we do not
292
+ // output the type string if it's the first type, or if the previous
293
+ // type was present.
294
+ $needTypeQualifier = false;
295
+
296
+ $length = count($this->SET);
297
+ for($i = 0; $i < $length; $i++) {
298
+ if(isset($project[$this->SET[$i]])) {
299
+ $data = $project[$this->SET[$i]];
300
+
301
+ if($needTypeQualifier) {
302
+ $result .= $this->SET[$i];
303
+ }
304
+ $result .= $this->renderDataType($data);
305
+ $needTypeQualifier = false;
306
+ } else {
307
+ $needTypeQualifier = true;
308
+ }
309
+ }
310
+
311
+ return $result;
312
+ }
313
+
314
+ /**
315
+ * Generates the URL parameter string for the current internal extensible data state.
316
+ *
317
+ * @return string
318
+ */
319
+ public function renderUrlString() {
320
+ $result = '';
321
+
322
+ foreach($this->projectData as $projectId => $project) {
323
+ $result .= $projectId . $this->renderProject($project);
324
+ }
325
+
326
+ return $result;
327
+ }
328
+
329
+ }
330
+
331
+ ?>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/Item.php ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics;
30
+
31
+ /**
32
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/ecommerce/Item.as
33
+ */
34
+ class Item {
35
+
36
+ /**
37
+ * Order ID, e.g. "a2343898", will be mapped to "utmtid" parameter
38
+ *
39
+ * @see Internals\ParameterHolder::$utmtid
40
+ * @var string
41
+ */
42
+ protected $orderId;
43
+
44
+ /**
45
+ * Product Code. This is the sku code for a given product, e.g. "989898ajssi",
46
+ * will be mapped to "utmipc" parameter
47
+ *
48
+ * @see Internals\ParameterHolder::$utmipc
49
+ * @var string
50
+ */
51
+ protected $sku;
52
+
53
+ /**
54
+ * Product Name, e.g. "T-Shirt", will be mapped to "utmipn" parameter
55
+ *
56
+ * @see Internals\ParameterHolder::$utmipn
57
+ * @var string
58
+ */
59
+ protected $name;
60
+
61
+ /**
62
+ * Variations on an item, e.g. "white", "black", "green" etc., will be mapped
63
+ * to "utmiva" parameter
64
+ *
65
+ * @see Internals\ParameterHolder::$utmiva
66
+ * @var string
67
+ */
68
+ protected $variation;
69
+
70
+ /**
71
+ * Unit Price. Value is set to numbers only (e.g. 19.95), will be mapped to
72
+ * "utmipr" parameter
73
+ *
74
+ * @see Internals\ParameterHolder::$utmipr
75
+ * @var float
76
+ */
77
+ protected $price;
78
+
79
+ /**
80
+ * Unit Quantity, e.g. 4, will be mapped to "utmiqt" parameter
81
+ *
82
+ * @see Internals\ParameterHolder::$utmiqt
83
+ * @var int
84
+ */
85
+ protected $quantity = 1;
86
+
87
+
88
+ public function validate() {
89
+ if($this->sku === null) {
90
+ Tracker::_raiseError('Items need to have a sku/product code defined.', __METHOD__);
91
+ }
92
+ }
93
+
94
+ /**
95
+ * @return string
96
+ */
97
+ public function getOrderId() {
98
+ return $this->orderId;
99
+ }
100
+
101
+ /**
102
+ * @param string $orderId
103
+ */
104
+ public function setOrderId($orderId) {
105
+ $this->orderId = $orderId;
106
+ }
107
+
108
+ /**
109
+ * @return string
110
+ */
111
+ public function getSku() {
112
+ return $this->sku;
113
+ }
114
+
115
+ /**
116
+ * @param string $sku
117
+ */
118
+ public function setSku($sku) {
119
+ $this->sku = $sku;
120
+ }
121
+
122
+ /**
123
+ * @return string
124
+ */
125
+ public function getName() {
126
+ return $this->name;
127
+ }
128
+
129
+ /**
130
+ * @param string $name
131
+ */
132
+ public function setName($name) {
133
+ $this->name = $name;
134
+ }
135
+
136
+ /**
137
+ * @return string
138
+ */
139
+ public function getVariation() {
140
+ return $this->variation;
141
+ }
142
+
143
+ /**
144
+ * @param string $variation
145
+ */
146
+ public function setVariation($variation) {
147
+ $this->variation = $variation;
148
+ }
149
+
150
+ /**
151
+ * @return float
152
+ */
153
+ public function getPrice() {
154
+ return $this->price;
155
+ }
156
+
157
+ /**
158
+ * @param float $price
159
+ */
160
+ public function setPrice($price) {
161
+ $this->price = (float)$price;
162
+ }
163
+
164
+ /**
165
+ * @return int
166
+ */
167
+ public function getQuantity() {
168
+ return $this->quantity;
169
+ }
170
+
171
+ /**
172
+ * @param int $quantity
173
+ */
174
+ public function setQuantity($quantity) {
175
+ $this->quantity = (int)$quantity;
176
+ }
177
+
178
+ }
179
+
180
+ ?>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/Page.php ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics;
30
+
31
+ class Page {
32
+
33
+ /**
34
+ * Page request URI, e.g. "/path/page.html", will be mapped to
35
+ * "utmp" parameter
36
+ *
37
+ * @see Internals\ParameterHolder::$utmp
38
+ * @var string
39
+ */
40
+ protected $path;
41
+
42
+ /**
43
+ * Page title, will be mapped to "utmdt" parameter
44
+ *
45
+ * @see Internals\ParameterHolder::$utmdt
46
+ * @var string
47
+ */
48
+ protected $title;
49
+
50
+ /**
51
+ * Charset encoding (e.g. "UTF-8"), will be mapped to "utmcs" parameter
52
+ *
53
+ * @see Internals\ParameterHolder::$utmcs
54
+ * @var string
55
+ */
56
+ protected $charset;
57
+
58
+ /**
59
+ * Referer URL, e.g. "http://www.example.com/path/page.html", will be
60
+ * mapped to "utmr" parameter
61
+ *
62
+ * @see Internals\ParameterHolder::$utmr
63
+ * @var string
64
+ */
65
+ protected $referrer;
66
+
67
+ /**
68
+ * Page load time in milliseconds, will be encoded into "utme" parameter.
69
+ *
70
+ * @see Internals\ParameterHolder::$utme
71
+ * @var int
72
+ */
73
+ protected $loadTime;
74
+
75
+
76
+ /**
77
+ * Constant to mark referrer as a site-internal one.
78
+ *
79
+ * @see Page::$referrer
80
+ * @const string
81
+ */
82
+ const REFERRER_INTERNAL = '0';
83
+
84
+
85
+ /**
86
+ * @param string $path
87
+ */
88
+ public function __construct($path) {
89
+ $this->setPath($path);
90
+ }
91
+
92
+ /**
93
+ * @param string $path
94
+ */
95
+ public function setPath($path) {
96
+ if($path && $path[0] != '/') {
97
+ Tracker::_raiseError('The page path should always start with a slash ("/").', __METHOD__);
98
+ }
99
+
100
+ $this->path = $path;
101
+ }
102
+
103
+ /**
104
+ * @return string
105
+ */
106
+ public function getPath() {
107
+ return $this->path;
108
+ }
109
+
110
+ /**
111
+ * @param string $title
112
+ */
113
+ public function setTitle($title) {
114
+ $this->title = $title;
115
+ }
116
+
117
+ /**
118
+ * @return string
119
+ */
120
+ public function getTitle() {
121
+ return $this->title;
122
+ }
123
+
124
+ /**
125
+ * @param string $charset
126
+ */
127
+ public function setCharset($encoding) {
128
+ $this->charset = $encoding;
129
+ }
130
+
131
+ /**
132
+ * @return string
133
+ */
134
+ public function getCharset() {
135
+ return $this->charset;
136
+ }
137
+
138
+ /**
139
+ * @param string $referrer
140
+ */
141
+ public function setReferrer($referrer) {
142
+ $this->referrer = $referrer;
143
+ }
144
+
145
+ /**
146
+ * @return string
147
+ */
148
+ public function getReferrer() {
149
+ return $this->referrer;
150
+ }
151
+
152
+ /**
153
+ * @param int $loadTime
154
+ */
155
+ public function setLoadTime($loadTime) {
156
+ if((int)$loadTime != (float)$loadTime) {
157
+ return Tracker::_raiseError('Page load time must be specified in integer milliseconds.', __METHOD__);
158
+ }
159
+
160
+ $this->loadTime = (int)$loadTime;
161
+ }
162
+
163
+ /**
164
+ * @return int
165
+ */
166
+ public function getLoadTime() {
167
+ return $this->loadTime;
168
+ }
169
+
170
+ }
171
+
172
+ ?>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/Session.php ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics;
30
+
31
+ use UnitedPrototype\GoogleAnalytics\Internals\Util;
32
+
33
+ use DateTime;
34
+
35
+ /**
36
+ * You should serialize this object and store it in the user session to keep it
37
+ * persistent between requests (similar to the "__umtb" cookie of
38
+ * the GA Javascript client).
39
+ */
40
+ class Session {
41
+
42
+ /**
43
+ * A unique per-session ID, will be mapped to "utmhid" parameter
44
+ *
45
+ * @see Internals\ParameterHolder::$utmhid
46
+ * @var int
47
+ */
48
+ protected $sessionId;
49
+
50
+ /**
51
+ * The amount of pageviews that were tracked within this session so far,
52
+ * will be part of the "__utmb" cookie parameter.
53
+ *
54
+ * Will get incremented automatically upon each request.
55
+ *
56
+ * @see Internals\ParameterHolder::$__utmb
57
+ * @see Internals\Request\Request::buildHttpRequest()
58
+ * @var int
59
+ */
60
+ protected $trackCount;
61
+
62
+ /**
63
+ * Timestamp of the start of this new session, will be part of the "__utmb"
64
+ * cookie parameter
65
+ *
66
+ * @see Internals\ParameterHolder::$__utmb
67
+ * @var DateTime
68
+ */
69
+ protected $startTime;
70
+
71
+
72
+ public function __construct() {
73
+ $this->setSessionId($this->generateSessionId());
74
+ $this->setTrackCount(0);
75
+ $this->setStartTime(new DateTime());
76
+ }
77
+
78
+ /**
79
+ * Will extract information for the "trackCount" and "startTime"
80
+ * properties from the given "__utmb" cookie value.
81
+ *
82
+ * @see Internals\ParameterHolder::$__utmb
83
+ * @see Internals\Request\Request::buildCookieParameters()
84
+ * @param string $value
85
+ * @return $this
86
+ */
87
+ public function fromUtmb($value) {
88
+ $parts = explode('.', $value);
89
+ if(count($parts) != 4) {
90
+ Tracker::_raiseError('The given "__utmb" cookie value is invalid.', __METHOD__);
91
+ return $this;
92
+ }
93
+
94
+ $this->setTrackCount($parts[1]);
95
+ $this->setStartTime(new DateTime('@' . $parts[3]));
96
+
97
+ // Allow chaining
98
+ return $this;
99
+ }
100
+
101
+ /**
102
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/core/DocumentInfo.as#52
103
+ * @return int
104
+ */
105
+ protected function generateSessionId() {
106
+ // TODO: Integrate AdSense support
107
+ return Util::generate32bitRandom();
108
+ }
109
+
110
+ /**
111
+ * @return int
112
+ */
113
+ public function getSessionId() {
114
+ return $this->sessionId;
115
+ }
116
+
117
+ /**
118
+ * @param int $sessionId
119
+ */
120
+ public function setSessionId($sessionId) {
121
+ $this->sessionId = $sessionId;
122
+ }
123
+
124
+ /**
125
+ * @return int
126
+ */
127
+ public function getTrackCount() {
128
+ return $this->trackCount;
129
+ }
130
+
131
+ /**
132
+ * @param int $trackCount
133
+ */
134
+ public function setTrackCount($trackCount) {
135
+ $this->trackCount = (int)$trackCount;
136
+ }
137
+
138
+ /**
139
+ * @param int $byAmount
140
+ */
141
+ public function increaseTrackCount($byAmount = 1) {
142
+ $this->trackCount += $byAmount;
143
+ }
144
+
145
+ /**
146
+ * @return DateTime
147
+ */
148
+ public function getStartTime() {
149
+ return $this->startTime;
150
+ }
151
+
152
+ /**
153
+ * @param DateTime $startTime
154
+ */
155
+ public function setStartTime(DateTime $startTime) {
156
+ $this->startTime = $startTime;
157
+ }
158
+
159
+ }
160
+
161
+ ?>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/SocialInteraction.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics;
30
+
31
+ class SocialInteraction {
32
+
33
+ /**
34
+ * Required. A string representing the social network being tracked (e.g. "Facebook", "Twitter", "LinkedIn", ...),
35
+ * will be mapped to "utmsn" parameter
36
+ *
37
+ * @see Internals\ParameterHolder::$utmsn
38
+ * @var string
39
+ */
40
+ protected $network;
41
+
42
+ /**
43
+ * Required. A string representing the social action being tracked (e.g. "Like", "Share", "Tweet", ...),
44
+ * will be mapped to "utmsa" parameter
45
+ *
46
+ * @see Internals\ParameterHolder::$utmsa
47
+ * @var string
48
+ */
49
+ protected $action;
50
+
51
+ /**
52
+ * Optional. A string representing the URL (or resource) which receives the action. For example,
53
+ * if a user clicks the Like button on a page on a site, the the target might be set to the title
54
+ * of the page, or an ID used to identify the page in a content management system. In many cases,
55
+ * the page you Like is the same page you are on. So if this parameter is not given, we will default
56
+ * to using the path of the corresponding Page object.
57
+ *
58
+ * @see Internals\ParameterHolder::$utmsid
59
+ * @var string
60
+ */
61
+ protected $target;
62
+
63
+
64
+ /**
65
+ * @param string $path
66
+ */
67
+ public function __construct($network = null, $action = null, $target = null) {
68
+ if($network !== null) $this->setNetwork($network);
69
+ if($action !== null) $this->setAction($action);
70
+ if($target !== null) $this->setTarget($target);
71
+ }
72
+
73
+ public function validate() {
74
+ if($this->network === null || $this->action === null) {
75
+ Tracker::_raiseError('Social interactions need to have at least the "network" and "action" attributes defined.', __METHOD__);
76
+ }
77
+ }
78
+
79
+ /**
80
+ * @param string $network
81
+ */
82
+ public function setNetwork($network) {
83
+ $this->network = $network;
84
+ }
85
+
86
+ /**
87
+ * @return string
88
+ */
89
+ public function getNetwork() {
90
+ return $this->network;
91
+ }
92
+
93
+ /**
94
+ * @param string $action
95
+ */
96
+ public function setAction($action) {
97
+ $this->action = $action;
98
+ }
99
+
100
+ /**
101
+ * @return string
102
+ */
103
+ public function getAction() {
104
+ return $this->action;
105
+ }
106
+
107
+ /**
108
+ * @param string $target
109
+ */
110
+ public function setTarget($target) {
111
+ $this->target = $target;
112
+ }
113
+
114
+ /**
115
+ * @return string
116
+ */
117
+ public function getTarget() {
118
+ return $this->target;
119
+ }
120
+
121
+ }
122
+
123
+ ?>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/Tracker.php ADDED
@@ -0,0 +1,344 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics;
30
+
31
+ use UnitedPrototype\GoogleAnalytics\Internals\Util;
32
+ use UnitedPrototype\GoogleAnalytics\Internals\Request\PageviewRequest;
33
+ use UnitedPrototype\GoogleAnalytics\Internals\Request\EventRequest;
34
+ use UnitedPrototype\GoogleAnalytics\Internals\Request\TransactionRequest;
35
+ use UnitedPrototype\GoogleAnalytics\Internals\Request\ItemRequest;
36
+ use UnitedPrototype\GoogleAnalytics\Internals\Request\SocialInteractionRequest;
37
+
38
+ class Tracker {
39
+
40
+ /**
41
+ * Google Analytics client version on which this library is built upon,
42
+ * will be mapped to "utmwv" parameter.
43
+ *
44
+ * This doesn't necessarily mean that all features of the corresponding
45
+ * ga.js version are implemented but rather that the requests comply
46
+ * with these of ga.js.
47
+ *
48
+ * @link http://code.google.com/apis/analytics/docs/gaJS/changelog.html
49
+ * @const string
50
+ */
51
+ const VERSION = '5.2.5'; // As of 25.02.2012
52
+
53
+
54
+ /**
55
+ * The configuration to use for all tracker instances.
56
+ *
57
+ * @var \UnitedPrototype\GoogleAnalytics\Config
58
+ */
59
+ protected static $config;
60
+
61
+ /**
62
+ * Google Analytics account ID, e.g. "UA-1234567-8", will be mapped to
63
+ * "utmac" parameter
64
+ *
65
+ * @see Internals\ParameterHolder::$utmac
66
+ * @var string
67
+ */
68
+ protected $accountId;
69
+
70
+ /**
71
+ * Host Name, e.g. "www.example.com", will be mapped to "utmhn" parameter
72
+ *
73
+ * @see Internals\ParameterHolder::$utmhn
74
+ * @var string
75
+ */
76
+ protected $domainName;
77
+
78
+ /**
79
+ * Whether to generate a unique domain hash, default is true to be consistent
80
+ * with the GA Javascript Client
81
+ *
82
+ * @link http://code.google.com/apis/analytics/docs/tracking/gaTrackingSite.html#setAllowHash
83
+ * @see Internals\Request\Request::generateDomainHash()
84
+ * @var bool
85
+ */
86
+ protected $allowHash = true;
87
+
88
+ /**
89
+ * @var array
90
+ */
91
+ protected $customVariables = array();
92
+
93
+ /**
94
+ * @var \UnitedPrototype\GoogleAnalytics\Campaign
95
+ */
96
+ protected $campaign;
97
+
98
+
99
+ /**
100
+ * @param string $accountId
101
+ * @param string $domainName
102
+ * @param \UnitedPrototype\GoogleAnalytics\Config $config
103
+ */
104
+ public function __construct($accountId, $domainName, Config $config = null) {
105
+ static::setConfig($config ? $config : new Config());
106
+
107
+ $this->setAccountId($accountId);
108
+ $this->setDomainName($domainName);
109
+ }
110
+
111
+ /**
112
+ * @return \UnitedPrototype\GoogleAnalytics\Config
113
+ */
114
+ public static function getConfig() {
115
+ return static::$config;
116
+ }
117
+
118
+ /**
119
+ * @param \UnitedPrototype\GoogleAnalytics\Config $value
120
+ */
121
+ public static function setConfig(Config $value) {
122
+ static::$config = $value;
123
+ }
124
+
125
+ /**
126
+ * @param string $value
127
+ */
128
+ public function setAccountId($value) {
129
+ if(!preg_match('/^(UA|MO)-[0-9]*-[0-9]*$/', $value)) {
130
+ static::_raiseError('"' . $value . '" is not a valid Google Analytics account ID.', __METHOD__);
131
+ }
132
+
133
+ $this->accountId = $value;
134
+ }
135
+
136
+ /**
137
+ * @return string
138
+ */
139
+ public function getAccountId() {
140
+ return $this->accountId;
141
+ }
142
+
143
+ /**
144
+ * @param string $value
145
+ */
146
+ public function setDomainName($value) {
147
+ $this->domainName = $value;
148
+ }
149
+
150
+ /**
151
+ * @return string
152
+ */
153
+ public function getDomainName() {
154
+ return $this->domainName;
155
+ }
156
+
157
+ /**
158
+ * @param bool $value
159
+ */
160
+ public function setAllowHash($value) {
161
+ $this->allowHash = (bool)$value;
162
+ }
163
+
164
+ /**
165
+ * @return bool
166
+ */
167
+ public function getAllowHash() {
168
+ return $this->allowHash;
169
+ }
170
+
171
+ /**
172
+ * Equivalent of _setCustomVar() in GA Javascript client.
173
+ *
174
+ * @link http://code.google.com/apis/analytics/docs/tracking/gaTrackingCustomVariables.html
175
+ * @param \UnitedPrototype\GoogleAnalytics\CustomVariable $customVariable
176
+ */
177
+ public function addCustomVariable(CustomVariable $customVariable) {
178
+ // Ensure that all required parameters are set
179
+ $customVariable->validate();
180
+
181
+ $index = $customVariable->getIndex();
182
+ $this->customVariables[$index] = $customVariable;
183
+ }
184
+
185
+ /**
186
+ * @return \UnitedPrototype\GoogleAnalytics\CustomVariable[]
187
+ */
188
+ public function getCustomVariables() {
189
+ return $this->customVariables;
190
+ }
191
+
192
+ /**
193
+ * Equivalent of _deleteCustomVar() in GA Javascript client.
194
+ *
195
+ * @param int $index
196
+ */
197
+ public function removeCustomVariable($index) {
198
+ unset($this->customVariables[$index]);
199
+ }
200
+
201
+ /**
202
+ * @param \UnitedPrototype\GoogleAnalytics\Campaign $campaign Isn't really optional, but can be set to null
203
+ */
204
+ public function setCampaign(Campaign $campaign = null) {
205
+ if($campaign) {
206
+ // Ensure that all required parameters are set
207
+ $campaign->validate();
208
+ }
209
+
210
+ $this->campaign = $campaign;
211
+ }
212
+
213
+ /**
214
+ * @return \UnitedPrototype\GoogleAnalytics\Campaign|null
215
+ */
216
+ public function getCampaign() {
217
+ return $this->campaign;
218
+ }
219
+
220
+ /**
221
+ * Equivalent of _trackPageview() in GA Javascript client.
222
+ *
223
+ * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html#_gat.GA_Tracker_._trackPageview
224
+ * @param \UnitedPrototype\GoogleAnalytics\Page $page
225
+ * @param \UnitedPrototype\GoogleAnalytics\Session $session
226
+ * @param \UnitedPrototype\GoogleAnalytics\Visitor $visitor
227
+ */
228
+ public function trackPageview(Page $page, Session $session, Visitor $visitor) {
229
+ $request = new PageviewRequest(static::$config);
230
+ $request->setPage($page);
231
+ $request->setSession($session);
232
+ $request->setVisitor($visitor);
233
+ $request->setTracker($this);
234
+ $request->fire();
235
+ }
236
+
237
+ /**
238
+ * Equivalent of _trackEvent() in GA Javascript client.
239
+ *
240
+ * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEventTracking.html#_gat.GA_EventTracker_._trackEvent
241
+ * @param \UnitedPrototype\GoogleAnalytics\Event $event
242
+ * @param \UnitedPrototype\GoogleAnalytics\Session $session
243
+ * @param \UnitedPrototype\GoogleAnalytics\Visitor $visitor
244
+ */
245
+ public function trackEvent(Event $event, Session $session, Visitor $visitor) {
246
+ // Ensure that all required parameters are set
247
+ $event->validate();
248
+
249
+ $request = new EventRequest(static::$config);
250
+ $request->setEvent($event);
251
+ $request->setSession($session);
252
+ $request->setVisitor($visitor);
253
+ $request->setTracker($this);
254
+ $request->fire();
255
+ }
256
+
257
+ /**
258
+ * Combines _addTrans(), _addItem() (indirectly) and _trackTrans() of GA Javascript client.
259
+ * Although the naming of "_addTrans()" would suggest multiple possible transactions
260
+ * per request, there is just one allowed actually.
261
+ *
262
+ * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html#_gat.GA_Tracker_._addTrans
263
+ * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html#_gat.GA_Tracker_._addItem
264
+ * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html#_gat.GA_Tracker_._trackTrans
265
+ *
266
+ * @param \UnitedPrototype\GoogleAnalytics\Transaction $transaction
267
+ * @param \UnitedPrototype\GoogleAnalytics\Session $session
268
+ * @param \UnitedPrototype\GoogleAnalytics\Visitor $visitor
269
+ */
270
+ public function trackTransaction(Transaction $transaction, Session $session, Visitor $visitor) {
271
+ // Ensure that all required parameters are set
272
+ $transaction->validate();
273
+
274
+ $request = new TransactionRequest(static::$config);
275
+ $request->setTransaction($transaction);
276
+ $request->setSession($session);
277
+ $request->setVisitor($visitor);
278
+ $request->setTracker($this);
279
+ $request->fire();
280
+
281
+ // Every item gets a separate request,
282
+ // see http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/v4/Tracker.as#312
283
+ foreach($transaction->getItems() as $item) {
284
+ // Ensure that all required parameters are set
285
+ $item->validate();
286
+
287
+ $request = new ItemRequest(static::$config);
288
+ $request->setItem($item);
289
+ $request->setSession($session);
290
+ $request->setVisitor($visitor);
291
+ $request->setTracker($this);
292
+ $request->fire();
293
+ }
294
+ }
295
+
296
+ /**
297
+ * Equivalent of _trackSocial() in GA Javascript client.
298
+ *
299
+ * @link http://code.google.com/apis/analytics/docs/tracking/gaTrackingSocial.html#settingUp
300
+ * @param \UnitedPrototype\GoogleAnalytics\SocialInteraction $socialInteraction
301
+ * @param \UnitedPrototype\GoogleAnalytics\Page $page
302
+ * @param \UnitedPrototype\GoogleAnalytics\Session $session
303
+ * @param \UnitedPrototype\GoogleAnalytics\Visitor $visitor
304
+ */
305
+ public function trackSocial(SocialInteraction $socialInteraction, Page $page, Session $session, Visitor $visitor) {
306
+ $request = new SocialInteractionRequest(static::$config);
307
+ $request->setSocialInteraction($socialInteraction);
308
+ $request->setPage($page);
309
+ $request->setSession($session);
310
+ $request->setVisitor($visitor);
311
+ $request->setTracker($this);
312
+ $request->fire();
313
+ }
314
+
315
+ /**
316
+ * For internal use only. Will trigger an error according to the current
317
+ * Config::$errorSeverity setting.
318
+ *
319
+ * @see Config::$errorSeverity
320
+ * @param string $message
321
+ * @param string $method
322
+ */
323
+ public static function _raiseError($message, $method) {
324
+ $method = str_replace(__NAMESPACE__ . '\\', '', $method);
325
+ $message = $method . '(): ' . $message;
326
+
327
+ $errorSeverity = isset(static::$config) ? static::$config->getErrorSeverity() : Config::ERROR_SEVERITY_EXCEPTIONS;
328
+
329
+ switch($errorSeverity) {
330
+ case Config::ERROR_SEVERITY_SILENCE:
331
+ // Do nothing
332
+ break;
333
+ case Config::ERROR_SEVERITY_WARNINGS:
334
+ trigger_error($message, E_USER_WARNING);
335
+ break;
336
+ case Config::ERROR_SEVERITY_EXCEPTIONS:
337
+ throw new Exception($message);
338
+ break;
339
+ }
340
+ }
341
+
342
+ }
343
+
344
+ ?>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/Transaction.php ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics;
30
+
31
+ /**
32
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/ecommerce/Transaction.as
33
+ */
34
+ class Transaction {
35
+
36
+ /**
37
+ * Order ID, e.g. "a2343898", will be mapped to "utmtid" parameter
38
+ *
39
+ * @see Internals\ParameterHolder::$utmtid
40
+ * @var string
41
+ */
42
+ protected $orderId;
43
+
44
+ /**
45
+ * Affiliation, Will be mapped to "utmtst" parameter
46
+ *
47
+ * @see Internals\ParameterHolder::$utmtst
48
+ * @var string
49
+ */
50
+ protected $affiliation;
51
+
52
+ /**
53
+ * Total Cost, will be mapped to "utmtto" parameter
54
+ *
55
+ * @see Internals\ParameterHolder::$utmtto
56
+ * @var float
57
+ */
58
+ protected $total;
59
+
60
+ /**
61
+ * Tax Cost, will be mapped to "utmttx" parameter
62
+ *
63
+ * @see Internals\ParameterHolder::$utmttx
64
+ * @var float
65
+ */
66
+ protected $tax;
67
+
68
+ /**
69
+ * Shipping Cost, values as for unit and price, e.g. 3.95, will be mapped to
70
+ * "utmtsp" parameter
71
+ *
72
+ * @see Internals\ParameterHolder::$utmtsp
73
+ * @var float
74
+ */
75
+ protected $shipping;
76
+
77
+ /**
78
+ * Billing City, e.g. "Cologne", will be mapped to "utmtci" parameter
79
+ *
80
+ * @see Internals\ParameterHolder::$utmtci
81
+ * @var string
82
+ */
83
+ protected $city;
84
+
85
+ /**
86
+ * Billing Region, e.g. "North Rhine-Westphalia", will be mapped to "utmtrg" parameter
87
+ *
88
+ * @see Internals\ParameterHolder::$utmtrg
89
+ * @var string
90
+ */
91
+ protected $region;
92
+
93
+ /**
94
+ * Billing Country, e.g. "Germany", will be mapped to "utmtco" parameter
95
+ *
96
+ * @see Internals\ParameterHolder::$utmtco
97
+ * @var string
98
+ */
99
+ protected $country;
100
+
101
+ /**
102
+ * @see Transaction::addItem()
103
+ * @var \UnitedPrototype\GoogleAnalytics\Item[]
104
+ */
105
+ protected $items = array();
106
+
107
+
108
+ public function validate() {
109
+ if(!$this->items) {
110
+ Tracker::_raiseError('Transactions need to consist of at least one item.', __METHOD__);
111
+ }
112
+ }
113
+
114
+ /**
115
+ * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html#_gat.GA_Tracker_._addItem
116
+ * @param \UnitedPrototype\GoogleAnalytics\Item $item
117
+ */
118
+ public function addItem(Item $item) {
119
+ // Associated items inherit the transaction's order ID
120
+ $item->setOrderId($this->orderId);
121
+
122
+ $sku = $item->getSku();
123
+ $this->items[$sku] = $item;
124
+ }
125
+
126
+ /**
127
+ * @return \UnitedPrototype\GoogleAnalytics\Item[]
128
+ */
129
+ public function getItems() {
130
+ return $this->items;
131
+ }
132
+
133
+ /**
134
+ * @return string
135
+ */
136
+ public function getOrderId() {
137
+ return $this->orderId;
138
+ }
139
+
140
+ /**
141
+ * @param string $orderId
142
+ */
143
+ public function setOrderId($orderId) {
144
+ $this->orderId = $orderId;
145
+
146
+ // Update order IDs of all associated items too
147
+ foreach($this->items as $item) {
148
+ $item->setOrderId($orderId);
149
+ }
150
+ }
151
+
152
+ /**
153
+ * @return string
154
+ */
155
+ public function getAffiliation() {
156
+ return $this->affiliation;
157
+ }
158
+
159
+ /**
160
+ * @param string $affiliation
161
+ */
162
+ public function setAffiliation($affiliation) {
163
+ $this->affiliation = $affiliation;
164
+ }
165
+
166
+ /**
167
+ * @return float
168
+ */
169
+ public function getTotal() {
170
+ return $this->total;
171
+ }
172
+
173
+ /**
174
+ * @param float $total
175
+ */
176
+ public function setTotal($total) {
177
+ $this->total = $total;
178
+ }
179
+
180
+ /**
181
+ * @return float
182
+ */
183
+ public function getTax() {
184
+ return $this->tax;
185
+ }
186
+
187
+ /**
188
+ * @param float $tax
189
+ */
190
+ public function setTax($tax) {
191
+ $this->tax = $tax;
192
+ }
193
+
194
+ /**
195
+ * @return float
196
+ */
197
+ public function getShipping() {
198
+ return $this->shipping;
199
+ }
200
+
201
+ /**
202
+ * @param float $shipping
203
+ */
204
+ public function setShipping($shipping) {
205
+ $this->shipping = $shipping;
206
+ }
207
+
208
+ /**
209
+ * @return string
210
+ */
211
+ public function getCity() {
212
+ return $this->city;
213
+ }
214
+
215
+ /**
216
+ * @param string $city
217
+ */
218
+ public function setCity($city) {
219
+ $this->city = $city;
220
+ }
221
+
222
+ /**
223
+ * @return string
224
+ */
225
+ public function getRegion() {
226
+ return $this->region;
227
+ }
228
+
229
+ /**
230
+ * @param string $region
231
+ */
232
+ public function setRegion($region) {
233
+ $this->region = $region;
234
+ }
235
+
236
+ /**
237
+ * @return string
238
+ */
239
+ public function getCountry() {
240
+ return $this->country;
241
+ }
242
+
243
+ /**
244
+ * @param string $country
245
+ */
246
+ public function setCountry($country) {
247
+ $this->country = $country;
248
+ }
249
+
250
+ }
251
+
252
+ ?>
app/code/local/Sluice/Connect/lib/GoogleAnalytics/Visitor.php ADDED
@@ -0,0 +1,463 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic Server-Side Google Analytics PHP Client
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License (LGPL) as published by the Free Software Foundation; either
9
+ * version 3 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
+ *
20
+ * Google Analytics is a registered trademark of Google Inc.
21
+ *
22
+ * @link http://code.google.com/p/php-ga
23
+ *
24
+ * @license http://www.gnu.org/licenses/lgpl.html
25
+ * @author Thomas Bachem <tb@unitedprototype.com>
26
+ * @copyright Copyright (c) 2010 United Prototype GmbH (http://unitedprototype.com)
27
+ */
28
+
29
+ namespace UnitedPrototype\GoogleAnalytics;
30
+
31
+ use UnitedPrototype\GoogleAnalytics\Internals\Util;
32
+
33
+ use DateTime;
34
+
35
+ /**
36
+ * You should serialize this object and store it in the user database to keep it
37
+ * persistent for the same user permanently (similar to the "__umta" cookie of
38
+ * the GA Javascript client).
39
+ */
40
+ class Visitor {
41
+
42
+ /**
43
+ * Unique user ID, will be part of the "__utma" cookie parameter
44
+ *
45
+ * @see Internals\ParameterHolder::$__utma
46
+ * @var int
47
+ */
48
+ protected $uniqueId;
49
+
50
+ /**
51
+ * Time of the very first visit of this user, will be part of the "__utma"
52
+ * cookie parameter
53
+ *
54
+ * @see Internals\ParameterHolder::$__utma
55
+ * @var DateTime
56
+ */
57
+ protected $firstVisitTime;
58
+
59
+ /**
60
+ * Time of the previous visit of this user, will be part of the "__utma"
61
+ * cookie parameter
62
+ *
63
+ * @see Internals\ParameterHolder::$__utma
64
+ * @see addSession
65
+ * @var DateTime
66
+ */
67
+ protected $previousVisitTime;
68
+
69
+ /**
70
+ * Time of the current visit of this user, will be part of the "__utma"
71
+ * cookie parameter
72
+ *
73
+ * @see Internals\ParameterHolder::$__utma
74
+ * @see addSession
75
+ * @var DateTime
76
+ */
77
+ protected $currentVisitTime;
78
+
79
+ /**
80
+ * Amount of total visits by this user, will be part of the "__utma"
81
+ * cookie parameter
82
+ *
83
+ * @see Internals\ParameterHolder::$__utma
84
+ * @var int
85
+ */
86
+ protected $visitCount;
87
+
88
+ /**
89
+ * IP Address of the end user, e.g. "123.123.123.123", will be mapped to "utmip" parameter
90
+ * and "X-Forwarded-For" request header
91
+ *
92
+ * @see Internals\ParameterHolder::$utmip
93
+ * @see Internals\Request\HttpRequest::$xForwardedFor
94
+ * @var string
95
+ */
96
+ protected $ipAddress;
97
+
98
+ /**
99
+ * User agent string of the end user, will be mapped to "User-Agent" request header
100
+ *
101
+ * @see Internals\Request\HttpRequest::$userAgent
102
+ * @var string
103
+ */
104
+ protected $userAgent;
105
+
106
+ /**
107
+ * Locale string (country part optional), e.g. "de-DE", will be mapped to "utmul" parameter
108
+ *
109
+ * @see Internals\ParameterHolder::$utmul
110
+ * @var string
111
+ */
112
+ protected $locale;
113
+
114
+ /**
115
+ * Visitor's Flash version, e.g. "9.0 r28", will be maped to "utmfl" parameter
116
+ *
117
+ * @see Internals\ParameterHolder::$utmfl
118
+ * @var string
119
+ */
120
+ protected $flashVersion;
121
+
122
+ /**
123
+ * Visitor's Java support, will be mapped to "utmje" parameter
124
+ *
125
+ * @see Internals\ParameterHolder::$utmje
126
+ * @var bool
127
+ */
128
+ protected $javaEnabled;
129
+
130
+ /**
131
+ * Visitor's screen color depth, e.g. 32, will be mapped to "utmsc" parameter
132
+ *
133
+ * @see Internals\ParameterHolder::$utmsc
134
+ * @var string
135
+ */
136
+ protected $screenColorDepth;
137
+
138
+ /**
139
+ * Visitor's screen resolution, e.g. "1024x768", will be mapped to "utmsr" parameter
140
+ *
141
+ * @see Internals\ParameterHolder::$utmsr
142
+ * @var string
143
+ */
144
+ protected $screenResolution;
145
+
146
+
147
+ /**
148
+ * Creates a new visitor without any previous visit information.
149
+ */
150
+ public function __construct() {
151
+ // ga.js sets all three timestamps to now for new visitors, so we do the same
152
+ $now = new DateTime();
153
+ $this->setFirstVisitTime($now);
154
+ $this->setPreviousVisitTime($now);
155
+ $this->setCurrentVisitTime($now);
156
+
157
+ $this->setVisitCount(1);
158
+ }
159
+
160
+ /**
161
+ * Will extract information for the "uniqueId", "firstVisitTime", "previousVisitTime",
162
+ * "currentVisitTime" and "visitCount" properties from the given "__utma" cookie
163
+ * value.
164
+ *
165
+ * @see Internals\ParameterHolder::$__utma
166
+ * @see Internals\Request\Request::buildCookieParameters()
167
+ * @param string $value
168
+ * @return $this
169
+ */
170
+ public function fromUtma($value) {
171
+ $parts = explode('.', $value);
172
+ if(count($parts) != 6) {
173
+ Tracker::_raiseError('The given "__utma" cookie value is invalid.', __METHOD__);
174
+ return $this;
175
+ }
176
+
177
+ $this->setUniqueId($parts[1]);
178
+ $this->setFirstVisitTime(new DateTime('@' . $parts[2]));
179
+ $this->setPreviousVisitTime(new DateTime('@' . $parts[3]));
180
+ $this->setCurrentVisitTime(new DateTime('@' . $parts[4]));
181
+ $this->setVisitCount($parts[5]);
182
+
183
+ // Allow chaining
184
+ return $this;
185
+ }
186
+
187
+ /**
188
+ * Will extract information for the "ipAddress", "userAgent" and "locale" properties
189
+ * from the given $_SERVER variable.
190
+ *
191
+ * @param array $value
192
+ * @return $this
193
+ */
194
+ public function fromServerVar(array $value) {
195
+ if(!empty($value['REMOTE_ADDR'])) {
196
+ $ip = null;
197
+ foreach(array('X_FORWARDED_FOR', 'REMOTE_ADDR') as $key) {
198
+ if(!empty($value[$key]) && !$ip) {
199
+ $ips = explode(',', $value[$key]);
200
+ $ip = trim($ips[(count($ips) - 1)]);
201
+
202
+ // Double-check if the address has a valid format
203
+ if(!preg_match('/^[\d+]{1,3}\.[\d+]{1,3}\.[\d+]{1,3}\.[\d+]{1,3}$/i', $ip)) {
204
+ $ip = null;
205
+ }
206
+ // Exclude private IP address ranges
207
+ if(preg_match('#^(?:127\.0\.0\.1|10\.|192\.168\.|172\.(?:1[6-9]|2[0-9]|3[0-1])\.)#', $ip)) {
208
+ $ip = null;
209
+ }
210
+ }
211
+ }
212
+
213
+ if($ip) {
214
+ $this->setIpAddress($ip);
215
+ }
216
+ }
217
+
218
+ if(!empty($value['HTTP_USER_AGENT'])) {
219
+ $this->setUserAgent($value['HTTP_USER_AGENT']);
220
+ }
221
+
222
+ if(!empty($value['HTTP_ACCEPT_LANGUAGE'])) {
223
+ $parsedLocales = array();
224
+ if(preg_match_all('/(^|\s*,\s*)([a-zA-Z]{1,8}(-[a-zA-Z]{1,8})*)\s*(;\s*q\s*=\s*(1(\.0{0,3})?|0(\.[0-9]{0,3})))?/i', $value['HTTP_ACCEPT_LANGUAGE'], $matches)) {
225
+ $matches[2] = array_map(function($part) { return str_replace('-', '_', $part); }, $matches[2]);
226
+ $matches[5] = array_map(function($part) { return $part === '' ? 1 : $part; }, $matches[5]);
227
+ $parsedLocales = array_combine($matches[2], $matches[5]);
228
+ arsort($parsedLocales, SORT_NUMERIC);
229
+ $parsedLocales = array_keys($parsedLocales);
230
+ }
231
+
232
+ if($parsedLocales) {
233
+ $this->setLocale($parsedLocales[0]);
234
+ }
235
+ }
236
+
237
+ // Allow chaining
238
+ return $this;
239
+ }
240
+
241
+ /**
242
+ * Generates a hashed value from user-specific properties.
243
+ *
244
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/v4/Tracker.as#542
245
+ * @return int
246
+ */
247
+ protected function generateHash() {
248
+ // TODO: Emulate orginal Google Analytics client library generation more closely
249
+ $string = $this->userAgent;
250
+ $string .= $this->screenResolution . $this->screenColorDepth;
251
+ return Util::generateHash($string);
252
+ }
253
+
254
+ /**
255
+ * Generates a unique user ID from the current user-specific properties.
256
+ *
257
+ * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/v4/Tracker.as#563
258
+ * @return int
259
+ */
260
+ protected function generateUniqueId() {
261
+ // There seems to be an error in the gaforflash code, so we take the formula
262
+ // from http://xahlee.org/js/google_analytics_tracker_2010-07-01_expanded.js line 711
263
+ // instead ("&" instead of "*")
264
+ return ((Util::generate32bitRandom() ^ $this->generateHash()) & 0x7fffffff);
265
+ }
266
+
267
+ /**
268
+ * @see generateUniqueId
269
+ * @param int $value
270
+ */
271
+ public function setUniqueId($value) {
272
+ if($value < 0 || $value > 0x7fffffff) {
273
+ Tracker::_raiseError('Visitor unique ID has to be a 32-bit integer between 0 and ' . 0x7fffffff . '.', __METHOD__);
274
+ }
275
+
276
+ $this->uniqueId = (int)$value;
277
+ }
278
+
279
+ /**
280
+ * Will be generated on first call (if not set already) to include as much
281
+ * user-specific information as possible.
282
+ *
283
+ * @return int
284
+ */
285
+ public function getUniqueId() {
286
+ if($this->uniqueId === null) {
287
+ $this->uniqueId = $this->generateUniqueId();
288
+ }
289
+ return $this->uniqueId;
290
+ }
291
+
292
+ /**
293
+ * Updates the "previousVisitTime", "currentVisitTime" and "visitCount"
294
+ * fields based on the given session object.
295
+ *
296
+ * @param Session $session
297
+ */
298
+ public function addSession(Session $session) {
299
+ $startTime = $session->getStartTime();
300
+ if($startTime != $this->currentVisitTime) {
301
+ $this->previousVisitTime = $this->currentVisitTime;
302
+ $this->currentVisitTime = $startTime;
303
+ ++$this->visitCount;
304
+ }
305
+ }
306
+
307
+ /**
308
+ * @param DateTime $value
309
+ */
310
+ public function setFirstVisitTime(DateTime $value) {
311
+ $this->firstVisitTime = $value;
312
+ }
313
+
314
+ /**
315
+ * @return DateTime
316
+ */
317
+ public function getFirstVisitTime() {
318
+ return $this->firstVisitTime;
319
+ }
320
+
321
+ /**
322
+ * @param DateTime $value
323
+ */
324
+ public function setPreviousVisitTime(DateTime $value) {
325
+ $this->previousVisitTime = $value;
326
+ }
327
+
328
+ /**
329
+ * @return DateTime
330
+ */
331
+ public function getPreviousVisitTime() {
332
+ return $this->previousVisitTime;
333
+ }
334
+
335
+ /**
336
+ * @param DateTime $value
337
+ */
338
+ public function setCurrentVisitTime(DateTime $value) {
339
+ $this->currentVisitTime = $value;
340
+ }
341
+
342
+ /**
343
+ * @return DateTime
344
+ */
345
+ public function getCurrentVisitTime() {
346
+ return $this->currentVisitTime;
347
+ }
348
+
349
+ /**
350
+ * @param int $value
351
+ */
352
+ public function setVisitCount($value) {
353
+ $this->visitCount = (int)$value;
354
+ }
355
+
356
+ /**
357
+ * @return int
358
+ */
359
+ public function getVisitCount() {
360
+ return $this->visitCount;
361
+ }
362
+
363
+ /**
364
+ * @param string $value
365
+ */
366
+ public function setIpAddress($value) {
367
+ $this->ipAddress = $value;
368
+ }
369
+
370
+ /**
371
+ * @return string
372
+ */
373
+ public function getIpAddress() {
374
+ return $this->ipAddress;
375
+ }
376
+
377
+ /**
378
+ * @param string $value
379
+ */
380
+ public function setUserAgent($value) {
381
+ $this->userAgent = $value;
382
+ }
383
+
384
+ /**
385
+ * @return string
386
+ */
387
+ public function getUserAgent() {
388
+ return $this->userAgent;
389
+ }
390
+
391
+ /**
392
+ * @param string $value
393
+ */
394
+ public function setLocale($value) {
395
+ $this->locale = $value;
396
+ }
397
+
398
+ /**
399
+ * @return string
400
+ */
401
+ public function getLocale() {
402
+ return $this->locale;
403
+ }
404
+
405
+ /**
406
+ * @param string $value
407
+ */
408
+ public function setFlashVersion($value) {
409
+ $this->flashVersion = $value;
410
+ }
411
+
412
+ /**
413
+ * @return string
414
+ */
415
+ public function getFlashVersion() {
416
+ return $this->flashVersion;
417
+ }
418
+
419
+ /**
420
+ * @param bool $value
421
+ */
422
+ public function setJavaEnabled($value) {
423
+ $this->javaEnabled = (bool)$value;
424
+ }
425
+
426
+ /**
427
+ * @return bool
428
+ */
429
+ public function getJavaEnabled() {
430
+ return $this->javaEnabled;
431
+ }
432
+
433
+ /**
434
+ * @param int $value
435
+ */
436
+ public function setScreenColorDepth($value) {
437
+ $this->screenColorDepth = (int)$value;
438
+ }
439
+
440
+ /**
441
+ * @return string
442
+ */
443
+ public function getScreenColorDepth() {
444
+ return $this->screenColorDepth;
445
+ }
446
+
447
+ /**
448
+ * @param string $value
449
+ */
450
+ public function setScreenResolution($value) {
451
+ $this->screenResolution = $value;
452
+ }
453
+
454
+ /**
455
+ * @return string
456
+ */
457
+ public function getScreenResolution() {
458
+ return $this->screenResolution;
459
+ }
460
+
461
+ }
462
+
463
+ ?>
app/etc/modules/Sluice_Connect.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Sluice_Connect>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Sluice_Connect>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>sluice_connect</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.gnu.org/licenses/gpl.html">GPL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Integration tool for SluiceHQ</summary>
10
+ <description>This extension helps connect your Magento Store to SluiceHQ service. </description>
11
+ <notes>- Track add to cart event (via google analitics)&#xD;
12
+ - Give Magento data access to Sluice HQ (via Web Services)</notes>
13
+ <authors><author><name>Konstantin</name><user>flyb1z0n</user><email>flyb1z0n@gmail.com</email></author></authors>
14
+ <date>2013-05-06</date>
15
+ <time>10:50:12</time>
16
+ <contents><target name="magelocal"><dir name="Sluice"><dir name="Connect"><dir name="Helper"><file name="Data.php" hash="72f7af6ab8f4dd94d7e0d56f2355e84a"/></dir><dir name="Model"><file name="Observer.php" hash="9bcc39b07c303b0bf3b62e67a411356e"/></dir><dir name="etc"><file name="config.xml" hash="a0d266785b3068b867d5110c7df8b397"/><file name="system.xml" hash="7c00c55ed5ec73bc35df97d4781ca4bd"/></dir><dir name="lib"><dir name="GoogleAnalytics"><file name="Campaign.php" hash="a56c9b002352e6fa2232adae0621931e"/><file name="Config.php" hash="5229e50ead3b5e28bd766db1c9a612d1"/><file name="CustomVariable.php" hash="179416f069ce3e75ddabffc6b7fe057c"/><file name="Event.php" hash="636e6f4bcca8399bfda862aceda45c8a"/><file name="Exception.php" hash="50417068da38cefd83e3d92119a20dbc"/><dir name="Internals"><file name="ParameterHolder.php" hash="4ab0b166482aae049fc56f574c6a64dd"/><dir name="Request"><file name="EventRequest.php" hash="8cb97231147c6c63f0c7aab693fae7fe"/><file name="HttpRequest.php" hash="9c0510decfa0c14aa5df014913ba8aae"/><file name="ItemRequest.php" hash="a44f5de031847018c9789274c253478b"/><file name="PageviewRequest.php" hash="d73996f2f96f9174c166edda36141157"/><file name="Request.php" hash="73fedf67146a6395b02f4f56a06df8b9"/><file name="SocialInteractionRequest.php" hash="0f67db29fd409fcf6fb5fbb5693f3d6a"/><file name="TransactionRequest.php" hash="1a3439aa5d914d2c6307722fd1e2bfe2"/></dir><file name="Util.php" hash="25e6f65af8552688b1324a0876cad8bb"/><file name="X10.php" hash="0e8b98f4bec17fd09cb5ff2fce8a06e8"/></dir><file name="Item.php" hash="152bb655f2dd8b891bc8e4f0e0df2d4f"/><file name="Page.php" hash="74e153d1142aec38c1e610367855d545"/><file name="Session.php" hash="4ea6c25a797857fd7160926cc596551a"/><file name="SocialInteraction.php" hash="bf9ac557daf775fe0b8e7885af3506b3"/><file name="Tracker.php" hash="23b282b473b56e8e9dc232b1042fe467"/><file name="Transaction.php" hash="9b13d60b9fd50c858ef2757d114aaa93"/><file name="Visitor.php" hash="0db07b945ac96bc0abe88cfb52ae8e34"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Sluice_Connect.xml" hash="87aa6be6cfdc5eea59f2033098c8fe78"/></dir></target></contents>
17
+ <compatible/>
18
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.6.0.0</min><max>1.7</max></package></required></dependencies>
19
+ </package>