IntileryAnalytics - Version 1.2.0

Version Notes

Support for Magento versions 1.9 to 1.9.2

Download this release

Release Info

Developer Gareth
Extension IntileryAnalytics
Version 1.2.0
Comparing to
See all releases


Code changes from version 1.1.1 to 1.2.0

app/code/local/Intilery/Analytics/Helper/Data.php DELETED
@@ -1,9 +0,0 @@
1
- <?php
2
-
3
- class Intilery_Analytics_Helper_Data extends Mage_Core_Helper_Abstract {
4
- public function getSomeData() {
5
-
6
- }
7
- }
8
-
9
- ?>
 
 
 
 
 
 
 
 
 
app/code/local/Intilery/Analytics/Model/Observer.php CHANGED
@@ -19,9 +19,9 @@ class Intilery_Analytics_Model_Observer {
19
 
20
  # Load category model
21
  $_category = Mage::getModel('catalog/category');
22
- $_category->load($categoryID);
23
 
24
- # Get the category name
25
  $categories[] = $_category->getName();
26
 
27
  # Clear up
@@ -34,13 +34,16 @@ class Intilery_Analytics_Model_Observer {
34
  'id' => $product->getId(),
35
  'name' => $product->getName(),
36
  'price' => Mage::helper('core')->currency($product->getPrice(), true, false),
 
37
  'sku' => $product->getSku(),
38
- 'image' => $product->getImage(),
39
  'description' => $product->getDescription(),
40
  'category' => implode(', ', $categories),
41
- 'categoryIds' => $product->getCategoryIds(),
42
  'language' => Mage::app()->getLocale()->getLocaleCode(),
43
- 'url' => $product->getProductUrl()
 
 
44
  )
45
  );
46
 
@@ -142,11 +145,11 @@ class Intilery_Analytics_Model_Observer {
142
 
143
  $updateCartArray[] = array(
144
  'id' => $item->getProduct()->getId(),
145
- 'quantity' => $newQty[$key]['qty']
 
146
  );
147
 
148
  }
149
-
150
  }
151
 
152
  # Store in the session
@@ -180,7 +183,7 @@ class Intilery_Analytics_Model_Observer {
180
  'id' => $product->getId(),
181
  'quantity' => Mage::app()->getRequest()->getParam('qty', 1),
182
  'name' => $product->getName(),
183
- 'price' => $currency_symbol = Mage::helper('core')->currency($product->getPrice(), true, false),
184
  'sku' => $product->getSku(),
185
  'language' => Mage::app()->getLocale()->getLocaleCode(),
186
  'category_name' => Mage::getModel('catalog/category')->load($categories[0])->getName(),
@@ -219,7 +222,87 @@ class Intilery_Analytics_Model_Observer {
219
  Mage::getSingleton('core/session')->setData('intileryTagType', 'RemoveCart');
220
 
221
  }
222
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
223
  }
224
 
225
  ?>
19
 
20
  # Load category model
21
  $_category = Mage::getModel('catalog/category');
22
+ $_category->load($categoryID);
23
 
24
+ # Get the category name
25
  $categories[] = $_category->getName();
26
 
27
  # Clear up
34
  'id' => $product->getId(),
35
  'name' => $product->getName(),
36
  'price' => Mage::helper('core')->currency($product->getPrice(), true, false),
37
+ 'rrpPrice' => Mage::helper('core')->currency($product->getMsrp(), true, false),
38
  'sku' => $product->getSku(),
39
+ 'image' => Mage::getModel('catalog/product_media_config')->getMediaUrl($product->getImage()),
40
  'description' => $product->getDescription(),
41
  'category' => implode(', ', $categories),
42
+ 'categoryIds' => implode(', ', $product->getCategoryIds()),
43
  'language' => Mage::app()->getLocale()->getLocaleCode(),
44
+ 'url' => $product->getProductUrl(),
45
+ 'brandName' => $product->getAttributeText('manufacturer'),
46
+ 'brandID' => $product->getManufacturer()
47
  )
48
  );
49
 
145
 
146
  $updateCartArray[] = array(
147
  'id' => $item->getProduct()->getId(),
148
+ 'quantity' => $newQty[$key]['qty'],
149
+ 'price' => Mage::helper('core')->currency($item->getPrice(), true, false)
150
  );
151
 
152
  }
 
153
  }
154
 
155
  # Store in the session
183
  'id' => $product->getId(),
184
  'quantity' => Mage::app()->getRequest()->getParam('qty', 1),
185
  'name' => $product->getName(),
186
+ 'price' => Mage::helper('core')->currency($product->getPrice(), true, false),
187
  'sku' => $product->getSku(),
188
  'language' => Mage::app()->getLocale()->getLocaleCode(),
189
  'category_name' => Mage::getModel('catalog/category')->load($categories[0])->getName(),
222
  Mage::getSingleton('core/session')->setData('intileryTagType', 'RemoveCart');
