Panalysis_TagManager - Version 0.6.0

Version Notes

Late beta release.

New features:
- Improved support for tracking product categories when the user adds and purchases a product
- Addition of Optimizely code to allow users to run experiments.
- Ability to switch between using the base currency and end user currency

Bug fixes include:
- refactoring code to improve efficiency and reduce database calls

Various other minor updates.

Download this release

Release Info

Developer Rod Jacka
Extension Panalysis_TagManager
Version 0.6.0
Comparing to
See all releases


Code changes from version 0.5.10 to 0.6.0

app/code/community/Panalysis/TagManager/Block/Tagmanager.php CHANGED
@@ -6,6 +6,7 @@ class Panalysis_TagManager_Block_Tagmanager extends Mage_Core_Block_Template
6
  {
7
 
8
  $helper = Mage::helper('panalysis_tagmanager');
 
9
  $session = Mage::getSingleton('core/session');
10
  $trackProductLists = $helper->getTrackProductList();
11
 
@@ -19,25 +20,27 @@ class Panalysis_TagManager_Block_Tagmanager extends Mage_Core_Block_Template
19
  $dataLayer += $visitorState;
20
  $dataLayer['pageType'] = $this->getRequest()->getModuleName() . "-" . $this->getRequest()->getControllerName();
21
  if($this->getPage() == 'Product Category'){
22
- $cl = Mage::getModel('catalog/layer');
23
- $level = $cl->getCurrentCategory()->getParentCategory()->getLevel();
24
- $cat_str = $cl->getCurrentCategory()->getName();
25
- if($level > 1){
26
- $cat = $cl->getCurrentCategory()->getParentCategory();
27
- while($level > 1){
28
- $cat_str = $cat->getName() . "/" . $cat_str;
29
- $cat = $cat->getParentCategory();
30
- $level--;
31
- }
32
- }
33
- $dataLayer['productCategory'] = $cat_str;
 
 
 
 
 
 
 
 
34
  }
35
-
36
- if ($this->getPage() == 'Product Detail') $dataLayer += $helper->buildProductDetailsData($this->getProductDetails());
37
- if ($this->getPage() == 'Order Success') $dataLayer += $helper->buildOrderData($this->getOrderData());
38
- if ($this->getPage() == 'Shopping Cart') $dataLayer += $helper->buildCheckoutData($this->getCartProducts());
39
- if ($this->getPage() == 'Onepage Checkout') $dataLayer += $helper->buildOnePageCartCheckoutData($this->getCartProducts());
40
- if ($this->getPage() == '404') $dataLayer['event']='404';
41
 
42
  $dataLayerJs = "dataLayer.push(" . json_encode($dataLayer,JSON_PRETTY_PRINT) .");\n";
43
 
@@ -128,7 +131,6 @@ class Panalysis_TagManager_Block_Tagmanager extends Mage_Core_Block_Template
128
  $page = '404';
129
  }
130
 
131
- Mage::log("Panalysis - " . $page, null, 'events.log', true);
132
  return $page;
133
  }
134
 
@@ -144,21 +146,21 @@ class Panalysis_TagManager_Block_Tagmanager extends Mage_Core_Block_Template
144
  $associated_ids = $helper->getBundleProducts($_product->getId());
145
  foreach($associated_ids as $child)
146
  {
147
- $products[] = $helper->CreateProductArray($child);
148
  }
149
  } elseif($productType === Mage_Catalog_Model_Product_Type::TYPE_GROUPED) {
150
  $associatedProducts = $_product->getTypeInstance(true)->getAssociatedProducts($_product);
151
  $i = 0;
152
  foreach($associatedProducts as $option)
153
  {
154
- $products[$i] = $helper->CreateProductArray($option->getId(), $option->getQty());
155
  $products[$i]['id'] = $option->getSku();
156
  $products[$i]['name'] = $option->getName();
157
  ++$i;
158
  }
159
 
160
  } else {
161
- $products[] = $helper->CreateProductArray($_product->getId());
162
  }
163
 
164
  return $products;
@@ -172,6 +174,7 @@ class Panalysis_TagManager_Block_Tagmanager extends Mage_Core_Block_Template
172
  $order = Mage::getSingleton('sales/order');
173
  $order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
174
  $storeName = Mage::app()->getStore()->getName();
 
175
  $data = array();
176
 
177
  try {
@@ -180,45 +183,83 @@ class Panalysis_TagManager_Block_Tagmanager extends Mage_Core_Block_Template
180
  $products = array();
181
 
182
  // convert the amounts to the correct currency based on the user's selected currency
183
- $revenue = Mage::helper('core')->currency($order->getBaseGrandTotal(), false, false);
184
- $tax = Mage::helper('core')->currency($order->getBaseTaxAmount(), false, false);
185
- $shipping = Mage::helper('core')->currency($order->getBaseShippingAmount(), false, false);
 
 
 
 
 
 
 
 
 
 
 
 
186
 
187
  $data = array(
188
  'actionField' => array(
189
- 'id' => $order->getIncrementId(),
190
- 'affiliation' => $storeName,
191
- 'revenue' => (float) $revenue,
192
- 'tax' => (float) $tax,
193
- 'shipping' => (float) $shipping,
194
- 'coupon' => ($order->getCouponCode() ? $order->getCouponCode() : ''),
195
  ),
196
  'products' => array()
197
  );
198
-
199
- foreach ($order->getAllItems() as $item)
 
 
200
  {
201
-
202
- $product = Mage::getModel('catalog/product')->load($item->getProductId());
203
- $product_type = $product->getTypeId();
204
-
205
- if ($product_type === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)
206
- $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $item->getSku());
 
 
 
 
 
 
 
 
 
 
 
 
 
207
 
208
- if ($product_type === Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) continue;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
 
210
- if (empty($products[$item->getSku()])) {
211
- $products[$item->getSku()] = $helper->CreateProductArray($product->getId(), $item->getQtyOrdered(), true);
212
- }elseif((int)$item->getPrice()) {
213
- $products[$item->getSku()]['quantity'] += (int)$item->getQtyOrdered();
214
- }
215
-
216
  }
217
-
218
- foreach ($products as $product)
219
- {
220
- $data['transactionProducts'][] = $product;
221
- }
222
  }
223
  } catch (exception $e) {
224
  Mage::logException($e);
@@ -250,31 +291,47 @@ class Panalysis_TagManager_Block_Tagmanager extends Mage_Core_Block_Template
250
  try
251
  {
252
  $helper = Mage::helper('panalysis_tagmanager');
253
- $cart = Mage::getModel("checkout/cart");
254
- $cartItems = $cart->getItems();
 
255
  if(count($cartItems) ==0) return;
256
 
257
  $tm = Mage::getSingleton('panalysis_tagmanager/tagmanager');
258
  $cartProducts = array();
259
-
 
 
260
  foreach ($cartItems as $item)
261
  {
262
- //$itemId = $item->getId();
263
  $productId = $item->getProductId();
264
- $product = Mage::getSingleton('catalog/product')->load($productId);
265
- if($item->getProductType() != 'configurable' && $item->getProductType() != 'bundle')
266
- {
267
- $myItem = $helper->CreateProductArray($product->getId(), $item->getQty());
268
-
269
- if($item->getParentItemId())
270
- {
271
- $parent = Mage::getModel('sales/quote_item')->load($item->getParentItemId());
272
- $myItem['quantity'] = (int)$parent->getQty();
273
- }
274
-
275
- array_push($cartProducts,$myItem);
 
 
 
 
276
  }
277
  }
 
 
 
 
 
 
 
 
 
 
278
  return $cartProducts;
279
  }
280
  catch(exception $e)
6
  {
7
 
8
  $helper = Mage::helper('panalysis_tagmanager');
9
+ $tm = Mage::getSingleton('panalysis_tagmanager/tagmanager');
10
  $session = Mage::getSingleton('core/session');
11
  $trackProductLists = $helper->getTrackProductList();
12
 
20
  $dataLayer += $visitorState;
21
  $dataLayer['pageType'] = $this->getRequest()->getModuleName() . "-" . $this->getRequest()->getControllerName();
22
  if($this->getPage() == 'Product Category'){
23
+ $__cat = $tm->getCategory();
24
+ $dataLayer['productCategory'] = $__cat;
25
+ $helper->setLastCategoryViewed($__cat);
26
+ }
27
+ elseif ($this->getPage() == 'Product Detail'){
28
+ $__cat = $tm->getCategory();
29
+ $helper->setLastCategoryViewed($__cat);
30
+ $dataLayer += $helper->buildProductDetailsData($this->getProductDetails());
31
+ }
32
+ elseif ($this->getPage() == 'Order Success'){
33
+ $dataLayer += $helper->buildOrderData($this->getOrderData());
34
+ }
35
+ elseif ($this->getPage() == 'Shopping Cart'){
36
+ $dataLayer += $helper->buildCheckoutData($this->getCartProducts());
37
+ }
38
+ elseif ($this->getPage() == 'Onepage Checkout'){
39
+ $dataLayer += $helper->buildOnePageCartCheckoutData($this->getCartProducts());
40
+ }
41
+ elseif ($this->getPage() == '404'){
42
+ $dataLayer['event']='404';
43
  }
 
 
 
 
 
 
44
 
45
  $dataLayerJs = "dataLayer.push(" . json_encode($dataLayer,JSON_PRETTY_PRINT) .");\n";
46
 
131
  $page = '404';
132
  }
133
 
 
134
  return $page;
135
  }
