W3CDigitalDataLayerByTriggeredMessaging - Version 0.3.5

Version Notes

All basic features included.
- It can handle full page caching.
- Exception handling has been added.
- Removed empty objects and arrays; Removed duplicated subcategories.
- Added product data for products on category and search pages.
- Fixed issue where configurable products have multiple product entries, and incorrect prices, in the cart object.
- Added more data into digitalData object so websites can be debugged.
- Configurable products have each of their configurations listed under 'linkedProduct'.
- Fixed bug that was breaking some styling.
- Added 'pageName' attribute and fixed type of 'returningStatus' object.
- Tweaks to configuration panel and default values.
- List of all installed non-Magento extensions are exposed (for debug purposes)
- Products associated with a Grouped Product have been included.
- Minimum prices of grouped and bundled products can be extracted.
- Output of debug data can now be controlled through admin configuration panel.

Download this release

Release Info

Developer Muhammed Miah
Extension W3CDigitalDataLayerByTriggeredMessaging
Version 0.3.5
Comparing to
See all releases


Code changes from version 0.3.3 to 0.3.5

app/code/community/TriggeredMessaging/DigitalDataLayer/Model/Page/Observer.php CHANGED
@@ -276,7 +276,7 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
276
 
277
  $this->_page['pageInfo'] = array();
278
  // $this->_page['pageInfo']['pageID']
279
- // $this->_page['pageInfo']['pageName']
280
  $this->_page['pageInfo']['destinationURL'] = Mage::helper('core/url')->getCurrentUrl();
281
  $referringURL = Mage::app()->getRequest()->getServer('HTTP_REFERER');
282
  if ($referringURL) {
@@ -469,38 +469,57 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
469
  if(!($product->getThumbnail()=="no_selection")){
470
  $product_model['productInfo']['productThumbnail'] = $product->getThumbnailUrl();
471
  }
472
- // $product_model['productInfo']['manufacturer'];
473
  if ($product->getWeight()) {
474
- $product_model['productInfo']['size'] = $product->getWeight();
475
  }
476
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
477
  // Category
478
- $categories = $this->_getProductCategories($product);
479
- if (isset($categories[0])||isset($categories[1])||isset($categories[2])) {
480
- $product_model['category'] = array();
481
-
482
- if (isset($categories[0])) {
483
- $product_model['category']['primaryCategory'] = $categories[0];
484
- }
485
- if (isset($categories[1])) {
486
- $product_model['category']['subCategory1'] = $categories[1];
487
-
488
- // Delete if subcategory is a duplicate of the primary category
489
- if (isset($categories[0]) && $categories[0]===$categories[1]) {
490
- unset( $product_model['category']['subCategory1'] );
491
- }
492
- }
493
- if (isset($categories[2])) {
494
- $product_model['category']['subCategory2'] = $categories[2];
495
-
496
- // Delete if subcategory is a duplicate of previous subcategory
497
- if (isset($categories[1]) && $categories[1]===$categories[2]) {
498
- unset( $product_model['category']['subCategory2'] );
499
- }
500
- }
501
-
502
- // $product_model['category']['productType'];
503
- }
504
 
505
  // Price
506
  $product_model['price'] = array();
@@ -539,7 +558,7 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
539
  $product_model['price']['basePrice'] = $normal_price;
540
  }
541
  }
542
-
543
  if ($this->_debug) {
544
  $product_model['price']['all'] = array();
545
  $product_model['price']['all']['getPrice'] = $product->getPrice();
@@ -698,7 +717,7 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
698
  } else {
699
  $litem_model['quantity'] = floatval($item->getQtyOrdered());
700
  }
701
-
702
  if (!is_array($litem_model['price'])) {
703
  $litem_model['price'] = array();
704
  }
@@ -724,7 +743,7 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
724
  }
725
 
726
  // $litem_model['linkedProduct'] = array();
727
- // $litem_model['attributes'] = array();
728
 
729
  array_push($line_items, $litem_model);
730
  }
