Stetic_Ecommerce_Analytics - Version 1.0.1

Version Notes

First release

Download this release

Release Info

Developer Stetic
Extension Stetic_Ecommerce_Analytics
Version 1.0.1
Comparing to
See all releases


Version 1.0.1

README.md ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Stetic Magento Extension
2
+
3
+ With this extension you can add the powerful Web and Ecommerce Analytics from Stetic to your Magento store.
4
+ It will integrate the tracking code to track pageviews and all actions a visitor or customer will take.
5
+ Logged-in users will be identified and pushed to Stetic for further analysis.
6
+ You can enable or disable all individual events in the extension settings.
7
+
8
+ ## Installation
9
+
10
+ Just copy the app folder to your Magento root folder. Alternatively you can do a direct package file upload in your Magento Connect Manager.
11
+
12
+
13
+ ### Event Tracking - List of actions tracked
14
+
15
+ The following actions can be tracked with this extension:
16
+
17
+ - Shopping Cart actions
18
+ - Orders
19
+ - Wishlist actions
20
+ - Send Friend
21
+ - Search
22
+ - Contact form
23
+ - Newsletter
24
+ - Product review
25
+ - Product compare
26
+ - Account creation
27
+ - Login and Logout
28
+ - Account actions
29
+ - Forgot Password
30
+ - 404 page Not Found
31
+
32
+
33
+ Note: You have to be registered with Stetic to use this extension.
34
+
app/code/community/Stetic/Analytics/Block/Tracker.php ADDED
@@ -0,0 +1,775 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Stetic Analytics Magento Extension
5
+ *
6
+ * @category Stetic
7
+ * @package Stetic_Analytics
8
+ * @copyright Copyright (c) 2014 Stetic (http://www.stetic.com/)
9
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
10
+ */
11
+
12
+ class Stetic_Analytics_Block_Tracker extends Mage_Core_Block_Template
13
+ {
14
+ /**
15
+ * Constructor
16
+ */
17
+ public function _construct()
18
+ {
19
+ parent::_construct();
20
+
21
+ if(Mage::helper('Stetic')->isEnabled() == true)
22
+ {
23
+ $this->setTemplate('stetic/tracker.phtml');
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Returns whenever this extension is enabled or disabled.
29
+ *
30
+ * @return bool
31
+ */
32
+ public function isEnabled()
33
+ {
34
+ return Mage::helper('Stetic')->isEnabled();
35
+ }
36
+
37
+ /**
38
+ * Returns site token from config
39
+ *
40
+ * @return string
41
+ */
42
+ public function getSiteToken()
43
+ {
44
+ return Mage::helper('Stetic')->getSiteToken();
45
+ }
46
+
47
+ /**
48
+ * Returns cookie domain from config
49
+ *
50
+ * @return string
51
+ */
52
+ public function getCookieDomain()
53
+ {
54
+ return Mage::helper('Stetic')->getCookieDomain();
55
+ }
56
+
57
+ /**
58
+ * Returns whenever order tracking is enabled or disabled.
59
+ *
60
+ * @return string
61
+ */
62
+ public function isOrderTrackingEnabled()
63
+ {
64
+ return ($this->isEnabled() && self::getConfig('advanced/order_tracking'));
65
+ }
66
+
67
+ /**
68
+ * Identify customers
69
+ *
70
+ * @return string
71
+ */
72
+ public function identify()
73
+ {
74
+ if(self::getConfig('advanced/identify_loggedin') && Mage::getSingleton('customer/session')->isLoggedIn())
75
+ {
76
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
77
+ if($customer)
78
+ {
79
+ $identify = array(
80
+ 'id' => $customer->getId(),
81
+ 'name' => $customer->getName(),
82
+ 'email' => $customer->getEmail(),
83
+ 'created_at' => date("Y-m-d H:i:s", $customer->getCreatedAtTimestamp()),
84
+ );
85
+
86
+ if(!$address = $customer->getDefaultBillingAddress())
87
+ {
88
+ $address = $customer->getDefaultShippingAddress();
89
+ }
90
+
91
+ if($address)
92
+ {
93
+ /***
94
+ * Check whenever customers from specific countries should be excluded
95
+ */
96
+ if(self::getConfig('advanced/identify_loggedin_disallow_specific'))
97
+ {
98
+ $disabled_countries = explode(",", self::getConfig('advanced/identify_loggedin_disallow_specificcountry'));
99
+ if(!empty($disabled_countries) && $address->getCountryId() && in_array($address->getCountryId(), $disabled_countries))
100
+ {
101
+ //self::log("Disabled country " . $address->getCountryId(), null, 'stetic.log');
102
+ return '';
103
+ }
104
+ }
105
+
106
+ $identify['company'] = $address->getCompany();
107
+ $identify['phone'] = $address->getTelephone();
108
+ $identify['city'] = $address->getCity();
109
+ $identify['country'] = $address->getCountryId();
110
+ }
111
+ return '_fss.identify = ' . json_encode($identify) . ';' . PHP_EOL;
112
+ }
113
+ }
114
+ return '';
115
+ }
116
+
117
+ /**
118
+ * Event tracking functions
119
+ *
120
+ * @return string
121
+ */
122
+ public function trackEvents()
123
+ {
124
+ if($triggers = Mage::getSingleton('core/session')->getData('stetic_event_trigger'))
125
+ {
126
+ // Unset used trigger
127
+ Mage::getSingleton('core/session')->unsetData('stetic_event_trigger');
128
+
129
+ $html_result = array();
130
+
131
+ foreach($triggers as $trigger)
132
+ {
133
+ $action = $trigger["action"];
134
+ $request = $trigger["request"];
135
+
136
+ //self::log($action, $trigger);
137
+
138
+ /***
139
+ * Cart add
140
+ */
141
+ if( $action == 'checkout_cart_add' && self::getConfig('advanced/cart_tracking') )
142
+ {
143
+ $product_id = $request['product'];
144
+
145
+ if($product_id && $product_data = $this->get_product_from_request($product_id, $request))
146
+ {
147
+ $product_data['quantity'] = ($request['qty']) ? (int)$request['qty'] : 1;
148
+
149
+ if(self::getConfig('advanced/track_products_with_options') && !empty($request['super_attribute']) )
150
+ {
151
+ $product = Mage::getModel('catalog/product')->load($product_id);
152
+ $child_product = Mage::getModel('catalog/product_type_configurable')->getProductByAttributes($request['super_attribute'], $product);
153
+
154
+ if($child_product && $child_product->getId())
155
+ {
156
+ $attributes = $child_product->getAttributes();
157
+
158
+ if($attributes && !empty($attributes))
159
+ {
160
+ $product_data['options'] = array();
161
+ foreach ($attributes as $attribute)
162
+ {
163
+ if ($attribute->getIsUserDefined() && $attribute->getIsVisibleOnFront() && $attribute->getIsConfigurable())
164
+ {
165
+ $label = $attribute->getFrontend()->getLabel($child_product);
166
+ $value = $attribute->getFrontend()->getValue($child_product);
167
+ $product_data['options'][$label] = $value;
168
+ }
169
+ }
170
+ }
171
+ }
172
+ }
173
+
174
+
175
+ $html_result[] = $this->trackEvent('basket', array("product" => $product_data));
176
+ }
177
+ }
178
+ /***
179
+ * Cart delete
180
+ */
181
+ elseif( $action == 'checkout_cart_delete' && self::getConfig('advanced/cart_tracking') )
182
+ {
183
+ if($product_id = $trigger["product_id"])
184
+ {
185
+ $quantity = (isset($trigger['quantity'])) ? (int)$trigger['quantity'] : 1;
186
+ $request['qty'] = $quantity;
187
+
188
+ if($product_data = $this->get_product_from_request($product_id, $request))
189
+ {
190
+ if(self::getConfig('advanced/track_products_with_options'))
191
+ {
192
+ if($options = $trigger['options'])
193
+ {
194
+ $product_data['quantity'] = $quantity;
195
+
196
+ $product_data['options'] = array();
197
+ foreach ($options['attributes_info'] as $option)
198
+ {
199
+ $product_data['options'][$option['label']] = $option['value'];
200
+ }
201
+
202
+ if($product_data['price'] == 0 && $options['bundle_options'] && is_array($options['bundle_options']))
203
+ {
204
+ $price = 0;
205
+ foreach($options['bundle_options'] as $bundle_option)
206
+ {
207
+ if($bundle_option['value'] && is_array($bundle_option['value']))
208
+ {
209
+ foreach($bundle_option['value'] as $value)
210
+ {
211
+ if(isset($value['price']))
212
+ {
213
+ $qty = ($value['qty']) ? (int)$value['qty'] : 1;
214
+ $price += ($qty*(float)$value['price']);
215
+ }
216
+ }
217
+ }
218
+ }
219
+ $product_data['price'] = $price;
220
+ }
221
+ }
222
+ }
223
+
224
+ $html_result[] = $this->trackEvent('basket_remove', array("product" => $product_data));
225
+ }
226
+ }
227
+ }
228
+ /***
229
+ * Cart coupon post
230
+ */
231
+ elseif( $action == 'checkout_cart_couponPost' && self::getConfig('advanced/cart_tracking') )
232
+ {
233
+ $coupon = Mage::getModel('salesrule/coupon')->load($request['coupon_code'], 'code');
234
+
235
+ $event = ($request['remove']) ? 'coupon_remove' : 'coupon';
236
+ $status = 'invalid';
237
+
238
+ $event_properties = array(
239
+ 'code' => $request['coupon_code'],
240
+ 'status' => $status,
241
+ );
242
+
243
+ if($coupon && $coupon->getCouponId())
244
+ {
245
+ $quote = Mage::getSingleton('checkout/cart')->getQuote();
246
+ $used_coupon_code = $quote->getCouponCode();
247
+ $event_properties['status'] = ($used_coupon_code == $request['coupon_code']) ? 'valid' : 'invalid';
248
+
249
+ $rule = Mage::getModel('salesrule/rule')->load($coupon->getRuleId());
250
+ if($rule && $rule->getRuleId())
251
+ {
252
+ $rule_data = $rule->getData();
253
+ $event_properties['name'] = $rule_data['name'];
254
+ }
255
+ }
256
+
257
+
258
+ $html_result[] = $this->trackEvent($event, $event_properties);
259
+ }
260
+ /***
261
+ * Cart estimate post
262
+ */
263
+ elseif( $action == 'checkout_cart_estimatePost' && self::getConfig('advanced/cart_tracking') )
264
+ {
265
+ $country = Mage::getModel('directory/country')->load($request['country_id']);
266
+ $region = Mage::getModel('directory/region')->load($request['region_id']);
267
+
268
+ $html_result[] = $this->trackEvent('basket_estimate_shipping', array(
269
+ 'country' => $country->getName(),
270
+ 'region' => $region->getName(),
271
+ 'zip' => $request['estimate_postcode'],
272
+ 'city' => $request['estimate_city'],
273
+ ));
274
+ }
275
+ /***
276
+ * Cart update
277
+ */
278
+ elseif( $action == 'checkout_cart_updatePost' && self::getConfig('advanced/cart_tracking') )
279
+ {
280
+ $html_result[] = $this->trackEvent('basket_update');
281
+ }
282
+ /***
283
+ * Checkout index
284
+ */
285
+ elseif( $action == 'checkout_onepage_index' && $this->isOrderTrackingEnabled() )
286
+ {
287
+ $html_result[] = $this->trackEvent('checkout_index');
288
+ }
289
+ /***
290
+ * Checkout success
291
+ */
292
+ elseif( ($action == 'checkout_onepage_saveOrder' || $action == 'checkout_onepage_savePayment' || $action == 'checkout_multishipping_success' || $action == 'checkoutMultishippingControllerSuccessAction') && $this->isOrderTrackingEnabled() )
293
+ {
294
+ $orderIds = array();
295
+ /***
296
+ * Multishipping can have more than one id
297
+ */
298
+ if($action == 'checkoutMultishippingControllerSuccessAction')
299
+ {
300
+ $orderIds = $request['order_ids'];
301
+ }
302
+ if(empty($orderIds))
303
+ {
304
+ $orderIds = array(Mage::getSingleton('checkout/session')->getLastOrderId());
305
+ }
306
+
307
+ $collection = Mage::getResourceModel('sales/order_collection')->addFieldToFilter('entity_id', array('in' => $orderIds));
308
+ $result = array();
309
+
310
+ foreach ($collection as $order)
311
+ {
312
+ $order_properties = array(
313
+ "id" => $order->getIncrementId(),
314
+ "total" => (float)$order->getGrandTotal(),
315
+ "sub_total" => (float)$order->getSubtotal(),
316
+ "coupon" => (string)$order->getCouponCode(),
317
+ "quantity" => (int)$order->getTotalQtyOrdered(),
318
+ "weight" => (float)$order->getWeight(),
319
+ "discount" => (float)$order->getDiscountAmount(),
320
+ "shipping" => array("type" => $order->getShippingDescription(), "amount" => (float)$order->getShippingAmount()),
321
+ );
322
+
323
+ if($payment = $order->getPayment()->getMethodInstance())
324
+ {
325
+ if($payment_amount = $payment->getAmount())
326
+ {
327
+ $order_properties['payment'] = array("type" => $payment->getTitle(), "amount" => (float)$payment_amount);
328
+ }
329
+ else
330
+ {
331
+ $order_properties['payment'] = $payment->getTitle();
332
+ }
333
+ }
334
+
335
+ $total_revenue = (float)$order->getSubtotal()+(float)$order->getDiscountAmount();
336
+
337
+ $products = array();
338
+ $order_items = $order->getAllVisibleItems();
339
+
340
+ foreach($order_items as $item_id => $item)
341
+ {
342
+ $product = Mage::getModel("catalog/product")->load($item->getProductId());
343
+ $quantity = ((int)$item->getQtyOrdered() > 0) ? (int)$item->getQtyOrdered() : 1;
344
+ $cost = $product->getCost();
345
+ $total_revenue -= $cost;
346
+
347
+ $categories = array();
348
+ $category_ids = $product->getCategoryIds();
349
+ foreach($category_ids as $category_id)
350
+ {
351
+ $category = Mage::getModel('catalog/category')->load($category_id) ;
352
+ $categories[] = $category->getName();
353
+ }
354
+
355
+ $product_for_products = array(
356
+ "id" => $item->getProductId(),
357
+ "name" => $item->getName(),
358
+ "sku" => $item->getSku(),
359
+ "quantity" => (int)$item->getQtyOrdered(),
360
+ "price" => (float)$item->getPrice(),
361
+ "cost" => (float)$cost,
362
+ "revenue" => (float)(($item->getPrice()-$cost)*$quantity),
363
+ "category" => $categories,
364
+ );
365
+
366
+ /***
367
+ * We have a configurable product
368
+ */
369
+ if($product->getTypeId() == 'configurable')
370
+ {
371
+ if($product_options = $item->getProductOptions())
372
+ {
373
+ /***
374
+ * Add options to order product if enabled in settings
375
+ */
376
+ if(self::getConfig('advanced/track_products_with_options'))
377
+ {
378
+ $product_for_products['options'] = array();
379
+ foreach ($product_options['attributes_info'] as $option)
380
+ {
381
+ $product_for_products['options'][$option['label']] = $option['value'];
382
+ }
383
+ }
384
+ }
385
+ }
386
+
387
+ $products[] = $product_for_products;
388
+ }
389
+
390
+ $order_properties['products'] = $products;
391
+ $order_properties['revenue'] = (float)$total_revenue;
392
+
393
+ $html_result[] = $this->trackEvent('order', $order_properties);
394
+ }
395
+ }
396
+ /***
397
+ * Reorder
398
+ */
399
+ elseif( $action == 'sales_order_reorder' && $this->isOrderTrackingEnabled() )
400
+ {
401
+ $html_result[] = $this->trackEvent('reorder', array('order_id' => $request['order_id']));
402
+ }
403
+ /***
404
+ * Order print
405
+ */
406
+ elseif( $action == 'sales_order_print' && $this->isOrderTrackingEnabled() )
407
+ {
408
+ $html_result[] = $this->trackEvent('order_print', array('order_id' => $request['order_id']));
409
+ }
410
+ /***
411
+ * Wishlist add
412
+ */
413
+ elseif( $action == 'wishlist_index_add' && self::getConfig('advanced/wishlist_tracking') && $request && $request['product'] )
414
+ {
415
+ if($product_data = $this->get_product_from_request($request['product'], $request))
416
+ {
417
+ $html_result[] = $this->trackEvent('wishlist', array("product" => $product_data));
418
+ }
419
+ }
420
+ /***
421
+ * Wishlist delete
422
+ */
423
+ elseif( $action == 'wishlist_index_remove' && self::getConfig('advanced/wishlist_tracking') && $request)
424
+ {
425
+ $product_id = $trigger['product_id'];
426
+
427
+ if($product_id && $product_data = $this->get_product_from_request($product_id, $request))
428
+ {
429
+ $html_result[] = $this->trackEvent('wishlist_remove', array("product" => $product_data));
430
+ }
431
+ }
432
+ /***
433
+ * Wishlist to cart
434
+ */
435
+ elseif( $action == 'wishlist_index_cart' && self::getConfig('advanced/wishlist_tracking') && $request)
436
+ {
437
+ $product_id = $trigger['product_id'];
438
+
439
+ if($product_id && $product_data = $this->get_product_from_request($product_id, $request))
440
+ {
441
+ $html_result[] = $this->trackEvent('wishlist_cart', array("product" => $product_data));
442
+ }
443
+ }
444
+ /***
445
+ * Wishlist update
446
+ */
447
+ elseif( $action == 'wishlist_index_update' && self::getConfig('advanced/wishlist_tracking') && $request)
448
+ {
449
+ $html_result[] = $this->trackEvent('wishlist_update');
450
+ }
451
+ /***
452
+ * Compare add
453
+ */
454
+ elseif( $action == 'catalog_product_compare_add' && self::getConfig('advanced/product_compare_tracking') && $request && $request['product'] )
455
+ {
456
+ if($product_data = $this->get_product_from_request($request['product'], $request))
457
+ {
458
+ $html_result[] = $this->trackEvent('compare', array("product" => $product_data));
459
+ }
460
+ }
461
+ /***
462
+ * Compare delete
463
+ */
464
+ elseif( $action == 'catalog_product_compare_remove' && self::getConfig('advanced/product_compare_tracking') && $request && $request['product'] )
465
+ {
466
+ if($product_data = $this->get_product_from_request($request['product'], $request))
467
+ {
468
+ $html_result[] = $this->trackEvent('compare_remove', array("product" => $product_data));
469
+ }
470
+ }
471
+ /***
472
+ * Sendfriend
473
+ */
474
+ elseif( $action == 'sendfriend_product_sendmail' && self::getConfig('advanced/sendfriend_tracking') )
475
+ {
476
+ $product_id = $request['id'];
477
+
478
+ if($product_id && $product_data = $this->get_product_from_request($product_id, $request))
479
+ {
480
+ $html_result[] = $this->trackEvent('sendfriend', array("product" => $product_data));
481
+ }
482
+ }
483
+ /***
484
+ * Account create view
485
+ */
486
+ /*
487
+ elseif( $action == 'customer_account_create' && self::getConfig('advanced/account_create_tracking') )
488
+ {
489
+ $html_result[] = $this->trackEvent('account_create_view');
490
+ }
491
+ */
492
+ /***
493
+ * Account create post
494
+ */
495
+ elseif( $action == 'customer_account_createpost' && self::getConfig('advanced/account_create_tracking') )
496
+ {
497
+ $html_result[] = $this->trackEvent('account_create', array(
498
+ 'firstname' => $request['firstname'],
499
+ 'lastname' => $request['lastname'],
500
+ 'email' => $request['email'],
501
+ 'newsletter' => (bool)($request['is_subscribed']),
502
+ ));
503
+
504
+ if( (bool)$request['is_subscribed'] === true )
505
+ {
506
+ $html_result[] = $this->trackEvent('newsletter_subscribe', array(
507
+ 'email' => $request['email'],
508
+ ));
509
+ }
510
+ }
511
+ /***
512
+ * Login
513
+ */
514
+ elseif( $action == 'customer_account_loginPost' && self::getConfig('advanced/login_tracking') )
515
+ {
516
+ $username = (isset($request['login']) && isset($request['login']['username'])) ? $request['login']['username'] : '';
517
+ if( Mage::getSingleton('customer/session')->isLoggedIn() )
518
+ {
519
+ $event = 'login';
520
+ }
521
+ else
522
+ {
523
+ $event = 'login_failed';
524
+ }
525
+ $html_result[] = $this->trackEvent($event, array('username' => $username));
526
+ }
527
+ /***
528
+ * Logout
529
+ */
530
+ elseif( $action == 'customer_account_logoutSuccess' && self::getConfig('advanced/login_tracking') )
531
+ {
532
+ $html_result[] = $this->trackEvent('logout');
533
+ }
534
+ /***
535
+ * Forgot password post
536
+ */
537
+ elseif( $action == 'customer_account_forgotpasswordpost' && self::getConfig('advanced/forgot_password_tracking') )
538
+ {
539
+ $html_result[] = $this->trackEvent('forgot password', array("email" => $request['email']));
540
+ }
541
+ /***
542
+ * Reset password post
543
+ */
544
+ elseif( $action == 'customer_account_resetpasswordpost' && self::getConfig('advanced/forgot_password_tracking') )
545
+ {
546
+ $html_result[] = $this->trackEvent('reset_password');
547
+ }
548
+ /***
549
+ * Change password
550
+ */
551
+ elseif( $action == 'customer_account_editPost' && self::getConfig('advanced/account_actions_tracking') )
552
+ {
553
+ if( $request['change_password'] && $request['password'] != $request['current_password'] && $request['password'] == $request['confirmation'] )
554
+ {
555
+ $html_result[] = $this->trackEvent('change_password');
556
+ }
557
+ }
558
+ /***
559
+ * New and update address
560
+ */
561
+ elseif( $action == 'customer_address_formPost' && self::getConfig('advanced/account_actions_tracking') )
562
+ {
563
+ $html_result[] = $this->trackEvent('address_action');
564
+ }
565
+ /***
566
+ * 404
567
+ */
568
+ elseif( $action == 'cms_index_noRoute' && self::getConfig('advanced/no_route_tracking') )
569
+ {
570
+ $html_result[] = $this->trackEvent('404', array(
571
+ 'url' => Mage::helper('core/url')->getCurrentUrl(),
572
+ 'referer' => Mage::helper('core/http')->getHttpReferer(),
573
+ ));
574
+ }
575
+ /***
576
+ * Search
577
+ */
578
+ elseif( $action == 'catalogsearch_result_index' && self::getConfig('advanced/search_tracking') )
579
+ {
580
+ $html_result[] = $this->trackEvent('search', array(
581
+ 'query' => $request['q'],
582
+ ));
583
+ }
584
+ /***
585
+ * Search avanced
586
+ */
587
+ elseif( $action == 'catalogsearch_advanced_result' && self::getConfig('advanced/search_tracking') )
588
+ {
589
+ $advanced_search = Mage::getModel("catalogsearch/advanced")->addFilters($request);
590
+
591
+ if($advanced_search && $search_criterias = $advanced_search->getSearchCriterias())
592
+ {
593
+ $criterias = array();
594
+ foreach($search_criterias as $criteria)
595
+ {
596
+ $criterias[$criteria['name']] = $criteria['value'];
597
+ }
598
+ $html_result[] = $this->trackEvent('search_advanced', array(
599
+ 'criterias' => $criterias,
600
+ ));
601
+ }
602
+ }
603
+ /***
604
+ * Contact form post
605
+ */
606
+ elseif( $action == 'contacts_index_post' && self::getConfig('advanced/contact_form_tracking') )
607
+ {
608
+ $html_result[] = $this->trackEvent('contact_form', array(
609
+ 'name' => $request['name'],
610
+ 'email' => $request['email'],
611
+ 'phone' => $request['telephone'],
612
+ 'comment' => $request['comment'],
613
+ ));
614
+ }
615
+ /***
616
+ * Newsletter actions
617
+ */
618
+ elseif( $action == 'newsletterSubscriberSaveAfter' && self::getConfig('advanced/newsletter_tracking') && $trigger['status_change'] == true )
619
+ {
620
+ $event = ($request['subscriber_status'] == Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED) ? 'unsubscribe' : 'subscribe';
621
+
622
+ $html_result[] = $this->trackEvent('newsletter_' . $event, array(
623
+ 'email' => $request['subscriber_email'],
624
+ ));
625
+ }
626
+ /***
627
+ * product review post
628
+ */
629
+ elseif( $action == 'review_product_post' && self::getConfig('advanced/product_review_tracking') )
630
+ {
631
+ $event_ratings = array();
632
+
633
+ foreach ($request['ratings'] as $ratingId => $optionId)
634
+ {
635
+ $rating = Mage::getModel('rating/rating')->load($ratingId);
636
+ $rating_option = Mage::getModel('rating/rating_option')->load($optionId);
637
+ $event_ratings[$rating->getRatingCode()] = $rating_option->getValue() . "/5";
638
+ }
639
+
640
+ $html_result[] = $this->trackEvent('product_review', array(
641
+ 'nickname' => $request['nickname'],
642
+ 'title' => $request['title'],
643
+ 'comment' => $request['detail'],
644
+ 'ratings' => $event_ratings
645
+ ));
646
+ }
647
+
648
+ }
649
+
650
+ return implode("\n", $html_result);
651
+ }
652
+ }
653
+
654
+ /**
655
+ * Returns html for block to track given event
656
+ *
657
+ * @param string $event
658
+ * @param array $properties
659
+ * @return string
660
+ */
661
+ protected function trackEvent($event, $properties = array())
662
+ {
663
+ $html = "stetic.track('{$event}'";
664
+ if(is_array($properties) && !empty($properties))
665
+ {
666
+ $html .= ", " . json_encode($properties);
667
+ }
668
+ $html .= ");";
669
+ return $html . PHP_EOL;
670
+ }
671
+
672
+ /**
673
+ * Get event properties for a product id
674
+ *
675
+ * @param string $product_id
676
+ * @return mixed
677
+ */
678
+ protected function get_product_from_request($product_id, $request = false)
679
+ {
680
+ if($product_object = Mage::getModel('catalog/product')->load($product_id))
681
+ {
682
+ $product = $product_object->getData();
683
+ $categories = array();
684
+ $category_ids = $product_object->getCategoryIds();
685
+ foreach($category_ids as $category_id)
686
+ {
687
+ $category = Mage::getModel('catalog/category')->load($category_id) ;
688
+ $categories[] = $category->getName();
689
+ }
690
+
691
+ $result_product = array(
692
+ "id" => $product_id,
693
+ "name" => $product['name'],
694
+ "sku" => $product['sku'],
695
+ "price" => (float)$this->get_product_price($product_object, $request),
696
+ "category" => $categories
697
+ );
698
+
699
+ return $result_product;
700
+ }
701
+
702
+ return false;
703
+ }
704
+
705
+
706
+ /**
707
+ * Returns product price for various product types
708
+ *
709
+ * @param Mage_Catalog_Model_Product $product
710
+ * @param array $request
711
+ * @return string
712
+ */
713
+ public function get_product_price($product, $request = false)
714
+ {
715
+ if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE && $request && $request['bundle_option'])
716
+ {
717
+ $selectionCollection = $product->getTypeInstance(true)->getSelectionsCollection(
718
+ array_keys($request['bundle_option']), $product
719
+ );
720
+
721
+ $price = 0;
722
+ $bundled_items = array();
723
+ foreach($selectionCollection as $option)
724
+ {
725
+ if( isset($request['bundle_option'][$option->getOptionId()]) && $request['bundle_option'][$option->getOptionId()] == $option->getSelectionId() )
726
+ {
727
+ $qty = $request['bundle_option_qty'][$option->getOptionId()];
728
+ if(!$qty)
729
+ {
730
+ $qty = 1;
731
+ }
732
+ $price += $option->getPrice()*1;
733
+ $bundled_items[] = array($option->product_id, $option->getOptionId(), $option->getSelectionId(), $option->getPrice());
734
+ }
735
+ }
736
+ return $price;
737
+
738
+ }
739
+ elseif($request['qty'] && (int)$request['qty'] > 1)
740
+ {
741
+ return $product->getTierPrice((int)$request['qty']);
742
+ }
743
+ elseif($product->getFinalPrice())
744
+ {
745
+ return $product->getFinalPrice();
746
+ }
747
+ else
748
+ {
749
+ return 0.00;
750
+ }
751
+ }
752
+
753
+ /**
754
+ * Get configuration value
755
+ *
756
+ * @param string $key
757
+ * @return string
758
+ */
759
+ protected static function getConfig($key)
760
+ {
761
+ return Mage::helper('Stetic')->getConfig($key);
762
+ }
763
+
764
+ /**
765
+ * Log Helper
766
+ * Logs a message to var/log in foursatts namespace
767
+ *
768
+ * @param string $msg
769
+ */
770
+ protected static function log()
771
+ {
772
+ $messages = func_get_args();
773
+ Mage::log($messages, null, 'stetic.log');
774
+ }
775
+ }
app/code/community/Stetic/Analytics/Helper/Data.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Stetic Analytics Magento Extension
5
+ *
6
+ * @category Stetic
7
+ * @package Stetic_Analytics
8
+ * @copyright Copyright (c) 2014 Stetic (http://www.stetic.com/)
9
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
10
+ */
11
+
12
+ class Stetic_Analytics_Helper_Data extends Mage_Core_Helper_Data
13
+ {
14
+ /**
15
+ * Config XML path prefix
16
+ * @var string
17
+ */
18
+ const XML_PATH_PREFIX = 'stetic_analytics/';
19
+
20
+
21
+ public function isEnabled($store = null)
22
+ {
23
+ /**
24
+ * Enabled the extension if site token is available and the
25
+ * extention is enabled in settings.
26
+ */
27
+ $enabled = $this->getConfig('settings/enabled', $store);
28
+ $site_token = $this->getSiteToken($store);
29
+ return $enabled && $site_token;
30
+ }
31
+
32
+ public function getSiteToken($store = null)
33
+ {
34
+ return $this->getConfig('settings/site_token', $store);
35
+ }
36
+
37
+ public function getCookieDomain($store = null)
38
+ {
39
+ return $this->getConfig('settings/cookie_domain', $store);
40
+ }
41
+
42
+ /**
43
+ * Get store config from Mage
44
+ *
45
+ * @param string $$key
46
+ * @param string $store
47
+ * @return mixed
48
+ */
49
+ public function getConfig($key, $store = null)
50
+ {
51
+ return Mage::getStoreConfig(self::XML_PATH_PREFIX . $key, $store);
52
+ }
53
+ }
app/code/community/Stetic/Analytics/Model/Observer.php ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Stetic Analytics Magento Extension
5
+ *
6
+ * @category Stetic
7
+ * @package Stetic_Analytics
8
+ * @copyright Copyright (c) 2014 Stetic (http://www.stetic.com/)
9
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
10
+ */
11
+
12
+ class Stetic_Analytics_Model_Observer extends Varien_Event_Observer
13
+ {
14
+ /**
15
+ * Events to listen on controller action predispatch
16
+ */
17
+ private $trigger_actions = array(
18
+ "checkout_cart_add",
19
+ "checkout_cart_delete",
20
+ "checkout_cart_updatePost",
21
+ "checkout_cart_estimatePost",
22
+ "checkout_cart_couponPost",
23
+ "checkout_onepage_index",
24
+ "checkout_onepage_savePayment",
25
+ "checkout_onepage_saveOrder",
26
+ "checkout_multishipping_success",
27
+ "sales_order_reorder",
28
+ "sales_order_print",
29
+ "customer_account_create",
30
+ "customer_account_createpost",
31
+ "customer_account_editPost",
32
+ "customer_account_loginPost",
33
+ "customer_account_logoutSuccess",
34
+ "customer_account_forgotpasswordpost",
35
+ "customer_account_resetpasswordpost",
36
+ "customer_address_formPost",
37
+ "wishlist_index_add",
38
+ "wishlist_index_remove",
39
+ "wishlist_index_cart",
40
+ "wishlist_index_update",
41
+ "sendfriend_product_sendmail",
42
+ "catalog_product_compare_add",
43
+ "catalog_product_compare_remove",
44
+ "catalogsearch_result_index",
45
+ "catalogsearch_advanced_result",
46
+ "contacts_index_post",
47
+ "review_product_post",
48
+ "cms_index_noRoute",
49
+ );
50
+
51
+ /**
52
+ * Controller Action Predispatch Observer
53
+ *
54
+ * @param Varien_Event_Observer $observer
55
+ */
56
+ public function controllerActionPredispatch(Varien_Event_Observer $observer)
57
+ {
58
+ $request = $observer->getEvent()->getControllerAction()->getRequest()->getParams();
59
+ $action = $observer->getEvent()->getControllerAction()->getFullActionName();
60
+
61
+ if(in_array($action, $this->trigger_actions))
62
+ {
63
+ $trigger = array("action" => $action, "request" => $request);
64
+
65
+ if($action == 'checkout_cart_delete')
66
+ {
67
+ $item = Mage::getModel('checkout/cart')->getQuote()->getItemById($request['id']);
68
+ $trigger['product_id'] = $item->getProduct()->getId();
69
+ $trigger['options'] = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
70
+ $trigger['quantity'] = $item->getQty();
71
+ }
72
+ elseif($action == 'wishlist_index_remove' || $action == 'wishlist_index_cart')
73
+ {
74
+ $trigger['product_id'] = Mage::getModel('wishlist/item')->load($request['item'])->getProduct()->getId();
75
+ }
76
+
77
+ $this->_addTrigger($trigger);
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Checkout Multishipping Controller Success Action Observer
83
+ *
84
+ * @param Varien_Event_Observer $observer
85
+ */
86
+ public function checkoutMultishippingControllerSuccessAction(Varien_Event_Observer $observer)
87
+ {
88
+ $data = $observer->getData();
89
+
90
+ $this->_addTrigger(array(
91
+ 'action' => 'checkoutMultishippingControllerSuccessAction',
92
+ 'request' => $data,
93
+ ));
94
+ }
95
+
96
+ /**
97
+ * Newsletter Subscriber Save After Observer
98
+ *
99
+ * @param Varien_Event_Observer $observer
100
+ */
101
+ public function newsletterSubscriberSaveAfter(Varien_Event_Observer $observer)
102
+ {
103
+ $event = $observer->getEvent();
104
+ $subscriber = $event->getDataObject();
105
+ $data = $subscriber->getData();
106
+
107
+ $this->_addTrigger(array(
108
+ 'action' => 'newsletterSubscriberSaveAfter',
109
+ 'request' => $data,
110
+ 'status_change' => $subscriber->getIsStatusChanged(),
111
+ ));
112
+ }
113
+
114
+ /**
115
+ * Adds a trigger
116
+ *
117
+ * @param array $trigger
118
+ */
119
+ private function _addTrigger($trigger)
120
+ {
121
+ $existing_triggers = Mage::getSingleton('core/session')->getData('stetic_event_trigger');
122
+ if(!$existing_triggers)
123
+ {
124
+ $existing_triggers = array();
125
+ }
126
+ $existing_triggers[] = $trigger;
127
+
128
+ Mage::getSingleton('core/session')->setData('stetic_event_trigger', $existing_triggers);
129
+ }
130
+ }
app/code/community/Stetic/Analytics/etc/config.xml ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Stetic Analytics Magento Extension
5
+ *
6
+ * @category Stetic
7
+ * @package Stetic_Analytics
8
+ * @copyright Copyright (c) 2014 Stetic (http://www.stetic.com/)
9
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
10
+ */
11
+ -->
12
+ <config>
13
+ <modules>
14
+ <Stetic_Analytics>
15
+ <version>0.1.0</version>
16
+ </Stetic_Analytics>
17
+ </modules>
18
+ <default>
19
+ <stetic_analytics>
20
+ <settings>
21
+ <enabled>1</enabled>
22
+ <site_token></site_token>
23
+ <api_key></api_key>
24
+ <cookie_domain></cookie_domain>
25
+ </settings>
26
+ <advanced>
27
+ <identify_loggedin>1</identify_loggedin>
28
+ <identify_loggedin_disallow_specific>0</identify_loggedin_disallow_specific>
29
+ <cart_tracking>1</cart_tracking>
30
+ <order_tracking>1</order_tracking>
31
+ <track_products_with_options>1</track_products_with_options>
32
+ <wishlist_tracking>1</wishlist_tracking>
33
+ <sendfriend_tracking>1</sendfriend_tracking>
34
+ <search_tracking>1</search_tracking>
35
+ <contact_form_tracking>1</contact_form_tracking>
36
+ <account_create_tracking>1</account_create_tracking>
37
+ <forgot_password_tracking>1</forgot_password_tracking>
38
+ <newsletter_tracking>1</newsletter_tracking>
39
+ <product_review_tracking>1</product_review_tracking>
40
+ <product_compare_tracking>1</product_compare_tracking>
41
+ <login_tracking>1</login_tracking>
42
+ <account_actions_tracking>1</account_actions_tracking>
43
+ <no_route_tracking>1</no_route_tracking>
44
+ </advanced>
45
+ </stetic_analytics>
46
+ </default>
47
+ <global>
48
+ <models>
49
+ <Stetic>
50
+ <class>Stetic_Analytics_Model</class>
51
+ </Stetic>
52
+ </models>
53
+ <blocks>
54
+ <Stetic>
55
+ <class>Stetic_Analytics_Block</class>
56
+ </Stetic>
57
+ </blocks>
58
+ <helpers>
59
+ <Stetic>
60
+ <class>Stetic_Analytics_Helper</class>
61
+ </Stetic>
62
+ </helpers>
63
+ </global>
64
+ <frontend>
65
+ <layout>
66
+ <updates>
67
+ <stetic>
68
+ <file>stetic.xml</file>
69
+ </stetic>
70
+ </updates>
71
+ </layout>
72
+ <events>
73
+ <controller_action_predispatch>
74
+ <observers>
75
+ <Stetic_Analytics_Model_Observer>
76
+ <class>Stetic/observer</class>
77
+ <method>controllerActionPredispatch</method>
78
+ </Stetic_Analytics_Model_Observer>
79
+ </observers>
80
+ </controller_action_predispatch>
81
+ <checkout_multishipping_controller_success_action>
82
+ <observers>
83
+ <Stetic_Analytics_Model_Observer>
84
+ <class>Stetic/observer</class>
85
+ <method>checkoutMultishippingControllerSuccessAction</method>
86
+ </Stetic_Analytics_Model_Observer>
87
+ </observers>
88
+ </checkout_multishipping_controller_success_action>
89
+ <newsletter_subscriber_save_after>
90
+ <observers>
91
+ <Stetic_Analytics_Model_Observer>
92
+ <class>Stetic/observer</class>
93
+ <method>newsletterSubscriberSaveAfter</method>
94
+ </Stetic_Analytics_Model_Observer>
95
+ </observers>
96
+ </newsletter_subscriber_save_after>
97
+ </events>
98
+ </frontend>
99
+ <adminhtml>
100
+ <acl>
101
+ <resources>
102
+ <admin>
103
+ <children>
104
+ <system>
105
+ <children>
106
+ <config>
107
+ <children>
108
+ <stetic_analytics>
109
+ <title>Stetic</title>
110
+ </stetic_analytics>
111
+ </children>
112
+ </config>
113
+ </children>
114
+ </system>
115
+ </children>
116
+ </admin>
117
+ </resources>
118
+ </acl>
119
+ </adminhtml>
120
+ </config>
app/code/community/Stetic/Analytics/etc/system.xml ADDED
@@ -0,0 +1,255 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Stetic Analytics Magento Extension
5
+ *
6
+ * @category Stetic
7
+ * @package Stetic_Analytics
8
+ * @copyright Copyright (c) 2014 Stetic (http://www.stetic.com/)
9
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
10
+ */
11
+ -->
12
+ <config>
13
+ <tabs>
14
+ <Stetic translate="label" module="Stetic">
15
+ <label>Stetic</label>
16
+ <sort_order>301</sort_order>
17
+ </Stetic>
18
+ </tabs>
19
+ <sections>
20
+ <stetic_analytics translate="label" module="Stetic">
21
+ <tab>Stetic</tab>
22
+ <label>Settings</label>
23
+ <sort_order>100</sort_order>
24
+ <show_in_default>1</show_in_default>
25
+ <show_in_website>1</show_in_website>
26
+ <show_in_store>1</show_in_store>
27
+ <groups>
28
+ <settings translate="label">
29
+ <label>Basic Settings</label>
30
+ <frontend_type>text</frontend_type>
31
+ <sort_order>100</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>1</show_in_website>
34
+ <show_in_store>1</show_in_store>
35
+ <expanded>1</expanded>
36
+ <fields>
37
+ <enabled translate="label">
38
+ <label>Enable Extension</label>
39
+ <comment>Enable or disable the Stetic extension.</comment>
40
+ <frontend_type>select</frontend_type>
41
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
42
+ <sort_order>10</sort_order>
43
+ <show_in_default>1</show_in_default>
44
+ <show_in_website>1</show_in_website>
45
+ <show_in_store>1</show_in_store>
46
+ </enabled>
47
+ <site_token translate="label">
48
+ <label>Site Token</label>
49
+ <comment>Your Site Token from stetic.com</comment>
50
+ <frontend_type>text</frontend_type>
51
+ <sort_order>11</sort_order>
52
+ <show_in_default>1</show_in_default>
53
+ <show_in_website>1</show_in_website>
54
+ <show_in_store>1</show_in_store>
55
+ </site_token>
56
+ </fields>
57
+ </settings>
58
+ <advanced translate="label">
59
+ <label>Advanced Settings</label>
60
+ <frontend_type>text</frontend_type>
61
+ <sort_order>101</sort_order>
62
+ <show_in_default>1</show_in_default>
63
+ <show_in_website>1</show_in_website>
64
+ <show_in_store>1</show_in_store>
65
+ <expanded>0</expanded>
66
+ <fields>
67
+ <identify_loggedin translate="label">
68
+ <label>Identify</label>
69
+ <comment>Identify logged in customers. Please pay attention to the data protection laws of your country.</comment>
70
+ <frontend_type>select</frontend_type>
71
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
72
+ <sort_order>1010</sort_order>
73
+ <show_in_default>1</show_in_default>
74
+ <show_in_website>1</show_in_website>
75
+ <show_in_store>1</show_in_store>
76
+ </identify_loggedin>
77
+ <identify_loggedin_disallow_specific translate="label">
78
+ <label>Identify - Exclude specific countries</label>
79
+ <comment>Enable whenever customers from specific countries should be excluded from identifying and transmission of personal data to Stetic. Based on customers address.</comment>
80
+ <frontend_type>select</frontend_type>
81
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
82
+ <sort_order>1020</sort_order>
83
+ <show_in_default>1</show_in_default>
84
+ <show_in_website>1</show_in_website>
85
+ <show_in_store>1</show_in_store>
86
+ <depends><identify_loggedin>1</identify_loggedin></depends>
87
+ </identify_loggedin_disallow_specific>
88
+ <identify_loggedin_disallow_specificcountry translate="label">
89
+ <label>Identify disabled countries</label>
90
+ <comment>Please select the countries from which customers should not be identified.</comment>
91
+ <frontend_type>multiselect</frontend_type>
92
+ <sort_order>1030</sort_order>
93
+ <source_model>adminhtml/system_config_source_country</source_model>
94
+ <show_in_default>1</show_in_default>
95
+ <show_in_website>1</show_in_website>
96
+ <show_in_store>1</show_in_store>
97
+ <can_be_empty>1</can_be_empty>
98
+ <depends><identify_loggedin_disallow_specific>1</identify_loggedin_disallow_specific></depends>
99
+ </identify_loggedin_disallow_specificcountry>
100
+ <cart_tracking translate="label">
101
+ <label>Cart Tracking</label>
102
+ <comment>Enable or disable shopping cart events. Required for Ecommerce Analytics.</comment>
103
+ <frontend_type>select</frontend_type>
104
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
105
+ <sort_order>1040</sort_order>
106
+ <show_in_default>1</show_in_default>
107
+ <show_in_website>1</show_in_website>
108
+ <show_in_store>1</show_in_store>
109
+ </cart_tracking>
110
+ <order_tracking translate="label">
111
+ <label>Order Tracking</label>
112
+ <comment>Enable or disable order events. Required for Ecommerce Analytics.</comment>
113
+ <frontend_type>select</frontend_type>
114
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
115
+ <sort_order>1050</sort_order>
116
+ <show_in_default>1</show_in_default>
117
+ <show_in_website>1</show_in_website>
118
+ <show_in_store>1</show_in_store>
119
+ </order_tracking>
120
+ <track_products_with_options translate="label">
121
+ <label>Products with options</label>
122
+ <comment>Track cart and orders with selected product options.</comment>
123
+ <frontend_type>select</frontend_type>
124
+ <source_model>adminhtml/system_config_source_yesno</source_model>
125
+ <sort_order>1060</sort_order>
126
+ <show_in_default>1</show_in_default>
127
+ <show_in_website>1</show_in_website>
128
+ <show_in_store>1</show_in_store>
129
+ </track_products_with_options>
130
+ <wishlist_tracking translate="label">
131
+ <label>Wishlist Tracking</label>
132
+ <comment>Enable or disable wishlist events.</comment>
133
+ <frontend_type>select</frontend_type>
134
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
135
+ <sort_order>1070</sort_order>
136
+ <show_in_default>1</show_in_default>
137
+ <show_in_website>1</show_in_website>
138
+ <show_in_store>1</show_in_store>
139
+ </wishlist_tracking>
140
+ <sendfriend_tracking translate="label">
141
+ <label>Send Friend Tracking</label>
142
+ <comment>Enable or disable tracking of products send to friends per email. Only product data will be tracked.</comment>
143
+ <frontend_type>select</frontend_type>
144
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
145
+ <sort_order>1071</sort_order>
146
+ <show_in_default>1</show_in_default>
147
+ <show_in_website>1</show_in_website>
148
+ <show_in_store>1</show_in_store>
149
+ </sendfriend_tracking>
150
+ <search_tracking translate="label">
151
+ <label>Search Tracking</label>
152
+ <comment>Enable or disable tracking of catalog searches.</comment>
153
+ <frontend_type>select</frontend_type>
154
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
155
+ <sort_order>1080</sort_order>
156
+ <show_in_default>1</show_in_default>
157
+ <show_in_website>1</show_in_website>
158
+ <show_in_store>1</show_in_store>
159
+ </search_tracking>
160
+ <contact_form_tracking translate="label">
161
+ <label>Contact form Tracking</label>
162
+ <comment>Enable or disable tracking of magento contact form. Includes submitted data in event.</comment>
163
+ <frontend_type>select</frontend_type>
164
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
165
+ <sort_order>1090</sort_order>
166
+ <show_in_default>1</show_in_default>
167
+ <show_in_website>1</show_in_website>
168
+ <show_in_store>1</show_in_store>
169
+ </contact_form_tracking>
170
+ <newsletter_tracking translate="label">
171
+ <label>Newsletter Tracking</label>
172
+ <comment>Enable or disable tracking of newsletter subscribes and unsubscribes.</comment>
173
+ <frontend_type>select</frontend_type>
174
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
175
+ <sort_order>1100</sort_order>
176
+ <show_in_default>1</show_in_default>
177
+ <show_in_website>1</show_in_website>
178
+ <show_in_store>1</show_in_store>
179
+ </newsletter_tracking>
180
+ <product_review_tracking translate="label">
181
+ <label>Product review Tracking</label>
182
+ <comment>Enable or disable tracking of product reviews. Includes product data in event.</comment>
183
+ <frontend_type>select</frontend_type>
184
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
185
+ <sort_order>1110</sort_order>
186
+ <show_in_default>1</show_in_default>
187
+ <show_in_website>1</show_in_website>
188
+ <show_in_store>1</show_in_store>
189
+ </product_review_tracking>
190
+ <product_compare_tracking translate="label">
191
+ <label>Product compare Tracking</label>
192
+ <comment>Enable or disable tracking of product compares. Includes product data in event.</comment>
193
+ <frontend_type>select</frontend_type>
194
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
195
+ <sort_order>1120</sort_order>
196
+ <show_in_default>1</show_in_default>
197
+ <show_in_website>1</show_in_website>
198
+ <show_in_store>1</show_in_store>
199
+ </product_compare_tracking>
200
+ <account_create_tracking translate="label">
201
+ <label>Account creation Tracking</label>
202
+ <comment>Enable or disable tracking of account creation (page view and post events).</comment>
203
+ <frontend_type>select</frontend_type>
204
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
205
+ <sort_order>1130</sort_order>
206
+ <show_in_default>1</show_in_default>
207
+ <show_in_website>1</show_in_website>
208
+ <show_in_store>1</show_in_store>
209
+ </account_create_tracking>
210
+ <login_tracking translate="label">
211
+ <label>Login Tracking</label>
212
+ <comment>Enable or disable tracking of login and logout events.</comment>
213
+ <frontend_type>select</frontend_type>
214
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
215
+ <sort_order>1140</sort_order>
216
+ <show_in_default>1</show_in_default>
217
+ <show_in_website>1</show_in_website>
218
+ <show_in_store>1</show_in_store>
219
+ </login_tracking>
220
+ <account_actions_tracking translate="label">
221
+ <label>Account Actions Tracking</label>
222
+ <comment>Enable or disable tracking of password changes and other account actions.</comment>
223
+ <frontend_type>select</frontend_type>
224
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
225
+ <sort_order>1150</sort_order>
226
+ <show_in_default>1</show_in_default>
227
+ <show_in_website>1</show_in_website>
228
+ <show_in_store>1</show_in_store>
229
+ </account_actions_tracking>
230
+ <forgot_password_tracking translate="label">
231
+ <label>Forgot Password Tracking</label>
232
+ <comment>Enable or disable tracking whenever customer requests a new password.</comment>
233
+ <frontend_type>select</frontend_type>
234
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
235
+ <sort_order>1160</sort_order>
236
+ <show_in_default>1</show_in_default>
237
+ <show_in_website>1</show_in_website>
238
+ <show_in_store>1</show_in_store>
239
+ </forgot_password_tracking>
240
+ <no_route_tracking translate="label">
241
+ <label>404 Tracking</label>
242
+ <comment>Enable or disable tracking of 404 page not found errors.</comment>
243
+ <frontend_type>select</frontend_type>
244
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
245
+ <sort_order>1170</sort_order>
246
+ <show_in_default>1</show_in_default>
247
+ <show_in_website>1</show_in_website>
248
+ <show_in_store>1</show_in_store>
249
+ </no_route_tracking>
250
+ </fields>
251
+ </advanced>
252
+ </groups>
253
+ </stetic_analytics>
254
+ </sections>
255
+ </config>
app/design/frontend/base/default/layout/stetic.xml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Stetic Analytics Magento Extension
5
+ *
6
+ * @category Stetic
7
+ * @package Stetic_Analytics
8
+ * @copyright Copyright (c) 2014 Stetic (http://www.stetic.com/)
9
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
10
+ */
11
+ -->
12
+ <layout>
13
+ <default>
14
+ <reference name="head">
15
+ <block type="Stetic/tracker" name="Stetic" as="Stetic" template="stetic/tracker.phtml"/>
16
+ </reference>
17
+ </default>
18
+ <sales_order_print>
19
+ <reference name="head">
20
+ <block type="Stetic/tracker" name="Stetic" as="Stetic" template="stetic/tracker.phtml"/>
21
+ </reference>
22
+ </sales_order_print>
23
+ <checkout_onepage_index>
24
+ <reference name="before_body_end">
25
+ <block type="Stetic/tracker" name="SteticCheckout" as="SteticCheckout" template="stetic/onepage.phtml"/>
26
+ </reference>
27
+ </checkout_onepage_index>
28
+ </layout>
app/design/frontend/base/default/template/stetic/onepage.phtml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if( $this->isOrderTrackingEnabled() )
3
+ { ?>
4
+ <script type="text/javascript">
5
+ Checkout.prototype.gotoSection = Checkout.prototype.gotoSection.wrap(function(parentMethod, section, reloadProgressBlock) {
6
+ parentMethod(section, reloadProgressBlock);
7
+ try {
8
+ if(section == '') {
9
+ section = 'billing';
10
+ }
11
+ stetic.track('checkout_' + section);
12
+ } catch(err) { }
13
+ });
14
+ </script>
15
+ <?php } ?>
app/design/frontend/base/default/template/stetic/tracker.phtml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Stetic Analytics Magento Extension
5
+ *
6
+ * @category Stetic
7
+ * @package Stetic_Analytics
8
+ * @copyright Copyright (c) 2014 Stetic (http://www.stetic.com/)
9
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
10
+ */
11
+ if($this->isEnabled()) { ?>
12
+ <script type="text/javascript">
13
+ var _fss=_fss||{}; _fss.token = '<?php echo $this->getSiteToken(); ?>';
14
+ <?php if($this->getCookieDomain()) { ?>_fss.cookieDomain = '<?php echo $this->getCookieDomain(); ?>';<?php } ?>
15
+ <?php echo $this->identify(); ?>
16
+ (function(){var e="stetic",a=window,c=["track","identify","config","register","unregister"],b=function(){var d=0,f=this;for(f._fs=[],d=0;c.length>d;d++){(function(j){f[j]=function(){return f._fs.push([j].concat(Array.prototype.slice.call(arguments,0))),f}})(c[d])}};a[e]=a[e]||new b;a.fourstats=a.fourstats||new b;var i=document;var h=i.createElement("script");h.type="text/javascript";h.async=true;h.src="//stetic.com/t.js";var g=i.getElementsByTagName("script")[0];g.parentNode.insertBefore(h,g)})();
17
+ <?php echo $this->trackEvents(); ?>
18
+ </script>
19
+ <?php
20
+ }
app/etc/modules/Stetic_Analytics.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Stetic Analytics Magento Extension
5
+ *
6
+ * @category Stetic
7
+ * @package Stetic_Analytics
8
+ * @copyright Copyright (c) 2014 Stetic (http://www.stetic.com/)
9
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
10
+ */
11
+ -->
12
+ <config>
13
+ <modules>
14
+ <Stetic_Analytics>
15
+ <active>true</active>
16
+ <codePool>community</codePool>
17
+ </Stetic_Analytics>
18
+ </modules>
19
+ </config>
package.xml ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Stetic_Ecommerce_Analytics</name>
4
+ <version>1.0.1</version>
5
+ <stability>stable</stability>
6
+ <license>GNU General Public License (GPL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Adds real-time Web &amp; Ecommerce Analytics from Stetic with event tracking of all important actions to Magento.</summary>
10
+ <description>With this extenstion you can add the powerful Web and Ecommerce Analytics from &lt;a href="http://www.stetic.com/"&gt;Stetic&lt;/a&gt; to your Magento store. &#xD;
11
+ It will integrate the tracking code to track pageviews and all actions a visitor or customer will take. Logged-in users will be identified and pushed to Stetic for further analysis.&#xD;
12
+ You can enable or disable all individual events in the extension settings.&lt;br&gt;&#xD;
13
+ &lt;br&gt;&#xD;
14
+ Stetic offers a stunning Ecommerce dashboard to monitor the performance of your online store with all important numbers at a glance. &lt;br&gt;&#xD;
15
+ &#xD;
16
+ &lt;br&gt;&#xD;
17
+ &lt;a href="https://www.stetic.com/ecommerce/"&gt;&lt;img src="https://www.stetic.com/img/features/ecommerce/dashboard_en.png" alt="Ecommerce Dashboard"&gt;&lt;/a&gt;&lt;br&gt;&#xD;
18
+ &lt;br&gt;&#xD;
19
+ Learn how successful your shopping cart is.&lt;br&gt;&#xD;
20
+ &lt;br&gt;&#xD;
21
+ &lt;a href="https://www.stetic.com/ecommerce/"&gt;&lt;img src="https://www.stetic.com/img/features/ecommerce/cart_1_en.png" alt="Shopping cart Abandonment Rate"&gt;&lt;/a&gt;&lt;br&gt;&#xD;
22
+ &lt;br&gt;&#xD;
23
+ &lt;a href="https://www.stetic.com/ecommerce/"&gt;&lt;img src="https://www.stetic.com/img/features/ecommerce/cart_2_en.png" alt="Time to cart and time to order"&gt;&lt;/a&gt;&lt;br&gt;&#xD;
24
+ &lt;br&gt;&#xD;
25
+ Customer Profiles - instead of visitors and sessions. Connect your magento customers with your web analytics.&lt;br&gt;&#xD;
26
+ &lt;br&gt;&#xD;
27
+ &lt;a href="https://www.stetic.com/ecommerce/"&gt;&lt;img src="https://www.stetic.com/img/features/ecommerce/user-profile_en.png" alt="Time to cart and time to order"&gt;&lt;/a&gt;&lt;br&gt;&#xD;
28
+ &lt;br&gt;&#xD;
29
+ ..and many more features.&#xD;
30
+ &lt;br&gt;&#xD;
31
+ &lt;br&gt;&#xD;
32
+ Event Tracking - the following actions can be tracked with this extension:&lt;br&gt;&#xD;
33
+ - Shopping Cart actions&lt;br&gt;&#xD;
34
+ - Orders&lt;br&gt;&#xD;
35
+ - Wishlist actions&lt;br&gt;&#xD;
36
+ - Send Friend&lt;br&gt;&#xD;
37
+ - Search&lt;br&gt;&#xD;
38
+ - Contact form&lt;br&gt;&#xD;
39
+ - Newsletter&lt;br&gt;&#xD;
40
+ - Product review&lt;br&gt;&#xD;
41
+ - Product compare&lt;br&gt;&#xD;
42
+ - Account creation&lt;br&gt;&#xD;
43
+ - Login and Logout&lt;br&gt;&#xD;
44
+ - Account actions&lt;br&gt;&#xD;
45
+ - Forgot Password&lt;br&gt;&#xD;
46
+ - 404 page Not Found&lt;br&gt;&#xD;
47
+ &lt;br&gt;&#xD;
48
+ &lt;br&gt;&#xD;
49
+ Note: You have to be registered with Stetic to use this extension.&#xD;
50
+ </description>
51
+ <notes>First release</notes>
52
+ <authors><author><name>Stetic</name><user>stetic</user><email>hello@stetic.com</email></author></authors>
53
+ <date>2014-11-01</date>
54
+ <time>14:30:28</time>
55
+ <contents><target name="magecommunity"><dir name="Stetic"><dir name="Analytics"><dir name="Block"><file name="Tracker.php" hash="bcd7ea404180d2495de429d1fdbde0de"/></dir><dir name="Helper"><file name="Data.php" hash="27026fd1fc808957990cdf61d3f40546"/></dir><dir name="Model"><file name="Observer.php" hash="9da89427ebb23bd0c940cbaf7e3eb761"/></dir><dir name="etc"><file name="config.xml" hash="e14bbc66c6cda199f9b8860bec47c6c2"/><file name="system.xml" hash="cea891cadc2e523579829773f1ed71b0"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="stetic"><file name="onepage.phtml" hash="50be5876eb8f853f528ff5e2799fbee6"/><file name="tracker.phtml" hash="9f89660d790cf7f4f2c6248a7d02b874"/></dir></dir><dir name="layout"><file name="stetic.xml" hash="8d83bec15d00c5d090ad99a765ce574f"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Stetic_Analytics.xml" hash="6452040fe0a72ee45695013a3796f271"/></dir></target></contents>
56
+ <compatible/>
57
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
58
+ </package>