136
 
146
  $associated_ids = $helper->getBundleProducts($_product->getId());
147
  foreach($associated_ids as $child)
148
  {
149
+ $products[] = $helper->createProductArray($child);
150
  }
151
  } elseif($productType === Mage_Catalog_Model_Product_Type::TYPE_GROUPED) {
152
  $associatedProducts = $_product->getTypeInstance(true)->getAssociatedProducts($_product);
153
  $i = 0;
154
  foreach($associatedProducts as $option)
155
  {
156
+ $products[$i] = $helper->createProductArray($option->getId(), $option->getQty());
157
  $products[$i]['id'] = $option->getSku();
158
  $products[$i]['name'] = $option->getName();
159
  ++$i;
160
  }
161
 
162
  } else {
163
+ $products[] = $helper->createProductArray($_product);
164
  }
165
 
166
  return $products;
174
  $order = Mage::getSingleton('sales/order');
175
  $order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
176
  $storeName = Mage::app()->getStore()->getName();
177
+ $collection = Mage::getModel('catalog/product')->getCollection();
178
  $data = array();
179
 
180
  try {
183
  $products = array();
184
 
185
  // convert the amounts to the correct currency based on the user's selected currency
186
+ if($helper->getUseMultipleCurrencies())
187
+ {
188
+ $revenue = Mage::helper('core')->currency($order->getGrandTotal(), false, false);
189
+ $tax = Mage::helper('core')->currency($order->getTaxAmount(), false, false);
190
+ $shipping = Mage::helper('core')->currency($order->getShippingAmount(), false, false);
191
+ }
192
+ else
193
+ {
194
+ $revenue = $order->getGrandTotal();
195
+ $tax = $order->getTaxAmount();
196
+ $shipping = $order->getShippingAmount();
197
+ }
198
+ $revenue = round($revenue,2);
199
+ $tax = round($tax,2);
200
+ $shipping = round($shipping,2);
201
 
202
  $data = array(
203
  'actionField' => array(
204
+ 'id' => $order->getIncrementId(),
205
+ 'affiliation' => $storeName,
206
+ 'revenue' => (float) $revenue,
207
+ 'tax' => (float) $tax,
208
+ 'shipping' => (float) $shipping,
209
+ 'coupon' => ($order->getCouponCode() ? $order->getCouponCode() : ''),
210
  ),
211
  'products' => array()
212
  );
213
+
214
+ $filterIds = array();
215
+ $items = array();
216
+ foreach ($order->getAllVisibleItems() as $item)
217
  {
218
+ if($parent = $item->getParentItem()){
219
+ $filterIds[] = $parent->getProductId();
220
+ $items[$parent->getProductId()] = array(
221
+ 'obj' => $parent,
222
+ 'variant' => $item->getSku()
223
+ );
224
+ $items[$parent->getProductId()]['variant'] = $parent;
225
+ } else {
226
+ $filterIds[] = $item->getProductId();
227
+ $items[$item->getProductId()] = array(
228
+ 'obj' => $item,
229
+ 'variant' => $item->getSku()
230
+ );
231
+
232
+ }
233
+ }
234
+
235
+ $productcollection = $collection->addAttributeToSelect('*')
236
+ ->addAttributeToFilter('entity_id', array('in' => $filterIds));
237
 
238
+ foreach ($productcollection as $product) {
239
+
240
+ //$product = Mage::getModel('catalog/product')->load($item->getProductId());
241
+ $sku = $product->getSku();
242
+
243
+ $item = $items[$product->getId()]['obj'];
244
+ $item_price = 0;
245
+ if($helper->getUseMultipleCurrencies())
246
+ $item_price = Mage::helper('core')->currency($item->getPrice(), false, false);
247
+ else
248
+ $item_price = $item->getPrice();
249
+
250
+ $product_array = array(
251
+ 'name' => $product->getName(),
252
+ 'id' => $sku,
253
+ 'variant' => $items[$product->getId()]['variant'],
254
+ 'price' => number_format($item_price, 2),
255
+ 'quantity' => (int)$item->getQtyOrdered(),
256
+ 'category' => $helper->getSkuCategory($sku)
257
+ );
258
 
259
+ if($brand = $tm->getBrand($product)) $product_array['brand'] = $brand;
260
+
261
+ $data['transactionProducts'][] = $product_array;
 
 
 
262
  }
 
 
 
 
 
263
  }
264
  } catch (exception $e) {
265
  Mage::logException($e);
291
  try
292
  {
293
  $helper = Mage::helper('panalysis_tagmanager');
294
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
295
+ $collection = Mage::getModel('catalog/product')->getCollection();
296
+ $cartItems = $quote->getAllVisibleItems();
297
  if(count($cartItems) ==0) return;
298
 
299
  $tm = Mage::getSingleton('panalysis_tagmanager/tagmanager');
300
  $cartProducts = array();
301
+ $items = array();
302
+ $filterList = array();
303
+
304
  foreach ($cartItems as $item)
305
  {
 
306
  $productId = $item->getProductId();
307
+
308
+ if($parentId = $item->getParentItemId()){
309
+ $parent = Mage::getModel('sales/quote_item')->load($parentId);
310
+ $items[$parentId] = array(
311
+ 'qty' => (int)$parent->getQty(),
312
+ 'variant' => $item->getSku()
313
+ );
314
+ $filterList[] = $parentId;
315
+ }
316
+ else{
317
+
318
+ $items[$productId] = array(
319
+ 'qty' => (int)$item->getQty(),
320
+ 'variant' => $item->getSku()
321
+ );
322
+ $filterList[] = $productId;
323
  }
324
  }
325
+
326
+ $products = $collection->addAttributeToSelect('*')
327
+ ->addAttributeToFilter('entity_id', array('in' => $filterList));
328
+
329
+ foreach($products as $product)
330
+ {
331
+ $myItem = $helper->createProductArray($product, $items[$product->getId()]['qty']);
332
+ $myItem['variant'] = $items[$product->getId()]['variant'];
333
+ array_push($cartProducts,$myItem);
334
+ }
335
  return $cartProducts;
336
  }
337
  catch(exception $e)
app/code/community/Panalysis/TagManager/Helper/Data.php CHANGED
@@ -14,9 +14,11 @@ class Panalysis_TagManager_Helper_Data extends Mage_Core_Helper_Abstract
14
  const TWITTER_CREATOR_USERNAME = 'panalysis_tagmanager/opengraph/twittercreatorid';
15
  const TWITTER_IMAGE = 'panalysis_tagmanager/opengraph/twitterimage';
16
  const GTM_MAX_PRODUCTS_IN_LISTS = 'panalysis_tagmanager/gtm/max_products';
 
17
  const GTM_BRAND_CODE = 'panalysis_tagmanager/gtm/brandcode';
18
- const GTM_COLOR_CODE = 'panalysis_tagmanager/gtm/colorcode';
19
  const AJAX_ENABLED = 'panalysis_tagmanager/gtm/enable_ajax';
 
 
20
 
21
  private $store_id = 0;
22
 
@@ -39,6 +41,11 @@ class Panalysis_TagManager_Helper_Data extends Mage_Core_Helper_Abstract
39
  return Mage::getStoreConfig(self::GTM_TRACK_PRODUCT_LISTS, $this->store_id);
40
  }