@@ -808,7 +827,7 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
808
 
809
  try {
810
  $basket = $this->_getCheckoutSession();
811
-
812
  if (!isset($basket)) {
813
  return;
814
  }
@@ -822,7 +841,11 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
822
  $cart['cartID'] = (string) $cart_id;
823
  }
824
  $cart['price'] = array();
825
- $cart['price']['basePrice'] = (float) $quote->getBaseSubtotal();
 
 
 
 
826
  if ($quote->getShippingAddress()->getCouponCode()) {
827
  $cart['price']['voucherCode'] = $quote->getShippingAddress()->getCouponCode();
828
  }
@@ -830,17 +853,26 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
830
  $cart['price']['voucherDiscount'] = abs((float) $quote->getShippingAddress()->getDiscountAmount());
831
  }
832
  $cart['price']['currency'] = $this->_getCurrency();
833
-
834
- $taxRate = (float) $quote->getShippingAddress()->getTaxAmount() / $quote->getBaseSubtotal();
835
- $cart['price']['taxRate'] = round($taxRate, 3); // TODO: Find a better way
 
836
  if ($quote->getShippingAmount()) {
837
  $cart['price']['shipping'] = (float) $quote->getShippingAmount();
838
  }
839
  if ($this->_extractShippingMethod($quote)) {
840
  $cart['price']['shippingMethod'] = $this->_extractShippingMethod($quote);
841
  }
842
- $cart['price']['priceWithTax'] = (float) $quote->getShippingAddress()->getTaxAmount() + $quote->getBaseSubtotal(); // TODO: Find a better way
843
- $cart['price']['cartTotal'] = (float) $quote->getGrandTotal();
 
 
 
 
 
 
 
 
844
  // $cart['attributes'] = array();