223
 
224
  }
225
+
226
+ public function logCartSave(Varien_Event_Observer $observer){
227
+
228
+ //USE THIS FUNCTION TO CHECK IF CART HAS BEEN EMPTIED
229
+
230
+ $cart = Mage::getModel('checkout/cart')->getQuote();
231
+ $updateCartArray = array();
232
+
233
+ if(sizeof($cart->getAllItems()) < 1){
234
+ //CART EMPTIED
235
+ # Set intilery action
236
+ Mage::getSingleton('core/session')->setData('intileryTagType', 'EmptiedCart');
237
+
238
+ }
239
+ }
240
+
241
+ public function logOrderPlacedAfter(Varien_Event_Observer $observer){
242
+
243
+ $orderObj = $observer->getEvent()->getData('order');
244
+ $orderNum = $orderObj->getId();
245
+
246
+ //GET ITEMS WITHIN ORDER
247
+ $order = $observer->getEvent()->getOrder();
248
+
249
+ //GET STATE
250
+ $regionModel = Mage::getSingleton('directory/region')->load($orderObj->getShippingAddress()->getRegionId());
251
+ $sstate_code = $regionModel->getCode();
252
+
253
+ if($order->getId()){
254
+ $ProdustIds = array();
255
+
256
+ foreach ($order->getAllVisibleItems() as $key=>$item)
257
+ {
258
+
259
+ $product = $item->getProduct();
260
+
261
+ # Get the categories
262
+ $categories = array();
263
+ $categoryCollection = $product->getCategoryIds();
264
+
265
+ # Get all categories
266
+ foreach($categoryCollection as $categoryID) {
267
+
268
+ # Load category model
269
+ $_category = Mage::getModel('catalog/category')->load($categoryID);
270
+
271
+ # Get the category name
272
+ $categories[] = $_category->getName();
273
+
274
+ # Clear up
275
+ unset($_category);
276
+ }
277
+
278
+ $ProdustIds[$key]['ID'] = $item->getProductID();
279
+ $ProdustIds[$key]['name'] = $item->getName();
280
+ $ProdustIds[$key]['sku'] = $item->getSku();
281
+ $ProdustIds[$key]['qty'] = $item->getQtyOrdered();
282
+ $ProdustIds[$key]['price'] = $item->getPrice();
283
+ $ProdustIds[$key]['cat'] = implode(", ", $categories);
284
+ }
285
+ }
286
+
287
+ //Set intilery action
288
+ Mage::getSingleton('core/session')->setData('intileryTagType', 'orderAfter');
289
+
290
+ # Store in the session
291
+ Mage::getSingleton('core/session')->setData('orderAfterData', array(
292
+ 'orderNum' => $orderNum,
293
+ 'storeName' => Mage::app()->getStore()->getName(),
294
+ 'grandTotal' => $orderObj->getBaseGrandTotal(),
295
+ 'shippingCity' => $orderObj->getShippingAddress()->getCity(),
296
+ 'state' => $orderObj->getShippingAddress()->getRegion(),
297
+ 'country' => $orderObj->getShippingAddress()->getCountryId(),
298
+ 'currentCurrency' => Mage::app()->getStore()->getBaseCurrencyCode(),
299
+ 'items' => $ProdustIds,
300
+ 'tax' => $orderObj->getData('tax_amount'),
301
+ 'shipping' => $orderObj->getData('shipping_amount')
302
+ )
303
+ );
304
+ }
305
+
306
  }
307
 
308
  ?>
app/code/local/Intilery/Analytics/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Intilery_Analytics>
5
- <version>1.1.0</version>
6
  </Intilery_Analytics>
7
  </modules>
8
 
@@ -22,16 +22,6 @@
22
  </helpers>
23
 
24
  <events>
25
- <!--<catalog_product_save_after>
26
- <observers>
27
- <analytics>
28
- <class>analytics/observer</class>
29
- <method>logCartUpdate</method>
30
- <type>singleton</type>
31
- </analytics>
32
- </observers>
33
- </catalog_product_save_after>-->
34
-
35
  <!--ADD CART ITEM-->
36
 
37
  <checkout_cart_add_product_complete>
@@ -88,6 +78,30 @@
88
  </observers>
89
  </sales_quote_remove_item>
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  <!--LOGOUT-->
92
 
93
  <customer_logout>
2
  <config>
3
  <modules>
4
  <Intilery_Analytics>
5
+ <version>1.2.0</version>
6
  </Intilery_Analytics>
7
  </modules>
8
 
22
  </helpers>
23
 
24
  <events>
 
 
 
 
 
 
 
 
 
 
25
  <!--ADD CART ITEM-->
26
 
27
  <checkout_cart_add_product_complete>
78
  </observers>
79
  </sales_quote_remove_item>
80
 