41
 
 
 
 
 
 
42
  public function useOpenGraph()
43
  {
44
  return Mage::getStoreConfig(self::OG_IS_ENABLED, $this->store_id);
@@ -93,15 +100,31 @@ class Panalysis_TagManager_Helper_Data extends Mage_Core_Helper_Abstract
93
  {
94
  return Mage::getStoreConfig(self::GTM_BRAND_CODE, $this->store_id);
95
  }
96
-
97
- public function getColorCode()
98
  {
99
- return Mage::getStoreConfig(self::GTM_COLOR_CODE, $this->store_id);
100
  }
101
 
102
- public function CreateProductArray($product_id, $qty = 1, $full_category = false)
 
 
 
 
 
103
  {
104
- $product = Mage::getModel('catalog/product')->load($product_id);
 
 
 
 
 
 
 
 
 
 
 
105
  if($product)
106
  {
107
  $tm = Mage::getSingleton('panalysis_tagmanager/tagmanager');
@@ -110,15 +133,12 @@ class Panalysis_TagManager_Helper_Data extends Mage_Core_Helper_Abstract
110
  $product_array = array(
111
  'name' => $product->getName(),
112
  'id' => $product->getSku(),
 
113
  'price' => $final_price,
 
114
  );
115
 
116
  if($brand = $tm->getBrand($product)) $product_array['brand'] = $brand;
117
- if($variant = $tm->getVariant($product)) $product_array['variant'] = $variant;
118
-
119
- if($full_category) $product_array['category'] = $tm->getCatArray($product);
120
- elseif($current_category = Mage::registry('current_category')) $product_array['category'] = $current_category->getName();
121
- else $product_array['category'] = $tm->getCategory($product);
122
 
123
  if($qty !== false && (int)$qty) $product_array['quantity'] = (int)$qty;
124
 
@@ -127,6 +147,26 @@ class Panalysis_TagManager_Helper_Data extends Mage_Core_Helper_Abstract
127
  } else return array();
128
  }
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  //get products just once
131
  public function getBundleProducts($product_id)
132
  {
@@ -153,9 +193,10 @@ class Panalysis_TagManager_Helper_Data extends Mage_Core_Helper_Abstract
153
  }
154
 
155
  public function buildProductDetailsData($products){
 
156
  $data = array(
157
  'ecommerce' => array(
158
- 'currencyCode' => Mage::app()->getStore()->getCurrentCurrencyCode(),
159
  'detail' => array(
160
  'products' => $products
161
  )
@@ -164,17 +205,26 @@ class Panalysis_TagManager_Helper_Data extends Mage_Core_Helper_Abstract
164
  return $data;
165
  }
166
 
167
- public function buildOrderData($order){
 
 
 
 
 
 
 
 
 
168
  $data = array(
169
  'ecommerce' => array(
170
- 'currencyCode' => Mage::app()->getStore()->getCurrentCurrencyCode(),
171
  'purchase' => array(
172
  'actionField' => $order['actionField'],
173
  'products' => $order['transactionProducts']
174
- )
175
  )
176
  );
177
-
178
  return $data;
179
 
180
  }
@@ -186,7 +236,7 @@ class Panalysis_TagManager_Helper_Data extends Mage_Core_Helper_Abstract
186
  $data = array(
187
  'event' => 'productlist',
188
  'ecommerce' => array(
189
- 'currencyCode' => Mage::app()->getStore()->getCurrentCurrencyCode(),
190
  'impressions' => $prodlist
191
  )
192
  );
@@ -197,10 +247,16 @@ class Panalysis_TagManager_Helper_Data extends Mage_Core_Helper_Abstract
197
 
198
  public function buildCheckoutData($products){
199
  if(empty($products)) return array();
 
 
 
 
 
 
200
  $data = array(
201
  'event' => 'checkout',
202
  'ecommerce' => array(
203
- 'currencyCode' => Mage::app()->getStore()->getCurrentCurrencyCode(),
204
  'checkout' => array(
205
  'actionField' => array(
206
  'step' =>'1',
@@ -215,10 +271,17 @@ class Panalysis_TagManager_Helper_Data extends Mage_Core_Helper_Abstract
215
  }
216
 
217
  public function buildOnePageCartCheckoutData($products){
 
 
 
 
 
 
 
218
  $data = array(
219
  'event' => 'checkout',
220
  'ecommerce' => array(
221
- 'currencyCode' => Mage::app()->getStore()->getCurrentCurrencyCode(),
222
  'checkout' => array(
223
  'actionField' => array(
224
  'step' =>'1',
@@ -232,14 +295,20 @@ class Panalysis_TagManager_Helper_Data extends Mage_Core_Helper_Abstract
232
  return $data;
233
  }
234
 
235
- public function buildAddToCartData($prods)
236
  {
 
 
 
 
 
 
237
  $data = array(
238
  'event' => 'addToCart',
239
  'ecommerce' => array(
240
- 'currencyCode' => Mage::app()->getStore()->getCurrentCurrencyCode(),
241
  'add' => array(
242
- 'products' => array_values($prods)
243
  )
244
  )
245
  );
@@ -252,4 +321,36 @@ class Panalysis_TagManager_Helper_Data extends Mage_Core_Helper_Abstract
252
  return Mage::getStoreConfig(self::AJAX_ENABLED, $this->store_id);
253
  }
254
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
  }
14
  const TWITTER_CREATOR_USERNAME = 'panalysis_tagmanager/opengraph/twittercreatorid';
15
  const TWITTER_IMAGE = 'panalysis_tagmanager/opengraph/twitterimage';
16
  const GTM_MAX_PRODUCTS_IN_LISTS = 'panalysis_tagmanager/gtm/max_products';
17
+ const USE_MULTIPLE_CURRENCIES = 'panalysis_tagmanager/gtm/multiple_currencies';
18
  const GTM_BRAND_CODE = 'panalysis_tagmanager/gtm/brandcode';
 
19
  const AJAX_ENABLED = 'panalysis_tagmanager/gtm/enable_ajax';
20
+ const OPTIMIZELY_ENABLED = 'panalysis_tagmanager/optimizely/is_enabled';
21
+ const OPTIMIZELY_ID = 'panalysis_tagmanager/optimizely/optimizelyid';
22
 
23
  private $store_id = 0;
24
 
41
  return Mage::getStoreConfig(self::GTM_TRACK_PRODUCT_LISTS, $this->store_id);
42
  }
43
 
44
+ public function getUseMultipleCurrencies()
45
+ {
46
+ return Mage::getStoreConfig(self::USE_MULTIPLE_CURRENCIES, $this->store_id);
47
+ }
48
+
49
  public function useOpenGraph()
50
  {
51
  return Mage::getStoreConfig(self::OG_IS_ENABLED, $this->store_id);
100
  {
101
  return Mage::getStoreConfig(self::GTM_BRAND_CODE, $this->store_id);
102
  }
103
+
104
+ public function useOptimizely()
105
  {
106
+ return Mage::getStoreConfig(self::OPTIMIZELY_ENABLED, $this->store_id);
107
  }
108
 
109
+ public function getOptimizelyId()
110
+ {
111
+ return Mage::getStoreConfig(self::OPTIMIZELY_ID, $this->store_id);
112
+ }
113
+
114
+ public function getCurrencyCode()
115
  {
116
+ if($this->getUseMultipleCurrencies())
117
+ $currencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
118
+ else
119
+ $currencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
120
+
121
+ return $currencyCode;
122
+ }
123
+
124
+ public function createProductArray($product_obj, $qty = 1)
125
+ {
126
+ $product = $this->getProductFromObj($product_obj);
127
+
128
  if($product)
129
  {
130
  $tm = Mage::getSingleton('panalysis_tagmanager/tagmanager');
133
  $product_array = array(
134
  'name' => $product->getName(),
135
  'id' => $product->getSku(),
136
+ 'variant' => $product->getSku(),
137
  'price' => $final_price,
138
+ 'category' => $tm->getCategory($product)
139
  );
140
 
141
  if($brand = $tm->getBrand($product)) $product_array['brand'] = $brand;
 
 
 
 
 
142
 
143
  if($qty !== false && (int)$qty) $product_array['quantity'] = (int)$qty;
144
 
147
  } else return array();
148
  }
149
 
150
+ private function getProductFromObj($product_obj){
151
+ $type = gettype($product_obj);
152
+ if($type == 'string' || $type == 'integer' ){
153
+ return Mage::getModel('catalog/product')->load($product_obj);
154
+ }
155
+ elseif($type == 'object') {
156
+ $class = get_class($product_obj);
157
+ if($class == 'Mage_Catalog_Model_Product'){
158
+ return $product_obj;
159
+ }
160
+ else{
161
+ return;
162
+ }
163
+ }
164
+ else {
165
+ return;
166
+
167
+ }
168
+ }
169
+
170
  //get products just once
171
  public function getBundleProducts($product_id)
172
  {
193
  }
194
 
195
  public function buildProductDetailsData($products){
196
+
197
  $data = array(
198
  'ecommerce' => array(
199
+ 'currencyCode' => $this->getCurrencyCode(),
200
  'detail' => array(
201
  'products' => $products
202
  )
205
  return $data;
206
  }
207
 
208
+ public function buildOrderData($order){
209
+
210
+
211
+ // get the add to cart category from the cache
212
+ foreach($order['transactionProducts'] as $k => $p){
213
+ $cat = $this->getSkuCategory($p['id']);
214
+ if($cat)
215
+ $order['transactionProducts'][$k]['category'] = $cat;
216
+ }
217
+
218
  $data = array(
219
  'ecommerce' => array(
220
+ 'currencyCode' => $this->getCurrencyCode(),
221
  'purchase' => array(
222
  'actionField' => $order['actionField'],
223
  'products' => $order['transactionProducts']
224
+ )
225
  )
226
  );
227
+ $this->expireSkuCategory();
228
  return $data;
229
 
230
  }
236
  $data = array(
237
  'event' => 'productlist',
238
  'ecommerce' => array(
239
+ 'currencyCode' => $this->getCurrencyCode(),
240
  'impressions' => $prodlist
241
  )
242
  );
247
 
248
  public function buildCheckoutData($products){
249
  if(empty($products)) return array();
250
+ foreach($products as $k=>$v){
251
+ if($cat = $this->getSkuCategory($v['id'])){
252
+ $products[$k]['category'] = $cat;
253
+ }
254
+ }
255
+
256
  $data = array(
257
  'event' => 'checkout',
258
  'ecommerce' => array(
259
+ 'currencyCode' => $this->getCurrencyCode(),
260
  'checkout' => array(
261
  'actionField' => array(
262
  'step' =>'1',
271
  }
272
 
273
  public function buildOnePageCartCheckoutData($products){
274
+ if(empty($products)) return array();
275
+ foreach($products as $k=>$v){
276
+ if($cat = $this->getSkuCategory($v['id'])){
277
+ $products[$k]['category'] = $cat;
278
+ }
279
+ }
280
+
281
  $data = array(
282
  'event' => 'checkout',
283
  'ecommerce' => array(
284
+ 'currencyCode' => $currencyCode = $this->getCurrencyCode(),
285
  'checkout' => array(
286
  'actionField' => array(
287
  'step' =>'1',
295
  return $data;
296
  }
297
 
298
+ public function buildAddToCartData($products)
299
  {
300
+ foreach($products as $k=>$v){
301
+ if($cat = $this->getSkuCategory($v['id'])){
302
+ $products[$k]['category'] = $cat;
303
+ }
304
+ }
305
+
306
  $data = array(
307
  'event' => 'addToCart',
308
  'ecommerce' => array(
309
+ 'currencyCode' => $this->getCurrencyCode(),
310
  'add' => array(
311
+ 'products' => array_values($products)
312
  )
313
  )
314
  );
321
  return Mage::getStoreConfig(self::AJAX_ENABLED, $this->store_id);
322
  }
323
 
324
+ public function getLastCategoryViewed(){
325
+ return Mage::getSingleton('core/session')->getGTMLastCategory();
326
+ }
327
+
328
+ public function setLastCategoryViewed($cat){
329
+ Mage::getSingleton('core/session')->setGTMLastCategory($cat);
330
+ }
331
+
332
+ public function updateSkuCategoryDetails($sku,$cat){
333
+
334
+ $session = Mage::getSingleton('core/session');
335
+
336
+ $skuCats = $session->getGTMCartSkuCats();
337
+ if(! $skuCats){
338
+ $skuCats = array();
339
+ }
340
+ $skuCats[$sku] = $cat;
341
+
342
+ $session->setGTMCartSkuCats($skuCats);
343
+ }
344
+
345
+ public function getSkuCategory($sku){
346
+ $skuCats = Mage::getSingleton('core/session')->getGTMCartSkuCats();
347
+ if(array_key_exists($sku,$skuCats))
348
+ return $skuCats[$sku];
349
+ else
350
+ return "";
351
+ }
352
+
353
+ public function expireSkuCategory(){
354
+ Mage::getSingleton('core/session')->unsGTMCartSkuCats();
355
+ }
356
  }
app/code/community/Panalysis/TagManager/Model/Observer.php CHANGED
@@ -16,6 +16,7 @@ class Panalysis_TagManager_Model_Observer
16
  $qty = 1;
17
  $price = '';
18
  $tmProduct = array();
 
19
 
20
  if (isset($params['qty'])) {
21
  $filter = new Zend_Filter_LocalizedToNormalized(
@@ -32,28 +33,53 @@ class Panalysis_TagManager_Model_Observer
32
  {
33
  $my_qty = $params['super_group'][$ip->getId()];
34
  if($my_qty > 0){
35
- $tmProduct[] = $helper->CreateProductArray($ip->getId(), $my_qty);
 
 
 
 
36
  }
37
  }
38
 
39
  } elseif ($type === Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
40
- $optionCollection = $product->getTypeInstance()->getOptionsCollection();
41
- $selectionCollection =$product->getTypeInstance()->getSelectionsCollection($product->getTypeInstance()->getOptionsIds());
42
- $options = $optionCollection->appendSelections($selectionCollection);
43
- foreach( $options as $option )
44
- {
45
- $_selections = $option->getSelections();
46
-
47
- foreach( $_selections as $selection )
48
- {
49
- $tmProduct[] = $helper->CreateProductArray($selection->getId(), $qty);
50
- }
51
- }
 
 
 
 
 
 
 
 
 
52
  } elseif($type === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE){
 
53
  $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $product->getSku());
54
- $tmProduct[] = $helper->CreateProductArray($product->getId(), $qty);
 
 
 
 
 
 
 
55
  }else {
56
- $tmProduct[] = $helper->CreateProductArray($product->getId(), $qty);
 
 
 
 
57
  }
58
 
59
  $session = Mage::getSingleton('core/session');
@@ -64,6 +90,9 @@ class Panalysis_TagManager_Model_Observer
64
 
65
  $session->setTmProduct($tmProduct);
66
 
 
 
 
67
  } catch (exception $e) {
68
  Mage::logException($e);
69
  }
@@ -114,33 +143,36 @@ class Panalysis_TagManager_Model_Observer
114
  return $event;
115
  }
116
 
 
117
  private function addItemToCart($product_id, $qty=1)
118
  {
119
  $helper = Mage::helper('panalysis_tagmanager');
 
120
  try {
121
  $addProduct = array();
122
  $tm = Mage::getSingleton('panalysis_tagmanager/tagmanager');
123
- $current_updated = Mage::getSingleton('core/session')->getTmProduct();
124
  if($current_updated) $addProduct = $current_updated;
125
- $addProduct[$product_id] = $helper->CreateProductArray($product_id, $qty);
126
- $session = Mage::getSingleton('core/session');
127
  $session->setTmProduct($addProduct);
 
128
  } catch (exception $e) {
129
  Mage::logException($e);
130
  }
131
  }
132
 
133
- private function removeItemFromCart($product_id, $qty)
134
  {
135
  $helper = Mage::helper('panalysis_tagmanager');
 
136
  try {
137
  $rmProduct = array();
138
  $tm = Mage::getSingleton('panalysis_tagmanager/tagmanager');
139
- $current_updated = Mage::getSingleton('core/session')->getRmProducts();
140
  if($current_updated) $rmProduct = $current_updated;
141
- $rmProduct[$product_id] = $helper->CreateProductArray($product_id, $qty);;
142
- $session = Mage::getSingleton('core/session');
143
  $session->setRmProducts($rmProduct);
 
144
  } catch (exception $e) {
145
  Mage::logException($e);
146
  }
@@ -153,8 +185,8 @@ class Panalysis_TagManager_Model_Observer
153
  $product = Mage::getModel('catalog/product')->load($item->getId());
154
  if($product->getTypeId() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)
155
  {
156
- $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $item->getSku());
157
- return $this->removeItemFromCart($product->getId(), $item->getQty());
158
  }
159
  elseif($product->getTypeId() === Mage_Catalog_Model_Product_Type::TYPE_BUNDLE)
160
  {
@@ -191,7 +223,7 @@ class Panalysis_TagManager_Model_Observer
191
  foreach ($allQuoteItems as $item) {
192
  $product = Mage::getSingleton('catalog/product')->load($item->getProductId());
193
  $tm = Mage::getSingleton('panalysis_tagmanager/tagmanager');
194
- $rmProduct = $helper->CreateProductArray($product->getId(), $item->getQty());
195
 
196
  $rmProducts[] = $rmProduct;
197
  }
@@ -213,17 +245,13 @@ class Panalysis_TagManager_Model_Observer
213
  $tm = Mage::getSingleton('panalysis_tagmanager/tagmanager');
214
 
215
  $catProducts = array();
216
- $catName = Mage::getSingleton('catalog/layer')->getCurrentCategory()->getName();
217
-
218
  $_collection = $observer->getEvent()->getCollection();
219
-
220
  $colorAttr = 'color';
221
  $brandAttr = 'manufacturer';
222
 
223
  if($helper->getBrandCode() != "")
224
  $brandAttr = $helper->getBrandCode();
225
- if($helper->getColorCode() != "")
226
- $colorAttr = $helper->getColorCode();
227
 
228
  $_collection->addAttributeToSelect($colorAttr)->addAttributeToSelect($brandAttr);
229
  $_products = $_collection->load();
@@ -233,7 +261,6 @@ class Panalysis_TagManager_Model_Observer
233
  $view = 'Search Results';
234
  $catName = "Search Results";
235
  }
236
- elseif($catName != "") $view = $catName . " Category Listing";
237
  else $view = 'Category Listing';
238
 
239
  $i = 0;
@@ -242,19 +269,25 @@ class Panalysis_TagManager_Model_Observer
242
  if($i >= $limit) break;
243
 
244
  $brand = $tm->getBrand($_product);
245
- $variant = $tm->getVariant($_product);
246
-
247
- $prod = [];
248
- $prod['name'] = $_product->getName();
249
- $prod['id'] = $_product->getSku();
250
- $prod['list'] = $view;
251
- $prod['position'] = ++$i;
252
- $prod['category'] = $catName;
253
 
 
 
 
 
 
 
 
 
 
254
  if($_product->getPrice() > 0 )
255
- $prod['price'] = Mage::helper('core')->currency($_product->getPrice(), false, false);
256
  elseif($_product->getMinPrice() > 0)
257
- $prod['price'] = Mage::helper('core')->currency($_product->getMinPrice(), false, false);
 
 
 
 
 
258
 
259
  if($variant) $prod['variant'] = $variant;
260
  if($brand) $prod['brand'] = $brand;
16
  $qty = 1;
17
  $price = '';
18
  $tmProduct = array();
19
+ $last_cat = Mage::helper('panalysis_tagmanager')->getLastCategoryViewed();
20
 
21
  if (isset($params['qty'])) {
22
  $filter = new Zend_Filter_LocalizedToNormalized(
33
  {
34
  $my_qty = $params['super_group'][$ip->getId()];
35
  if($my_qty > 0){
36
+ $__prod = $helper->createProductArray($ip->getId(), $my_qty);
37
+ if($last_cat){
38
+ $__prod['category'] = $last_cat;
39
+ }
40
+ $tmProduct[] = $__prod;
41
  }
42
  }
43
 
44
  } elseif ($type === Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
45
+ //$optionCollection = $product->getTypeInstance()->getOptionsCollection();
46
+ //$selectionCollection =$product->getTypeInstance()->getSelectionsCollection($product->getTypeInstance()->getOptionsIds());
47
+ //$options = $optionCollection->appendSelections($selectionCollection);
48
+
49
+ $tst_sku = $product->getSku();
50
+ if(strpos($tst_sku, '-')>0){
51
+ $sku_array = explode('-',$tst_sku);
52
+ $sku = $sku_array[0];
53
+ }
54
+ else{
55
+ $sku = $tst_sku;
56
+ }
57
+
58
+ $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
59
+
60
+ $__prod = $helper->createProductArray($ip->getId(), $qty);
61
+ if($last_cat){
62
+ $__prod['category'] = $last_cat;
63
+ }
64
+ $tmProduct[] = $__prod;
65
+
66
  } elseif($type === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE){
67
+ $_parent = Mage::getModel('catalog/product')->load($params['product']);
68
  $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $product->getSku());
69
+ $__prod = $helper->createProductArray($product, $qty);
70
+ // replace the SKU with the item from the parent SKU. Google Analytics doesn't handle SKUs properly.
71
+ $__prod['id'] = $_parent->getSku();
72
+ $__prod['variant'] = $product->getSku();
73
+ if($last_cat){
74
+ $__prod['category'] = $last_cat;
75
+ }
76
+ $tmProduct[] = $__prod;
77
  }else {
78
+ $__prod = $helper->createProductArray($product->getId(), $qty);
79
+ if($last_cat){
80
+ $__prod['category'] = $last_cat;
81
+ }
82
+ $tmProduct[] = $__prod;
83
  }
84
 
85
  $session = Mage::getSingleton('core/session');
90
 
91
  $session->setTmProduct($tmProduct);
92
 
93
+ foreach($tmProduct as $prod)
94
+ $helper->updateSkuCategoryDetails($prod['id'],$prod['category']);
95
+
96
  } catch (exception $e) {
97
  Mage::logException($e);
98
  }
143
  return $event;
144
  }
145
 
146
+
147
  private function addItemToCart($product_id, $qty=1)
148
  {
149
  $helper = Mage::helper('panalysis_tagmanager');
150
+ $session = Mage::getSingleton('core/session');
151
  try {
152
  $addProduct = array();
153
  $tm = Mage::getSingleton('panalysis_tagmanager/tagmanager');
154
+ $current_updated = $session->getTmProduct();
155
  if($current_updated) $addProduct = $current_updated;
156
+ $addProduct[$product_id] = $helper->createProductArray($product_id, $qty);
 
157
  $session->setTmProduct($addProduct);
158
+
159
  } catch (exception $e) {
160
  Mage::logException($e);
161
  }
162
  }
163
 
164
+ private function removeItemFromCart($product, $qty)
165
  {
166
  $helper = Mage::helper('panalysis_tagmanager');
167
+ $session = Mage::getSingleton('core/session');
168
  try {
169
  $rmProduct = array();
170
  $tm = Mage::getSingleton('panalysis_tagmanager/tagmanager');
171
+ $current_updated = $session->getRmProducts();
172
  if($current_updated) $rmProduct = $current_updated;
173
+ $rmProduct[$product] = $helper->createProductArray($product, $qty);
 
174
  $session->setRmProducts($rmProduct);
175
+
176
  } catch (exception $e) {
177
  Mage::logException($e);
178
  }
185
  $product = Mage::getModel('catalog/product')->load($item->getId());
186
  if($product->getTypeId() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)
187
  {
188
+ // use the parent product as GA doesn't handle configurable skus well.
189
+ return $this->removeItemFromCart($product, $item->getQty());
190
  }
191
  elseif($product->getTypeId() === Mage_Catalog_Model_Product_Type::TYPE_BUNDLE)
192
  {
223
  foreach ($allQuoteItems as $item) {
224
  $product = Mage::getSingleton('catalog/product')->load($item->getProductId());
225
  $tm = Mage::getSingleton('panalysis_tagmanager/tagmanager');
226
+ $rmProduct = $helper->createProductArray($product->getId(), $item->getQty());
227
 
228
  $rmProducts[] = $rmProduct;
229
  }
245
  $tm = Mage::getSingleton('panalysis_tagmanager/tagmanager');
246
 
247
  $catProducts = array();
248
+ $catName = $tm->getCategory();
 
249
  $_collection = $observer->getEvent()->getCollection();
 
250
  $colorAttr = 'color';
251
  $brandAttr = 'manufacturer';
252
 
253
  if($helper->getBrandCode() != "")
254
  $brandAttr = $helper->getBrandCode();
 
 
255
 
256
  $_collection->addAttributeToSelect($colorAttr)->addAttributeToSelect($brandAttr);
257
  $_products = $_collection->load();
261
  $view = 'Search Results';
262
  $catName = "Search Results";
263
  }
 
264
  else $view = 'Category Listing';
265
 
266
  $i = 0;
269
  if($i >= $limit) break;
270
 
271
  $brand = $tm->getBrand($_product);
 
 
 
 
 
 
 
 
272
 
273
+ $prod = array(
274
+ 'name' => $_product->getName(),
275
+ 'id' => $_product->getSku(),
276
+ 'list' => $view,
277
+ 'position' => ++$i,
278
+ 'category' => $catName,
279
+ 'url' => $_product->getProductUrl()
280
+ );
281
+
282
  if($_product->getPrice() > 0 )
283
+ $prod['price'] = $_product->getPrice();
284
  elseif($_product->getMinPrice() > 0)
285
+ $prod['price'] = $_product->getMinPrice();
286
+
287
+ if($helper->getUseMultipleCurrencies())
288
+ $prod['price'] = Mage::helper('core')->currency($prod['price'], false, false);
289
+
290
+ $prod['price'] = number_format($prod['price'], 2);
291
 
292
  if($variant) $prod['variant'] = $variant;
293
  if($brand) $prod['brand'] = $brand;
app/code/community/Panalysis/TagManager/Model/Tagmanager.php CHANGED
@@ -5,6 +5,7 @@ class Panalysis_TagManager_Model_Tagmanager extends Mage_Core_Model_Abstract
5
 
6
  public $checkoutState = "";
7
  public $categoryProducts = array();
 
8
 
9
  public function getAttributes($product)
10
  {
@@ -20,7 +21,7 @@ class Panalysis_TagManager_Model_Tagmanager extends Mage_Core_Model_Abstract
20
  * @param $product
21
  * @return mixed
22
  */
23
- public function getPrice($product_id)
24
  {
25
  $storeId = Mage::app()->getStore()->getStoreId();
26
  $product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($product_id);
@@ -39,8 +40,10 @@ class Panalysis_TagManager_Model_Tagmanager extends Mage_Core_Model_Abstract
39
  $price = $product->getFinalPrice();
40
  }
41
 
42
- $price = Mage::helper('core')->currency($price, false, false);
43
- $final_price = Mage::app()->getStore()->roundPrice($price);
 
 
44
 
45
  return $final_price;
46
  }
@@ -64,36 +67,66 @@ class Panalysis_TagManager_Model_Tagmanager extends Mage_Core_Model_Abstract
64
  return $brand;
65
  }
66
 
67
- public function getVariant($product)
68
- {
69
- $color = '';
70
- //$product = Mage::getModel('catalog/product')->load($product->getID());
71
- $colorAttr = Mage::helper('panalysis_tagmanager')->getColorCode();
72
- $attributes = $this->getAttributes($product);
73
-
74
- if (in_array($colorAttr, $attributes)) {
75
- $color = @$product->getAttributeText($colorAttr);
76
- } else {
77
- if (in_array('color', $attributes)) {
78
- $color = @$product->getAttributeText('color');
79
- }
80
- }
81
- return $color;
82
- }
83
-
84
- public function getCategory($product)
85
  {
 
86
  $category = Mage::registry('current_category');
87
- $catName = '';
88
- if (isset($category)) {
89
- $catName = $category->getName();
90
- } else {
91
  $category = $product->getCategoryCollection()
92
  ->addAttributeToSelect('name')
93
  ->getFirstItem();
94
- if($category->getName()) $catName = $category->getName();
95
  }
96
- return $catName;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  }
98
 
99
  public function getCatArray($product)
@@ -195,7 +228,7 @@ class Panalysis_TagManager_Model_Tagmanager extends Mage_Core_Model_Abstract
195
  if($from != $to)
196
  {
197
  $price = Mage::helper('directory')->currencyConvert($price, $from, $to);
198
- $price = Mage::app()->getStore()->roundPrice($price);
199
  }
200
 
201
  return $price;
5
 
6
  public $checkoutState = "";
7
  public $categoryProducts = array();
8
+ private $__cachedCategories = array();
9
 
10
  public function getAttributes($product)
11
  {
21
  * @param $product
22
  * @return mixed
23
  */
24
+ public function getPrice($product_id, $currency='default')
25
  {
26
  $storeId = Mage::app()->getStore()->getStoreId();
27
  $product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($product_id);
40
  $price = $product->getFinalPrice();
41
  }
42
 
43
+ if(Mage::helper('panalysis_tagmanager')->getUseMultipleCurrencies() || $currency=='user')
44
+ $price = Mage::helper('core')->currency($price, false, false);
45
+
46
+ $final_price = number_format($price, 2);
47
 
48
  return $final_price;
49
  }
67
  return $brand;
68
  }
69
 
70
+ /*
71
+ * (string) getCategory()
72
+ * Extracts the category for either a specific product or from the current
73
+ * category in the registry
74
+ */
75
+ public function getCategory($product=null)
 
 
 
 
 
 
 
 
 
 
 
 
76
  {
77
+ // check whether there is a current category
78
  $category = Mage::registry('current_category');
79
+ if (! isset($category) && isset($product)) {
80
+ // if there isn't a current category and a product has been supplied
81
+ // then get the first category listed for that product
 
82
  $category = $product->getCategoryCollection()
83
  ->addAttributeToSelect('name')
84
  ->getFirstItem();
 
85
  }
86
+ elseif(! isset($category)) {
87
+ // otherwise return an empty string
88
+ return "";
89
+ }
90
+
91
+ // if we have made it this far then create the string category path
92
+ $catPath = '';
93
+ $pathIds = $category->getPathIds();
94
+ $_key = implode($pathIds, "-");
95
+ if(array_key_exists($_key, $this->__cachedCategories)){
96
+ return $this->__cachedCategories[$_key];
97
+ }
98
+
99
+ // exclude the root level categories from the list
100
+ $root_id = Mage::app()->getStore()->getRootCategoryId();
101
+ $is_ok = false;
102
+ $idList = array();
103
+ foreach($pathIds as $i){
104
+ if($i == $root_id){
105
+ $is_ok = true;
106
+ continue;
107
+ }
108
+ elseif($is_ok==false){
109
+ continue;
110
+ }
111
+ else
112
+ {
113
+ $idList[] = $i;
114
+ }
115
+ }
116
+
117
+ // load the data in a single query to save resources
118
+ $coll = $category->getResourceCollection();
119
+ $coll->addAttributeToSelect('name');
120
+ $coll->addAttributeToFilter('entity_id', array('in' => $idList));
121
+ $i=0;
122
+ foreach ($coll as $cat) {
123
+ if($i>0) $catPath .= " / ";
124
+ $i++;
125
+ $catPath .= $cat->getName();
126
+ }
127
+
128
+ $this->__cachedCategories[$_key] = $catPath;
129
+ return $catPath;
130
  }
131
 
132
  public function getCatArray($product)
228
  if($from != $to)
229
  {
230
  $price = Mage::helper('directory')->currencyConvert($price, $from, $to);
231
+ $price = number_format($price, 2);
232
  }
233
 
234
  return $price;
app/code/community/Panalysis/TagManager/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Panalysis_TagManager>
5
- <version>0.5.9</version>
6
  </Panalysis_TagManager>
7
  </modules>
8
  <default>
@@ -38,14 +38,15 @@
38
  </panalysis_tagmanager>
39
  </observers>
40
  </checkout_cart_add_product_complete>
 
41
 
42
  <checkout_cart_update_items_before>
43
- <observers>
44
- <panalysis_tagmanager>
45
- <class>panalysis_tagmanager/observer</class>
46
- <method>hookToUpdateToCart</method>
47
- </panalysis_tagmanager>
48
- </observers>
49
  </checkout_cart_update_items_before>
50
 
51
  <sales_quote_remove_item>
2
  <config>
3
  <modules>
4
  <Panalysis_TagManager>
5
+ <version>0.6.0</version>
6
  </Panalysis_TagManager>
7
  </modules>
8
  <default>
38
  </panalysis_tagmanager>
39
  </observers>
40
  </checkout_cart_add_product_complete>
41
+
42
 
43
  <checkout_cart_update_items_before>
44
+ <observers>
45
+ <panalysis_tagmanager>
46
+ <class>panalysis_tagmanager/observer</class>
47
+ <method>hookToUpdateToCart</method>
48
+ </panalysis_tagmanager>
49
+ </observers>
50
  </checkout_cart_update_items_before>
51
 
52
  <sales_quote_remove_item>
app/code/community/Panalysis/TagManager/etc/system.xml CHANGED
@@ -56,21 +56,22 @@
56
  <show_in_website>1</show_in_website>
57
  <show_in_store>1</show_in_store>
58
  </brandcode>
59
- <colorcode translate="label">
60
- <label>Product Color Attribute Code</label>
61
- <frontend_type>text</frontend_type>
62
- <comment>Please enter the attribute code for color/variant attribute used in your website. If not specified, default color attribute would be used</comment>
63
- <sort_order>30</sort_order>
 
64
  <show_in_default>1</show_in_default>
65
  <show_in_website>1</show_in_website>
66
  <show_in_store>1</show_in_store>
67
- </colorcode>
68
  <enable_product_lists translate="label">
69
  <label>Enable Product List View Tracking</label>
70
  <frontend_type>select</frontend_type>
71
  <source_model>adminhtml/system_config_source_yesno</source_model>
72
  <comment>Turn this on if you would like to track product list impressions.</comment>
73
- <sort_order>40</sort_order>
74
  <show_in_default>1</show_in_default>
75
  <show_in_website>1</show_in_website>
76
  <show_in_store>1</show_in_store>
@@ -235,6 +236,40 @@
235
  </twitterimage>
236
  </fields>
237
  </opengraph>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  </groups>
239
  </panalysis_tagmanager>
240
  </sections>
56
  <show_in_website>1</show_in_website>
57
  <show_in_store>1</show_in_store>
58
  </brandcode>
59
+ <multiple_currencies translate="label">
60
+ <label>Use Multilple Currencies</label>
61
+ <frontend_type>select</frontend_type>
62
+ <source_model>adminhtml/system_config_source_yesno</source_model>
63
+ <comment>If your site can process sales in multiple currencies turning this option on will send the price data to Google Analytics in the currency selected by the user.</comment>
64
+ <sort_order>40</sort_order>
65
  <show_in_default>1</show_in_default>
66
  <show_in_website>1</show_in_website>
67
  <show_in_store>1</show_in_store>
68
+ </multiple_currencies>
69
  <enable_product_lists translate="label">
70
  <label>Enable Product List View Tracking</label>
71
  <frontend_type>select</frontend_type>
72
  <source_model>adminhtml/system_config_source_yesno</source_model>
73
  <comment>Turn this on if you would like to track product list impressions.</comment>
74
+ <sort_order>50</sort_order>
75
  <show_in_default>1</show_in_default>
76
  <show_in_website>1</show_in_website>
77
  <show_in_store>1</show_in_store>
236
  </twitterimage>
237
  </fields>
238
  </opengraph>
239
+ <optimizely>
240
+ <label>Optimizely Tag</label>
241
+ <sort_order>30</sort_order>
242
+ <show_in_default>1</show_in_default>
243
+ <show_in_website>1</show_in_website>
244
+ <show_in_store>1</show_in_store>
245
+ <expanded>true</expanded>
246
+ <comment><![CDATA[<p>Enabling this feature will add the Optimizely code snippet to the head section of your site.</p>]]></comment>
247
+ <fields>
248
+ <is_enabled translate="label">
249
+ <label>Enabled</label>
250
+ <frontend_type>select</frontend_type>
251
+ <source_model>adminhtml/system_config_source_yesno</source_model>
252
+ <sort_order>10</sort_order>
253
+ <show_in_default>1</show_in_default>
254
+ <show_in_website>1</show_in_website>
255
+ <show_in_store>1</show_in_store>
256
+ </is_enabled>
257
+
258
+ <optimizelyid translate="label">
259
+ <label>Optimizely Project ID</label>
260
+ <frontend_type>text</frontend_type>
261
+ <backend_model>Panalysis_TagManager_Model_Config_Data_NotEmpty</backend_model>
262
+ <comment>Please enter your the Optimizely Project ID.</comment>
263
+ <sort_order>20</sort_order>
264
+ <show_in_default>1</show_in_default>
265
+ <show_in_website>1</show_in_website>
266
+ <show_in_store>1</show_in_store>
267
+ <depends>
268
+ <is_enabled>1</is_enabled>
269
+ </depends>
270
+ </optimizelyid>
271
+ </fields>
272
+ </optimizely>
273
  </groups>
274
  </panalysis_tagmanager>
275
  </sections>
app/design/frontend/base/default/layout/panalysis/tagmanager.xml CHANGED
@@ -6,11 +6,16 @@
6
  <block type="panalysis_tagmanager/tagmanager" name="tag.manager" as="gtm"
7
  template="panalysis/tagmanager/tagmanager.phtml"></block>
8
  </reference>
 
 
 
 
 
9
  <reference name="head">
10
  <block type="panalysis_tagmanager/tagmanager" name="datalayer"
11
  template="panalysis/tagmanager/datalayer.phtml"></block>
12
  </reference>
13
- <reference name="head">
14
  <block type="panalysis_tagmanager/tagmanager" name="opengraph"
15
  template="panalysis/tagmanager/opengraph.phtml"></block>
16
  </reference>
6
  <block type="panalysis_tagmanager/tagmanager" name="tag.manager" as="gtm"
7
  template="panalysis/tagmanager/tagmanager.phtml"></block>
8
  </reference>
9
+ <reference name="head">
10
+ <block type="panalysis_tagmanager/tagmanager" name="optimizely"
11
+ template="panalysis/tagmanager/optimizely.phtml"></block>
12
+ <sort_order>0</sort_order>
13
+ </reference>
14
  <reference name="head">
15
  <block type="panalysis_tagmanager/tagmanager" name="datalayer"
16
  template="panalysis/tagmanager/datalayer.phtml"></block>
17
  </reference>
18
+ <reference name="head">
19
  <block type="panalysis_tagmanager/tagmanager" name="opengraph"
20
  template="panalysis/tagmanager/opengraph.phtml"></block>
21
  </reference>
app/design/frontend/base/default/template/panalysis/tagmanager/opengraph.phtml CHANGED
@@ -19,18 +19,16 @@ if($helper->useOpenGraph()){
19
 
20
  if($pgtm_og['page_type']=="Product Detail"){
21
  $pgtm_og['og:type'] = "product";
 
22
 
23
  if(Mage::registry('current_product')){
24
  $pan_product_id = Mage::registry('current_product')->getId();
25
  $pan_product= Mage::getModel('catalog/product')->setStoreId($storeId)->load($pan_product_id);
26
  }
27
 
28
-
29
  if($pan_product->getTypeId() === Mage_Catalog_Model_Product_Type::TYPE_GROUPED)
30
  {
31
  $pgtm_og['product:price:amount'] = [];
32
- $pgtm_og['product:price:currency'] = Mage::app()->getStore()->getCurrentCurrencyCode();
33
-
34
  foreach ($pan_product->getTypeInstance(true)->getAssociatedProducts($pan_product) as $assoProd)
35
  {
36
  $pgtm_og['product:price:amount'][] = $tm->getPrice($assoProd->getId());
@@ -42,10 +40,10 @@ if($helper->useOpenGraph()){
42
  $pgtm_og['product:price:amount'] = [];
43
  foreach($associated_ids as $child)
44
  {
45
- $pgtm_og['product:price:amount'][] = $tm->getPrice($child);
46
  }
47
  }else{
48
- $pgtm_og['product:price:amount'] = $tm->getPrice($pan_product_id);
49
  }
50
  }
51
 
19
 
20
  if($pgtm_og['page_type']=="Product Detail"){
21
  $pgtm_og['og:type'] = "product";
22
+ $pgtm_og['product:price:currency'] = Mage::app()->getStore()->getCurrentCurrencyCode();
23
 
24
  if(Mage::registry('current_product')){
25
  $pan_product_id = Mage::registry('current_product')->getId();
26
  $pan_product= Mage::getModel('catalog/product')->setStoreId($storeId)->load($pan_product_id);
27
  }
28
 
 
29
  if($pan_product->getTypeId() === Mage_Catalog_Model_Product_Type::TYPE_GROUPED)
30
  {
31
  $pgtm_og['product:price:amount'] = [];
 
 
32
  foreach ($pan_product->getTypeInstance(true)->getAssociatedProducts($pan_product) as $assoProd)
33
  {
34
  $pgtm_og['product:price:amount'][] = $tm->getPrice($assoProd->getId());
40
  $pgtm_og['product:price:amount'] = [];
41
  foreach($associated_ids as $child)
42
  {
43
+ $pgtm_og['product:price:amount'][] = $tm->getPrice($child, 'user');
44
  }
45
  }else{
46
+ $pgtm_og['product:price:amount'] = $tm->getPrice($pan_product_id, 'user');
47
  }
48
  }
49
 
app/design/frontend/base/default/template/panalysis/tagmanager/optimizely.phtml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $helper = Mage::helper('panalysis_tagmanager');
4
+
5
+ if($helper->useOptimizely()){
6
+ echo('<script src="https://cdn.optimizely.com/js/' . $helper->getOptimizelyId(). '.js"></script>');
7
+ }
8
+
9
+ ?>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Panalysis_TagManager</name>
4
- <version>0.5.10</version>
5
  <stability>beta</stability>
6
  <license uri="http://www.gnu.org/licenses/gpl-3.0.en.html">GPL Version 3</license>
7
  <channel>community</channel>
@@ -10,23 +10,21 @@
10
  <description>This extension provides a seamless way of connecting to the Google Tag Manager service by adding both the code snippet and the data layer with enhanced ecommerce references.&#xD;
11
  &#xD;
12
  In addition to this it also provides support for the Open Graph tags used by Facebook and Pinterest as well as the Twitter Card extensions</description>
13
- <notes>Late beta release. This has been tested on 1.8 and 1.9 editions plus 1.4.1.1&#xD;
14
  &#xD;
15
- Bug fixes include:&#xD;
16
- - corrections to multiple currency support to ensure correct order and shipping totals&#xD;
17
- - performance improvements in product listings&#xD;
18
- - Prevent add to cart and remove from cart dataLayer calls being fired at the same time as order transaction details&#xD;
19
  &#xD;
20
- Additional features:&#xD;
21
- - Add Magento page type to data layer&#xD;
22
- - Added Customer Group attribute to data layer&#xD;
23
- - Added number of previous orders to data layer&#xD;
24
  &#xD;
25
  Various other minor updates.</notes>
26
  <authors><author><name>Rod Jacka</name><user>panalysis</user><email>rod@panalysis.com</email></author><author><name>Ariel Tarnowski</name><user>polcode</user><email>ariel.tarnowski@polcode.net</email></author></authors>
27
- <date>2016-05-07</date>
28
- <time>06:51:18</time>
29
- <contents><target name="magecommunity"><dir name="Panalysis"><dir name="TagManager"><dir><dir name="Block"><dir name="Adminhtml"><file name="Version.php" hash="0edf6f9f427413344f8b2688211be290"/></dir><file name="Tagmanager.php" hash="c724e822f0442be31f6f3d570a274beb"/></dir><dir name="Helper"><file name="Data.php" hash="73a15a153568aae11404f0d5fe023874"/></dir><dir name="Model"><dir name="Config"><dir name="Data"><file name="NotEmpty.php" hash="a38fa920e7f7c0505c7d17ed381f0e13"/></dir></dir><file name="Observer.php" hash="a3c664eaad090af0d5311c19ac8da1cf"/><file name="Tagmanager.php" hash="94b347738b7fd920356d0f5b0100ad1e"/></dir><dir name="controllers"><file name="AjaxController.php" hash="6ac5c018f10a7469bda41b7ba6c58b36"/></dir><dir name="etc"><file name="config.xml" hash="b8e672273af6ee9d29fd5d304a4d8d3e"/><file name="system.xml" hash="29d391af2cf654dfb55dbb5932fcb646"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Panalysis_TagManager.xml" hash="04297a3ffe4f6462aa77006fc8076538"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="panalysis"><file name="tagmanager.xml" hash="84d5ada43613ce1dd51bc183fd7c5dbe"/></dir></dir><dir name="template"><dir name="panalysis"><dir name="tagmanager"><file name="datalayer.phtml" hash="4bd65906c366247c4214d19adbe3949e"/><file name="opengraph.phtml" hash="b39ef6e8a4ef67b88fc2f41fde6c2885"/><file name="tagmanager.phtml" hash="da20b6d708e726f9154dae67504129d7"/></dir></dir></dir></dir></dir></dir></target></contents>
30
  <compatible/>
31
  <dependencies><required><php><min>5.4.38</min><max>7.0.0</max></php></required></dependencies>
32
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Panalysis_TagManager</name>
4
+ <version>0.6.0</version>
5
  <stability>beta</stability>
6
  <license uri="http://www.gnu.org/licenses/gpl-3.0.en.html">GPL Version 3</license>
7
  <channel>community</channel>
10
  <description>This extension provides a seamless way of connecting to the Google Tag Manager service by adding both the code snippet and the data layer with enhanced ecommerce references.&#xD;
11
  &#xD;
12
  In addition to this it also provides support for the Open Graph tags used by Facebook and Pinterest as well as the Twitter Card extensions</description>
13
+ <notes>Late beta release. &#xD;
14
  &#xD;
15
+ New features:&#xD;
16
+ - Improved support for tracking product categories when the user adds and purchases a product&#xD;
17
+ - Addition of Optimizely code to allow users to run experiments.&#xD;
18
+ - Ability to switch between using the base currency and end user currency&#xD;
19
  &#xD;
20
+ Bug fixes include:&#xD;
21
+ - refactoring code to improve efficiency and reduce database calls&#xD;
 
 
22
  &#xD;
23
  Various other minor updates.</notes>
24
  <authors><author><name>Rod Jacka</name><user>panalysis</user><email>rod@panalysis.com</email></author><author><name>Ariel Tarnowski</name><user>polcode</user><email>ariel.tarnowski@polcode.net</email></author></authors>
25
+ <date>2016-05-27</date>
26
+ <time>00:17:14</time>
27
+ <contents><target name="magecommunity"><dir name="Panalysis"><dir name="TagManager"><dir><dir name="Block"><dir name="Adminhtml"><file name="Version.php" hash="0edf6f9f427413344f8b2688211be290"/></dir><file name="Tagmanager.php" hash="65a1327495ffa78d5ed41940ebeaabd7"/></dir><dir name="Helper"><file name="Data.php" hash="49e986af5e46ab03421122bc317b682c"/></dir><dir name="Model"><dir name="Config"><dir name="Data"><file name="NotEmpty.php" hash="a38fa920e7f7c0505c7d17ed381f0e13"/></dir></dir><file name="Observer.php" hash="30314ceccea88fd3d7b4823b45022fde"/><file name="Tagmanager.php" hash="667d9e7edcba7330dcd94ccc7040735d"/></dir><dir name="controllers"><file name="AjaxController.php" hash="6ac5c018f10a7469bda41b7ba6c58b36"/></dir><dir name="etc"><file name="config.xml" hash="34b273b5c101503fdc5508756893f7e8"/><file name="system.xml" hash="b44eaac49c1ca0a9e683d61030e9846a"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Panalysis_TagManager.xml" hash="04297a3ffe4f6462aa77006fc8076538"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="panalysis"><file name="tagmanager.xml" hash="0021ab27d4a24c56c70ef5137710260a"/></dir></dir><dir name="template"><dir name="panalysis"><dir name="tagmanager"><file name="datalayer.phtml" hash="4bd65906c366247c4214d19adbe3949e"/><file name="opengraph.phtml" hash="a3b839ca469a949756e4b4a97ff292a8"/><file name="optimizely.phtml" hash="df6e0ef04f611c6f9a67275fd5843859"/><file name="tagmanager.phtml" hash="da20b6d708e726f9154dae67504129d7"/></dir></dir></dir></dir></dir></dir></target></contents>
28
  <compatible/>
29
  <dependencies><required><php><min>5.4.38</min><max>7.0.0</max></php></required></dependencies>
30
  </package>