845
  if ($cart['price']['basePrice']===0.0&&$cart['price']['cartTotal']===0.0&&$cart['price']['priceWithTax']===0.0) {
846
  unset($cart['price']);
@@ -848,7 +880,7 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
848
 
849
  // Line items
850
  $items = $quote->getAllVisibleItems();
851
- if (!$items && $cart['price']) {
852
  if ($this->_debug) {
853
  $cart['price']['testLog'] = "Second method used to retrieve cart items.";
854
  }
@@ -977,14 +1009,15 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
977
  $transaction['total']['shippingMethod'] = $this->_extractShippingMethod($order);
978
 
979
  // Get addresses
980
- $shippingId = $order->getShippingAddress()->getId();
981
- $address = $this->_getOrderAddress()->load($shippingId);
982
- $billingAddress = $order->getBillingAddress();
983
- $shippingAddress = $order->getShippingAddress();
984
- $transaction['profile'] = array();
985
- $transaction['profile']['address'] = $this->_getAddress($billingAddress);
986
- $transaction['profile']['shippingAddress'] = $this->_getAddress($shippingAddress);
987
-
 
988
  // Get items
989
  $items = $order->getAllItems();
990
  $line_items = $this->_getLineItems($items, 'transaction');
276
 
277
  $this->_page['pageInfo'] = array();
278
  // $this->_page['pageInfo']['pageID']
279
+ $this->_page['pageInfo']['pageName'] = '';
280
  $this->_page['pageInfo']['destinationURL'] = Mage::helper('core/url')->getCurrentUrl();
281
  $referringURL = Mage::app()->getRequest()->getServer('HTTP_REFERER');
282
  if ($referringURL) {
469
  if(!($product->getThumbnail()=="no_selection")){
470
  $product_model['productInfo']['productThumbnail'] = $product->getThumbnailUrl();
471
  }
472
+ //Attributes
473
  if ($product->getWeight()) {
474
+ $product_model['attributes']['weight'] = floatval($product->getWeight());
475
  }
476
+ try{
477
+ $attributes = Mage::getSingleton('eav/config')->getEntityType(Mage_Catalog_Model_Product::ENTITY)->getAttributeCollection();
478
+ foreach($attributes as $attr){
479
+ $infoLocation = 'none';
480
+ $attrCode = $attr->getAttributecode();
481
+ if($attrCode==='color'||$attrCode==='manufacturer'||$attrCode==='size'){
482
+ $infoLocation = 'productInfo';
483
+ } elseif($attr->getData('is_user_defined')) {
484
+ $infoLocation = 'attributes';
485
+ }
486
+ if($infoLocation!=='none'){
487
+ if($attr->getData('frontend_class')==='validate-number'){
488
+ $product_model[$infoLocation][$attrCode] = floatval($attr->getFrontend()->getValue($product));
489
+ } elseif($attr->getData('frontend_class')==='validate-digits'){
490
+ $product_model[$infoLocation][$attrCode] = intval($attr->getFrontend()->getValue($product));
491
+ } else {
492
+ if($product->getAttributeText($attrCode)){
493
+ $product_model[$infoLocation][$attrCode] = $product->getAttributeText($attrCode);
494
+ }
495
+ }
496
+ }
497
+ }
498
+ } catch(Exception $e){
499
+ }
500
  // Category
501
+ // Iterates through all categories, checking for duplicates
502
+ $allcategories = $this->_getProductCategories($product);
503
+ if($allcategories){
504
+ $catiterator = 0;
505
+ $setCategories = array();
506
+ foreach($allcategories as $cat){
507
+ if($catiterator==0){
508
+ $product_model['category']['primaryCategory'] = $cat;
509
+ $catiterator++;
510
+
511
+ } else {
512
+ if(!in_array($cat, $setCategories)){
513
+ $product_model['category']["subCategory$catiterator"] = $cat;
514
+ $catiterator++;
515
+ }
516
+ }
517
+ array_push($setCategories, $cat);
518
+ }
519
+ if($product->getTypeID()){
520
+ $product_model['category']['productType'] = $product->getTypeID();
521
+ }
522
+ }
 
 
 
 
523
 
524
  // Price
525
  $product_model['price'] = array();
558
  $product_model['price']['basePrice'] = $normal_price;
559
  }
560
  }
561
+
562
  if ($this->_debug) {
563
  $product_model['price']['all'] = array();
564
  $product_model['price']['all']['getPrice'] = $product->getPrice();
717
  } else {
718
  $litem_model['quantity'] = floatval($item->getQtyOrdered());
719
  }
720
+
721
  if (!is_array($litem_model['price'])) {
722
  $litem_model['price'] = array();
723
  }
743
  }
744
 
745
  // $litem_model['linkedProduct'] = array();
746
+ // $litem_model['attributes'] = array();
747
 
748
  array_push($line_items, $litem_model);
749
  }
827
 
828
  try {
829
  $basket = $this->_getCheckoutSession();
830
+
831
  if (!isset($basket)) {
832
  return;
833
  }
841
  $cart['cartID'] = (string) $cart_id;
842
  }
843
  $cart['price'] = array();
844
+ if($quote->getBaseSubtotal()){
845
+ $cart['price']['basePrice'] = (float) $quote->getBaseSubtotal();
846
+ } else {
847
+ $cart['price']['basePrice'] = 0.0;
848
+ }
849
  if ($quote->getShippingAddress()->getCouponCode()) {
850
  $cart['price']['voucherCode'] = $quote->getShippingAddress()->getCouponCode();
851
  }
853
  $cart['price']['voucherDiscount'] = abs((float) $quote->getShippingAddress()->getDiscountAmount());
854
  }
855
  $cart['price']['currency'] = $this->_getCurrency();
856
+ if($cart['price']['basePrice'] > 0.0){
857
+ $taxRate = (float) $quote->getShippingAddress()->getTaxAmount() / $cart['price']['basePrice'];
858
+ $cart['price']['taxRate'] = round($taxRate, 3); // TODO: Find a better way
859
+ }
860
  if ($quote->getShippingAmount()) {
861
  $cart['price']['shipping'] = (float) $quote->getShippingAmount();
862
  }