81
+ <!--CART SAVE-->
82
+
83
+ <checkout_cart_save_before>
84
+ <observers>
85
+ <analytics_cart_add>
86
+ <class>analytics/observer</class>
87
+ <method>logCartSave</method>
88
+ <type>singleton</type>
89
+ </analytics_cart_add>
90
+ </observers>
91
+ </checkout_cart_save_before>
92
+
93
+ <!--PURCHASED ITEM-->
94
+
95
+ <sales_order_place_after>
96
+ <observers>
97
+ <analytics_save_order>
98
+ <class>analytics/observer</class>
99
+ <method>logOrderPlacedAfter</method>
100
+ <type>singleton</type>
101
+ </analytics_save_order>
102
+ </observers>
103
+ </sales_order_place_after>
104
+
105
  <!--LOGOUT-->
106
 
107
  <customer_logout>
app/design/frontend/base/default/template/intilery/footer.phtml CHANGED
@@ -4,282 +4,341 @@
4
  $intileryConfig = Mage::getStoreConfig('intilery/tracking');
5
 
6
  # Enabled tracking?
7
- if($intileryConfig['active']) {
8
-
9
- ?>
10
- <script type="text/javascript">
11
- window.INTILERY = {};
12
- INTILERY.gaq = [];
13
- var _itq = _itq || [];
14
- _itq.push(["_setAccount", "<?=$intileryConfig['code']?>"]);
15
- (function () {
16
- var it = document.createElement("script");
17
- it.type = "text/javascript";
18
- it.async = true;
19
- it.src = ("https:" == document.location.protocol ? "https://" : "http://") + "www.intilery-analytics.com/rest/it.js";
20
- var s = document.getElementsByTagName("script")[0];
21
- s.parentNode.insertBefore(it, s);
22
- })();
23
- </script>
24
-
25
- <?php
26
-
27
- # Get any triggered events
28
- $intileryTagType = Mage::getSingleton('core/session')->getData('intileryTagType', true);
29
-
30
- # Special cases
31
- $intileryTagTypeRegister = Mage::getSingleton('core/session')->getData('intileryCustomerRegister', true);
32
-
33
- # Found register?
34
- if(!is_null($intileryTagTypeRegister) || ($intileryTagType == 'customerRegister')) {
35
-
36
- # Any "add to cart" data
37
- $customerRegisterData = Mage::getSingleton('core/session')->getData('intileryCustomerData', true);
38
-
39
- if(!is_null($customerRegisterData) && !empty($customerRegisterData)) {
40
-
41
- ?>
42
- <script>
43
- var _itq = _itq || [];
44
- _itq.push(['_trackUserEvent','register account',
45
- [
46
- {"name":"Customer.Email", "value":"<?=$customerRegisterData['email']?>"},
47
- {"name":"Customer.First Name", "value":"<?=$customerRegisterData['forename']?>"},
48
- {"name":"Customer.Last Name", "value":"<?=$customerRegisterData['surname']?>"},
49
- {"name":"Customer.Subscribed", "value":"<?=$customerRegisterData['subscribe']?>"}
50
- ]]);
51
- </script>
52
- <?php
53
-
54
- }
55
-
56
- }
57
-
58
- # Found some tag type
59
- if(!is_null($intileryTagType)) {
60
-
61
- # Login customer
62
- if($intileryTagType == 'CustomerLogin') {
63
-
64
- // <editor-fold desc="Customer Login">
65
-
66
- # Any "add to cart" data
67
- $customerLoginData = Mage::getSingleton('core/session')->getData('customerLogin', true);
68
-
69
- # Did we add to cart?
70
- if(!is_null($customerLoginData) && !empty($customerLoginData)) {
71
-
72
- ?>
73
- <script>
74
- var _itq = _itq || [];
75
- _itq.push(['_trackUserEvent', 'sign in', []]);
76
- </script>
77
- <?php
78
- }
79
- // </editor-fold>
80
-
81
- # Logout customer
82
- } elseif($intileryTagType == 'CustomerLogout') {
83
-
84
- // <editor-fold desc="Customer Logout">
85
-
86
- ?>
87
-
88
- <script>
89
- var _itq = _itq || [];
90
- _itq.push(['_trackUserEvent', 'sign out', []]);
91
- </script>
92
-
93
- <?php
94
-
95
- // </editor-fold>
96
-
97
- # When we added to cart
98
- } elseif($intileryTagType == 'AddCart') {
99
-
100
- // <editor-fold desc="Add Cart">
101
-
102
- # Any "add to cart" data
103
- $productAddedToCart = Mage::getSingleton('core/session')->getData('productInShoppingCart', true);
104
-
105
- # Did we add to cart?
106
- if(!is_null($productAddedToCart) && !empty($productAddedToCart)) {
107
- ?>
108
-
109
- <script>
110
- var _itq = _itq || [];
111
- _itq.push(["_trackUserEvent", "add to basket",
112
- [
113
- {"name":"Add To Basket.Price","value":"<?=$productAddedToCart['price']?>"},
114
- {"name":"Add To Basket.Quantity","value":"<?=$productAddedToCart['quantity']?>"},
115
- {"name":"Local Product.ID","value":"<?=$productAddedToCart['id']?>"},
116
- {"name":"Local Product.Language","value":"<?=$productAddedToCart['language']?>"},
117
- {"name":"Local Product.Link","value":"<?=$productAddedToCart['url']?>"},
118
- {"name":"Local Product.Name","value":"<?=$productAddedToCart['name']?>"},
119
- {"name":"Local Product.Price","value":"<?=$productAddedToCart['price']?>"}
120
- ],
121
- "Add To Basket"
122
- ]);
123
-
124
- </script>
125
- <?php
126
- }
127
-
128
- // </editor-fold>
129
-
130
- } elseif($intileryTagType == 'RemoveCart') {
131
-
132
- //<editor-fold desc="Remove Cart">
133
-
134
- # Any "add to cart" data
135
- $productRemovedFromCart = Mage::getSingleton('core/session')->getData('productOutShoppingCart', true);
136
-
137
- # Did we add to cart?
138
- if(!is_null($productRemovedFromCart) && !empty($productRemovedFromCart)) {
139
- ?>
140
- <script>
141
- var _itq = _itq || [];
142
- _itq.push(["_trackUserEvent", "remove from basket", [
143
-     {"name":"Remove From Basket.Quantity","value":"<?=$productRemovedFromCart['qty']?>"},
144
- {"name":"Local Product.ID","value":"<?=$productRemovedFromCart['id']?>"},
145
- {"name":"Local Product.Language","value":"<?=$productRemovedFromCart['language']?>"},
146
- {"name":"Local Product.Link","value":"<?=$productRemovedFromCart['url']?>"},
147
- {"name":"Local Product.Name","value":"<?=$productRemovedFromCart['name']?>"},
148
- {"name":"Local Product.Price","value":"<?=$productRemovedFromCart['price']?>"}
149
- ], "Remove From Basket"]);
150
- </script>
151
- <?php
152
- }
153
-
154
- // </editor-fold>
155
-
156
- } elseif($intileryTagType == 'UpdateCart') {
157
-
158
- // <editor-fold desc="Update Cart">
159
-
160
- # Any "update sale item cart" data
161
- $productUpdatedInCart = Mage::getSingleton('core/session')->getData('productUpdateShoppingCart', true);
162
-
163
- # Did we add to cart?
164
- if(!is_null($productUpdatedInCart) && !empty($productUpdatedInCart) && is_array($productUpdatedInCart) && sizeof($productUpdatedInCart) > 0) {
165
-
166
- foreach($productUpdatedInCart as $product){
167
- ?>
168
- <script>
169
- _itq.push(["_trackUserEvent", "Update Basket Quantity",
170
- [
171
- {"name":"Update Basket.Quantity","value":"<?=$product['quantity']?>"},
172
- {"name":"Product.ID","value":"<?=$product['id']?>"}
173
- ],
174
- "Update Basket"
175
- ]);
176
- </script>
177
- <?php
178
- }
179
-
180
- }
181
-
182
- // </editor-fold>
183
-
184
- } elseif($intileryTagType == 'Search') {
185
-
186
- // <editor-fold desc="Search">
187
-
188
- # Any "update sale item cart" data
189
- $searchQueryText = Mage::getSingleton('core/session')->getData('searchQuery', true);
190
-
191
- # Did we add to cart?
192
- if(!is_null($searchQueryText) && !empty($searchQueryText)) {
193
-
194
- ?>
195
- <script>
196
- _itq.push(["_trackUserEvent", "search",
197
- [
198
- {"name":"Search.Text","value":"<?=$searchQueryText?>"},
199
- {"name":"_brand","value":"brand"}
200
- ],
201
- "Search"
202
- ]);
203
- </script>
204
- <?php
205
- }
206
-
207
- // </editor-fold>
208
-
209
- } elseif($intileryTagType == 'ProductView') {
210
-
211
- // <editor-fold desc="Product View">
212
-
213
- # Get the product data
214
- $productViewData= Mage::getSingleton('core/session')->getData('productViewData', true);
215
-
216
- # Did we add to cart?
217
- if(!is_null($productViewData) && !empty($productViewData)) {
218
-
219
- ?>
220
- <script>
221
- var _itq = _itq || [];
222
- _itq.push(["_trackUserEvent", "view product",
223
- [
224
- {"name":"View Product.Price","value":"<?=$productViewData['price']?>"},
225
- {"name":"Local Product.ID","value":"<?=$productViewData['id']?>"},
226
- {"name":"Local Product.Image","value":"<?=$productViewData['image']?>"},
227
- {"name":"Local Product.Language","value":"<?=$productViewData['language']?>"},
228
- {"name":"Local Product.Link","value":"<?=$productViewData['url']?>"},
229
- {"name":"Local Product.Name","value":"<?=$productViewData['name']?>"},
230
- {"name":"Local Product.Price","value":"<?=$productViewData['price']?>"},
231
- {"name":"Local Product.RRP Price","value":"<?=$productViewData['price']?>"},
232
- {"name":"Product.ID","value":"<?=$productViewData['id']?>"},
233
- {"name":"Category.ID","value":"<?=$productViewData['categoryIds']?>"}
234
- ],
235
- "View Product"
236
- ]);
237
- </script>
238
-
239
- <?php
240
-
241
- }
242
-
243
- // </editor-fold>
244
-
245
- }
246
-
247
- }
248
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  }
250
 