863
  if ($this->_extractShippingMethod($quote)) {
864
  $cart['price']['shippingMethod'] = $this->_extractShippingMethod($quote);
865
  }
866
+ if ($quote->getShippingAddress()->getTaxAmount() && $quote->getBaseSubtotal()){
867
+ $cart['price']['priceWithTax'] = (float) $quote->getShippingAddress()->getTaxAmount() + $quote->getBaseSubtotal(); // TODO: Find a better way
868
+ } else {
869
+ $cart['price']['priceWithTax'] = 0.0;
870
+ }
871
+ if($quote->getGrandTotal()){
872
+ $cart['price']['cartTotal'] = (float) $quote->getGrandTotal();
873
+ } else {
874
+ $cart['price']['cartTotal'] = 0.0;
875
+ }
876
  // $cart['attributes'] = array();
877
  if ($cart['price']['basePrice']===0.0&&$cart['price']['cartTotal']===0.0&&$cart['price']['priceWithTax']===0.0) {
878
  unset($cart['price']);
880
 
881
  // Line items
882
  $items = $quote->getAllVisibleItems();
883
+ if (!$items && isset($cart['price'])) {
884
  if ($this->_debug) {
885
  $cart['price']['testLog'] = "Second method used to retrieve cart items.";
886
  }
1009
  $transaction['total']['shippingMethod'] = $this->_extractShippingMethod($order);
1010
 
1011
  // Get addresses
1012
+ $transaction['profile'] = array();
1013
+ if($order->getBillingAddress()){
1014
+ $billingAddress = $order->getBillingAddress();
1015
+ $transaction['profile']['address'] = $this->_getAddress($billingAddress);
1016
+ }
1017
+ if($order->getShippingAddress()){
1018
+ $shippingAddress = $order->getShippingAddress();
1019
+ $transaction['profile']['shippingAddress'] = $this->_getAddress($shippingAddress);
1020
+ }
1021
  // Get items
1022
  $items = $order->getAllItems();
1023
  $line_items = $this->_getLineItems($items, 'transaction');
app/design/frontend/base/default/template/triggeredmessaging/digital_data_layer.phtml CHANGED
@@ -26,8 +26,10 @@
26
  if (!$page['pageInfo']) {
27
  $page['pageInfo'] = array();
28
  }
29
- if (!$page['pageInfo']['pageName']) {
30
  $page['pageInfo']['pageName'] = $this->getLayout()->getBlock('head')->getTitle();
 
 
31
  }
32
  } catch(Exception $e) {}
33
  ?>
26
  if (!$page['pageInfo']) {
27
  $page['pageInfo'] = array();
28
  }
29
+ if (!$page['pageInfo']['pageName'] || $page['pageInfo']['pageName']==='') {
30
  $page['pageInfo']['pageName'] = $this->getLayout()->getBlock('head')->getTitle();
31
+ } else {
32
+ unset($page['pageInfo']['pageName']);
33
  }
34
  } catch(Exception $e) {}
35
  ?>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>W3CDigitalDataLayerByTriggeredMessaging</name>
4
- <version>0.3.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/apachepl.php">Apache Software License v2</license>
7
  <channel>community</channel>
@@ -29,9 +29,9 @@ https://github.com/TriggeredMessaging/digitalDataMagentoExtension/issues</descri
29
  - Minimum prices of grouped and bundled products can be extracted.&#xD;
30
  - Output of debug data can now be controlled through admin configuration panel.</notes>
31
  <authors><author><name>Muhammed Miah</name><user>momiah1234</user><email>muhammed.miah@triggeredmessaging.com</email></author><author><name>Triggered Messaging</name><user>tmsdemo</user><email>demostore@triggeredmessaging.com</email></author><author><name>Mike Austin</name><user>tmsdemo</user><email>dev@triggeredmessaging.com</email></author></authors>
32
- <date>2014-09-29</date>
33
- <time>12:59:57</time>
34
- <contents><target name="magecommunity"><dir name="TriggeredMessaging"><dir name="DigitalDataLayer"><dir name="Block"><file name="Ddl.php" hash="134766e2a49c3ecfbf03d1025dd41e8b"/></dir><dir name="Helper"><file name="Data.php" hash="5a6e19225e7db056946c95b1477e5c18"/></dir><dir name="Model"><dir name="Container"><file name="Ddl.php" hash="cc9dcd8cf4e460a01c242ac675ce5634"/></dir><file name="Observer.php" hash="26e0dcfc7a19d5310e44e004c144c23e"/><dir name="Page"><file name="Observer.php" hash="2f438462d1372e7e993b301b552ac861"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="8b98dee82241e0b69661bf4699cba334"/><file name="cache.xml" hash="1b6658073a8126cd655cb18109559f49"/><file name="config.xml" hash="a29f9fb1250c40a8d973e470ffab46ac"/><file name="system.xml" hash="a72e032172f1a6b05ba969415bf33f63"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="triggeredmessaging"><file name="digital_data_layer.phtml" hash="61001c0d1d3478f9db8366f4386da754"/><file name="digital_data_layer_after_content.phtml" hash="6ee383b4d2011fd7e718b2930b7cd95d"/></dir></dir><dir name="layout"><dir name="triggeredmessaging"><file name="digital_data_layer.xml" hash="3c58b9faec1d9c63e1fb0a3fcc35a2d8"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="TriggeredMessaging_DigitalDataLayer.xml" hash="cfc3b1bff54f3e1f224f120e536bc411"/></dir></target></contents>
35
  <compatible/>
36
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
37
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>W3CDigitalDataLayerByTriggeredMessaging</name>
4
+ <version>0.3.5</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/apachepl.php">Apache Software License v2</license>
7
  <channel>community</channel>
29
  - Minimum prices of grouped and bundled products can be extracted.&#xD;
30
  - Output of debug data can now be controlled through admin configuration panel.</notes>
31
  <authors><author><name>Muhammed Miah</name><user>momiah1234</user><email>muhammed.miah@triggeredmessaging.com</email></author><author><name>Triggered Messaging</name><user>tmsdemo</user><email>demostore@triggeredmessaging.com</email></author><author><name>Mike Austin</name><user>tmsdemo</user><email>dev@triggeredmessaging.com</email></author></authors>
32
+ <date>2014-10-01</date>
33
+ <time>05:55:56</time>
34
+ <contents><target name="magecommunity"><dir name="TriggeredMessaging"><dir name="DigitalDataLayer"><dir name="Block"><file name="Ddl.php" hash="134766e2a49c3ecfbf03d1025dd41e8b"/></dir><dir name="Helper"><file name="Data.php" hash="5a6e19225e7db056946c95b1477e5c18"/></dir><dir name="Model"><dir name="Container"><file name="Ddl.php" hash="cc9dcd8cf4e460a01c242ac675ce5634"/></dir><file name="Observer.php" hash="26e0dcfc7a19d5310e44e004c144c23e"/><dir name="Page"><file name="Observer.php" hash="eb6dbe1c03fc786769c25857f807afc8"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="8b98dee82241e0b69661bf4699cba334"/><file name="cache.xml" hash="1b6658073a8126cd655cb18109559f49"/><file name="config.xml" hash="a29f9fb1250c40a8d973e470ffab46ac"/><file name="system.xml" hash="a72e032172f1a6b05ba969415bf33f63"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="triggeredmessaging"><file name="digital_data_layer.phtml" hash="61001c0d1d3478f9db8366f4386da754"/><file name="digital_data_layer_after_content.phtml" hash="6ee383b4d2011fd7e718b2930b7cd95d"/></dir></dir><dir name="layout"><dir name="triggeredmessaging"><file name="digital_data_layer.xml" hash="3c58b9faec1d9c63e1fb0a3fcc35a2d8"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="TriggeredMessaging_DigitalDataLayer.xml" hash="cfc3b1bff54f3e1f224f120e536bc411"/></dir></target></contents>
35
  <compatible/>
36
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
37
  </package>