251
  # Read session
252
  $checkSessionExists = Mage::getSingleton('core/session')->getData('intilerySessionExists', true);
253
 
254
  # Nothing passed over yet
255
- if(is_null($checkSessionExists) || empty($checkSessionExists)) {
256
-
257
- # Get the user session
258
- $session = Mage::getSingleton('customer/session');
259
-
260
- # Are we logged in?
261
- if($session->isLoggedIn()) {
262
-
263
- # Get customer data
264
- $customer = $session->getCustomer();
265
-
266
- # All the bits we need
267
- $customerEmail = $customer->getEmail();
268
- $customerFirstName = $customer->getFirstname();
269
- $customerLastName = $customer->getLastname();
270
-
271
- echo "<script>
272
  _itq.push(['_trackUserEvent', 'identify', [
273
  {name:'Customer.Email', value:'{$customerEmail}'},
274
  {name:'Customer.First Name', value:\"{$customerFirstName}\"},
275
  {name:'Customer.Last Name', value:\"{$customerLastName}\"}
276
  ]]);
277
  </script>";
278
-
279
- # Set intilery action
280
- Mage::getSingleton('core/session')->setData('intilerySessionExists', '1');
281
-
282
- }
283
 
284
  }
285
 
4
  $intileryConfig = Mage::getStoreConfig('intilery/tracking');
5
 
6
  # Enabled tracking?
7
+ if ($intileryConfig['active']) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
+ ?>
10
+ <script type="text/javascript">
11
+ window.INTILERY = {};
12
+ INTILERY.gaq = [];
13
+ var _itq = _itq || [];
14
+ _itq.push(["_setAccount", "<?=$intileryConfig['code']?>"]);
15
+ (function () {
16
+ var it = document.createElement("script");
17
+ it.type = "text/javascript";
18
+ it.async = true;
19
+ it.src = ("https:" == document.location.protocol ? "https://" : "http://") + "www.intilery-analytics.com/rest/it.js";
20
+ var s = document.getElementsByTagName("script")[0];
21
+ s.parentNode.insertBefore(it, s);
22
+ })();
23
+ </script>
24
+
25
+ <?php
26
+
27
+ # Get any triggered events
28
+ $intileryTagType = Mage::getSingleton('core/session')->getData('intileryTagType', true);
29
+
30
+ # Special cases
31
+ $intileryTagTypeRegister = Mage::getSingleton('core/session')->getData('intileryCustomerRegister', true);
32
+
33
+ # Found register?
34
+ if (!is_null($intileryTagTypeRegister) || ($intileryTagType == 'customerRegister')) {
35
+
36
+ # Any "add to cart" data
37
+ $customerRegisterData = Mage::getSingleton('core/session')->getData('intileryCustomerData', true);
38
+
39
+ if (!is_null($customerRegisterData) && !empty($customerRegisterData)) {
40
+
41
+ ?>
42
+ <script>
43
+ var _itq = _itq || [];
44
+ _itq.push(['_trackUserEvent', 'register account',
45
+ [
46
+ {"name": "Customer.Email", "value": "<?=$customerRegisterData['email']?>"},
47
+ {"name": "Customer.First Name", "value": "<?=$customerRegisterData['forename']?>"},
48
+ {"name": "Customer.Last Name", "value": "<?=$customerRegisterData['surname']?>"},
49
+ {"name": "Customer.Subscribed", "value": "<?=$customerRegisterData['subscribe']?>"}
50
+ ], 'Register Account']);
51
+ </script>
52
+ <?php
53
+
54
+ }
55
+ }
56
+
57
+ # Found some tag type
58
+ if (!is_null($intileryTagType)) {
59
+
60
+ # Login customer
61
+ if ($intileryTagType == 'CustomerLogin') {
62
+
63
+ // <editor-fold desc="Customer Login">
64
+
65
+ # Any "add to cart" data
66
+ $customerLoginData = Mage::getSingleton('core/session')->getData('customerLogin', true);
67
+
68
+ # Did we add to cart?
69
+ if (!is_null($customerLoginData) && !empty($customerLoginData)) {
70
+
71
+ ?>
72
+ <script>
73
+ var _itq = _itq || [];
74
+ _itq.push(['_trackUserEvent', 'sign in', [{
75
+ "name": "Customer.Email",
76
+ "value": "<?=$customerLoginData['email']?>"
77
+ }], 'Sign In']);
78
+ </script>
79
+ <?php
80
+ }
81
+ // </editor-fold>
82
+
83
+ # Logout customer
84
+ } elseif ($intileryTagType == 'CustomerLogout') {
85
+
86
+ // <editor-fold desc="Customer Logout">
87
+
88
+ ?>
89
+
90
+ <script>
91
+ var _itq = _itq || [];
92
+ _itq.push(['_trackUserEvent', 'sign out', [], 'Sign Out']);
93
+ </script>
94
+
95
+ <?php
96
+
97
+ // </editor-fold>
98
+
99
+ # When we added to cart
100
+ } elseif ($intileryTagType == 'AddCart') {
101
+
102
+ // <editor-fold desc="Add Cart">
103
+
104
+ # Any "add to cart" data
105
+ $productAddedToCart = Mage::getSingleton('core/session')->getData('productInShoppingCart', true);
106
+
107
+ # Did we add to cart?
108
+ if (!is_null($productAddedToCart) && !empty($productAddedToCart)) {
109
+ ?>
110
+ <script>
111
+
112
+ var _itq = _itq || [];
113
+ _itq.push(["_trackUserEvent", "add to basket",
114
+ [
115
+ {"name": "Add To Basket.Price", "value": "<?=$productAddedToCart['price']?>"},
116
+ {"name": "Add To Basket.Quantity", "value": "<?=$productAddedToCart['quantity']?>"},
117
+ {"name": "Local Product.ID", "value": "<?=$productAddedToCart['id']?>"},
118
+ {"name": "Product.ID", "value": "<?=$productAddedToCart['id']?>"},
119
+ {"name": "Local Product.Language", "value": "<?=$productAddedToCart['language']?>"},
120
+ {"name": "Local Product.Link", "value": "<?=$productAddedToCart['url']?>"},
121
+ {"name": "Local Product.Name", "value": "<?=$productAddedToCart['name']?>"},
122
+ {"name": "Local Product.Price", "value": "<?=$productAddedToCart['price']?>"}
123
+ ],
124
+ "Add To Basket"
125
+ ]);
126
+
127
+ </script>
128
+ <?php
129
+ }
130
+
131
+ // </editor-fold>
132
+
133
+ } elseif ($intileryTagType == 'RemoveCart') {
134
+
135
+ //<editor-fold desc="Remove Cart">
136
+
137
+ # Any "add to cart" data
138
+ $productRemovedFromCart = Mage::getSingleton('core/session')->getData('productOutShoppingCart', true);
139
+
140
+ # Did we add to cart?
141
+ if (!is_null($productRemovedFromCart) && !empty($productRemovedFromCart)) {
142
+ ?>
143
+ <script>
144
+ var _itq = _itq || [];
145
+ _itq.push(["_trackUserEvent", "remove from basket", [
146
+ {"name": "Remove From Basket.Quantity", "value": "<?=$productRemovedFromCart['qty']?>"},
147
+ {"name": "Local Product.ID", "value": "<?=$productRemovedFromCart['id']?>"},
148
+ {"name": "Product.ID", "value": "<?=$productRemovedFromCart['id']?>"},
149
+ {"name": "Local Product.Language", "value": "<?=$productRemovedFromCart['language']?>"}
150
+ ], "Remove From Basket"]);
151
+ </script>
152
+ <?php
153
+ }
154
+
155
+ // </editor-fold>
156
+
157
+ } elseif ($intileryTagType == 'UpdateCart') {
158
+
159
+ // <editor-fold desc="Update Cart">
160
+
161
+ # Any "update sale item cart" data
162
+ $productUpdatedInCart = Mage::getSingleton('core/session')->getData('productUpdateShoppingCart', true);
163
+
164
+ # Did we add to cart?
165
+ if (!is_null($productUpdatedInCart) && !empty($productUpdatedInCart) && is_array($productUpdatedInCart) && sizeof($productUpdatedInCart) > 0) {
166
+
167
+ foreach ($productUpdatedInCart as $product) {
168
+ ?>
169
+ <script>
170
+ _itq.push(["_trackUserEvent", "Update Basket",
171
+ [
172
+ {"name": "Update Basket.Quantity", "value": "<?=$product['quantity']?>"},
173
+ {"name": "Product.ID", "value": "<?=$product['id']?>"},
174
+ {"name": "Update Basket.Price", "value": "<?=$product['price']?>"}
175
+ ],
176
+ "Update Basket"
177
+ ]);
178
+ </script>
179
+ <?php
180
+ }
181
+
182
+ }
183
+
184
+ // </editor-fold>
185
+
186
+ } elseif ($intileryTagType == 'Search') {
187
+
188
+ // <editor-fold desc="Search">
189
+
190
+ # Any "update sale item cart" data
191
+ $searchQueryText = Mage::getSingleton('core/session')->getData('searchQuery', true);
192
+
193
+ # Did we add to cart?
194
+ if (!is_null($searchQueryText) && !empty($searchQueryText)) {
195
+
196
+ ?>
197
+ <script>
198
+ _itq.push(["_trackUserEvent", "search",
199
+ [
200
+ {"name": "Search.Text", "value": "<?=$searchQueryText?>"}
201
+ ],
202
+ "Search"
203
+ ]);
204
+ </script>
205
+ <?php
206
+ }
207
+
208
+ // </editor-fold>
209
+
210
+ } elseif ($intileryTagType == 'ProductView') {
211
+
212
+ // <editor-fold desc="Product View">
213
+
214
+ # Get the product data
215
+ $productViewData = Mage::getSingleton('core/session')->getData('productViewData', true);
216
+
217
+ # Did we add to cart?
218
+ if (!is_null($productViewData) && !empty($productViewData)) {
219
+
220
+ ?>
221
+ <script>
222
+
223
+ var _itq = _itq || [];
224
+ _itq.push(["_trackUserEvent", "view product",
225
+ [
226
+ {"name": "View Product.Price", "value": "<?=$productViewData['price']?>"},
227
+ {"name": "Local Product.ID", "value": "<?=$productViewData['id']?>"},
228
+ {"name": "Local Product.Image", "value": "<?=$productViewData['image']?>"},
229
+ {"name": "Local Product.Language", "value": "<?=$productViewData['language']?>"},
230
+ {"name": "Local Product.Link", "value": "<?=$productViewData['url']?>"},
231
+ {"name": "Local Product.Name", "value": "<?=$productViewData['name']?>"},
232
+ {"name": "Local Product.Price", "value": "<?=$productViewData['price']?>"},
233
+ {"name": "Local Product.RRP Price", "value": "<?=$productViewData['rrpPrice']?>"},
234
+ {"name": "Product.ID", "value": "<?=$productViewData['id']?>"},
235
+ {"name": "Category.ID", "value": "<?=$productViewData['categoryIds']?>"},
236
+ {"name": "Brand.ID", "value": "<?=$productViewData['brandID']?>"},
237
+ {"name": "Brand.Name", "value": "<?=$productViewData['brandName']?>"},
238
+ {"name": "Local Category.ID", "value": "<?=$productViewData['categoryIds']?>"},
239
+ {"name": "Local Category.Name", "value": "<?=$productViewData['category']?>"},
240
+ {"name": "Local Category.Language", "value": "<?=$productViewData['language']?>"}
241
+ ],
242
+ "View Product"
243
+ ]);
244
+ </script>
245
+
246
+ <?php
247
+ }
248
+
249
+ // </editor-fold>
250
+
251
+ } elseif ($intileryTagType == 'EmptiedCart') {
252
+
253
+ //<editor-fold desc="Emptied Cart">
254
+ ?>
255
+ <script>
256
+ _itq.push(["_trackUserEvent", "clear basket",
257
+ [],
258
+ "Clear Basket"
259
+ ]);
260
+ </script>
261
+ <?php
262
+ //</editor-fold>
263
+
264
+ } elseif ($intileryTagType == 'orderAfter') {
265
+
266
+ # Get the order data
267
+ $orderData = Mage::getSingleton('core/session')->getData('orderAfterData', true);
268
+ $total = $orderData['grandTotal'] - ($orderData['tax'] + $orderData['shipping']);
269
+
270
+ ?>
271
+ <script>
272
+ _itq.push(['_addTrans',
273
+ '<?=$orderData['orderNum']?>', // transaction ID - required (orderid)
274
+ '<?=$orderData['storeName']?>', // affiliation or store name
275
+ '<?=$total?>', // total - required; Shown as "Revenue" in the
276
+ // Transactions report. Does not include Tax and Shipping.
277
+ '<?=$orderData['tax']?>', // tax
278
+ '<?=$orderData['shipping']?>', // shipping
279
+ '<?=$orderData['shippingCity']?>', // city
280
+ '<?=$orderData['state']?>', // state or province
281
+ '<?=$orderData['country']?>', // country
282
+ [
283
+ {"name": "Transaction.Currency", "value": "<?=$orderData['currentCurrency']?>"}
284
+ ]
285
+ ]);
286
+ </script>
287
+ <?php
288
+
289
+ foreach ($orderData['items'] as $key => $item) {
290
+ ?>
291
+ <script>
292
+ _itq.push(['_addItem',
293
+ '<?=$orderData['orderNum']?>', // transaction ID - necessary to associate item with transaction (orderid)
294
+ '<?=$item['sku']?>', // SKU/code - required
295
+ '<?=$item['name']?>', // product name
296
+ '<?=$item['cat']?>', // category or variation
297
+ '<?=$item['price']?>', // unit price - required
298
+ '<?=$item['qty']?>', // quantity - required
299
+ [
300
+ {"name": "Product.ID", "value": "<?=$item['ID']?>"}
301
+ ]
302
+ ]);
303
+ </script>
304
+ <?php
305
+ }
306
+ }
307
+ }
308
  }
309
 
310
  # Read session
311
  $checkSessionExists = Mage::getSingleton('core/session')->getData('intilerySessionExists', true);
312
 
313
  # Nothing passed over yet
314
+ if (is_null($checkSessionExists) || empty($checkSessionExists)) {
315
+
316
+ # Get the user session
317
+ $session = Mage::getSingleton('customer/session');
318
+
319
+ # Are we logged in?
320
+ if ($session->isLoggedIn()) {
321
+
322
+ # Get customer data
323
+ $customer = $session->getCustomer();
324
+
325
+ # All the bits we need
326
+ $customerEmail = $customer->getEmail();
327
+ $customerFirstName = $customer->getFirstname();
328
+ $customerLastName = $customer->getLastname();
329
+
330
+ echo "<script>
331
  _itq.push(['_trackUserEvent', 'identify', [
332
  {name:'Customer.Email', value:'{$customerEmail}'},
333
  {name:'Customer.First Name', value:\"{$customerFirstName}\"},
334
  {name:'Customer.Last Name', value:\"{$customerLastName}\"}
335
  ]]);
336
  </script>";
337
+
338
+ # Set intilery action
339
+ Mage::getSingleton('core/session')->setData('intilerySessionExists', '1');
340
+
341
+ }
342
 
343
  }
344
 
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>IntileryAnalytics</name>
4
- <version>1.1.1</version>
5
  <stability>stable</stability>
6
  <license>Open Software License (OSL)</license>
7
  <channel>community</channel>
@@ -10,9 +10,9 @@
10
  <description>Intilery Customer Engagement Connector allows you to connect Magento with Intilery.com seamlessly.</description>
11
  <notes>Support for Magento versions 1.9 to 1.9.2</notes>
12
  <authors><author><name>Gareth</name><user>intilery</user><email>gareth.james@intilery.com</email></author></authors>
13
- <date>2015-10-16</date>
14
- <time>12:54:20</time>
15
- <contents><target name="magelocal"><dir name="Intilery"><dir name="Analytics"><dir name="Model"><file name="Observer.php" hash="f4ac9b6c4ace3c761d49dfe555b542b1"/></dir><dir name="etc"><file name="config.xml" hash="3149fd3538d7da8eeadc33acfcb5a09d"/><file name="adminhtml.xml" hash="a6eb6b0d6eaca7f0c086f5dd0ff8d85e"/><file name="system.xml" hash="c33bbe5c89fb09e0ac6665ef63e705b6"/></dir><dir name="Helper"><file name="Data.php" hash="7875f3486d0bb7edbccc8ef2d41ee006"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="intilery"><file name="footer.phtml" hash="da29397069e675c74ed07cf10b6c0d5a"/></dir></dir><dir name="layout"><file name="intileryanalytics.xml" hash="6f8d7b5aed8d4fa54ab6f4b9cb2a453d"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Intilery_Analytics.xml" hash="943756b51b7a8bab8175c9132a7473c8"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>IntileryAnalytics</name>
4
+ <version>1.2.0</version>
5
  <stability>stable</stability>
6
  <license>Open Software License (OSL)</license>
7
  <channel>community</channel>
10
  <description>Intilery Customer Engagement Connector allows you to connect Magento with Intilery.com seamlessly.</description>
11
  <notes>Support for Magento versions 1.9 to 1.9.2</notes>
12
  <authors><author><name>Gareth</name><user>intilery</user><email>gareth.james@intilery.com</email></author></authors>
13
+ <date>2015-10-27</date>
14
+ <time>16:21:04</time>
15
+ <contents><target name="magelocal"><dir><dir name="Intilery"><dir name="Analytics"><dir name="Model"><file name="Observer.php" hash="8eb7c3d72dfedfaf36a36e5f3e07932d"/></dir><dir name="etc"><file name="config.xml" hash="59cce74b3bcd4db6e65fc19c328352a6"/><file name="adminhtml.xml" hash="a6eb6b0d6eaca7f0c086f5dd0ff8d85e"/><file name="system.xml" hash="c33bbe5c89fb09e0ac6665ef63e705b6"/></dir></dir></dir></dir></target><target name="magedesign"><dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="intilery"><file name="footer.phtml" hash="d61c3d26b552bfb39f43d480841e650d"/></dir></dir><dir name="layout"><file name="intileryanalytics.xml" hash="6f8d7b5aed8d4fa54ab6f4b9cb2a453d"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="Intilery_Analytics.xml" hash="943756b51b7a8bab8175c9132a7473c8"/></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>