W3CDigitalDataLayerByTriggeredMessaging - Version 0.3.6

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.6
Comparing to
See all releases


Code changes from version 0.3.5 to 0.3.6

app/code/community/TriggeredMessaging/DigitalDataLayer/Model/Page/Observer.php CHANGED
@@ -332,6 +332,7 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
332
  $user_id = $user->getEntityId();
333
  $firstName = $user->getFirstname();
334
  $lastName = $user->getLastname();
 
335
 
336
  if ($this->_isConfirmation()) {
337
  $orderId = $this->_getCheckoutSession()->getLastOrderId();
@@ -343,7 +344,6 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
343
  $email = $user->getEmail();
344
  }
345
 
346
- // $this->_user['segment'] = array();
347
  $this->_user['profile'] = array();
348
 
349
  $profile = array();
@@ -363,7 +363,10 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
363
  }
364
  $profile['profileInfo']['language'] = Mage::getStoreConfig('general/locale/code', Mage::app()->getStore()->getId());
365
  $profile['profileInfo']['returningStatus'] = $user_id ? 'true' : 'false';
366
- // $profile['profileInfo']['type'];
 
 
 
367
 
368
  // $profile['address'] = array();
369
  // $profile['address']['line1'];
@@ -419,7 +422,7 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
419
  return Mage::app()->getStore()->getCurrentCurrencyCode();
420
  }
421
 
422
- public function _getProductModel($product) {
423
  /*
424
  Section 6.4 of http://www.w3.org/2013/12/ceddl-201312.pdf
425
  product: [
@@ -453,6 +456,18 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
453
  */
454
 
455
  $product_model = array();
 
 
 
 
 
 
 
 
 
 
 
 
456
 
457
  try {
458
  // Product Info
@@ -463,10 +478,10 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
463
  $product_model['productInfo']['productURL'] = $product->getProductUrl();
464
 
465
  //Check if images contain placeholders
466
- if(!($product->getImage()=="no_selection")){
467
  $product_model['productInfo']['productImage'] = $product->getImageUrl();
468
  }
469
- if(!($product->getThumbnail()=="no_selection")){
470
  $product_model['productInfo']['productThumbnail'] = $product->getThumbnailUrl();
471
  }
472
  //Attributes
@@ -476,24 +491,32 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
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
  }
@@ -583,6 +606,7 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
583
  $product_model['price']['taxRate'] = ((float) $percent) / 100;
584
 
585
  // For configurable/grouped/composite products, add all associated products to 'linkedProduct'
 
586
  if ($product->isConfigurable() || $product->isGrouped() || $product->isComposite()) {
587
 
588
  $product_model['linkedProduct'] = array();
@@ -609,7 +633,7 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
609
  // Add related products to the data layer
610
  $min_price = 0.0;
611
  foreach($simple_collection as $simple_product){
612
- array_push($product_model['linkedProduct'], $this->_getProductModel($simple_product));
613
  $simple_product_price = floatval($simple_product->getPrice());
614
  if ($simple_product_price && (!$min_price || $simple_product_price<$min_price)) {
615
  $min_price = $simple_product_price;
@@ -625,6 +649,7 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
625
  unset($product_model['linkedProduct']);
626
  }
627
  }
 
628
 
629
  if ($this->_debug) {
630
  $product_model['more']['isConfigurable'] = $product->isConfigurable();
@@ -702,7 +727,6 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
702
  */
703
 
704
  $line_items = array();
705
-
706
  try {
707
  foreach($items as $item) {
708
  $productId = $item->getProductId();
@@ -710,7 +734,7 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
710
  // product needs to be visible
711
  if ($product->isVisibleInSiteVisibility()) {
712
 
713
- $litem_model = $this->_getProductModel($product);
714
 
715
  if ($page_type == 'cart') {
716
  $litem_model['quantity'] = floatval($item->getQty());
@@ -777,7 +801,7 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
777
  $product = $this->_getCurrentProduct();
778
  if (!$product) return false;
779
  $this->_product = array();
780
- array_push($this->_product, $this->_getProductModel($product));
781
  } catch (Exception $e) {
782
  }
783
  }
@@ -834,7 +858,6 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
834
 
835
  $cart = array();
836
  $quote = $basket->getQuote();
837
-
838
  // Set normal params
839
  $cart_id = $basket->getQuoteId();
840
  if ($cart_id) {
@@ -1047,6 +1070,7 @@ class TriggeredMessaging_DigitalDataLayer_Model_Page_Observer {
1047
 
1048
  if ($triggered_messaging_digital_data_layer_enabled==1) {
1049
  $this->_debug = (boolean)Mage::getStoreConfig('triggered_messaging/triggered_messaging_digital_data_layer_debug_enabled');
 
1050
 
1051
  $this->_setUser();
1052
  $this->_setPage();
332
  $user_id = $user->getEntityId();
333
  $firstName = $user->getFirstname();
334
  $lastName = $user->getLastname();
335
+ $userGroup = Mage::getModel('customer/group')->load(Mage::getSingleton('customer/session')->getCustomerGroupId());
336
 
337
  if ($this->_isConfirmation()) {
338
  $orderId = $this->_getCheckoutSession()->getLastOrderId();
344
  $email = $user->getEmail();
345
  }
346
 
 
347
  $this->_user['profile'] = array();
348
 
349
  $profile = array();
363
  }
364
  $profile['profileInfo']['language'] = Mage::getStoreConfig('general/locale/code', Mage::app()->getStore()->getId());
365
  $profile['profileInfo']['returningStatus'] = $user_id ? 'true' : 'false';
366
+ if($userGroup && $this->_userGroupExp){
367
+ $profile['profileInfo']['segment']['userGroupId'] = $userGroup->getData('customer_group_id');
368
+ $profile['profileInfo']['segment']['userGroup'] = $userGroup->getData('customer_group_code');
369
+ }
370
 
371
  // $profile['address'] = array();
372
  // $profile['address']['line1'];
422
  return Mage::app()->getStore()->getCurrentCurrencyCode();
423
  }
424
 
425
+ public function _getProductModel($product, $inCart) {
426
  /*
427
  Section 6.4 of http://www.w3.org/2013/12/ceddl-201312.pdf
428
  product: [
456
  */
457
 
458
  $product_model = array();
459
+ $options = array();
460
+ //If there is optional data then add it
461
+ if($inCart){
462
+ $opt = $product->getProduct()->getTypeInstance(true)->getOrderOptions($product->getProduct());
463
+ if(isset($opt['attributes_info'])){
464
+ foreach($opt['attributes_info'] as $attribute){
465
+ $options[$attribute['label']] = $attribute['value'];
466
+ }
467
+ }
468
+ $productId = $product->getProductId();
469
+ $product = $this->_getProduct($productId);
470
+ }
471
 
472
  try {
473
  // Product Info
478
  $product_model['productInfo']['productURL'] = $product->getProductUrl();
479
 
480
  //Check if images contain placeholders
481
+ if($product->getImage() && !($product->getImage()=="no_selection")){
482
  $product_model['productInfo']['productImage'] = $product->getImageUrl();
483
  }
484
+ if($product->getThumbnail() && !($product->getThumbnail()=="no_selection")){
485
  $product_model['productInfo']['productThumbnail'] = $product->getThumbnailUrl();
486
  }
487
  //Attributes
491
  try{
492
  $attributes = Mage::getSingleton('eav/config')->getEntityType(Mage_Catalog_Model_Product::ENTITY)->getAttributeCollection();
493
  foreach($attributes as $attr){
494
+ $infoLocation = 'none';
495
  $attrCode = $attr->getAttributecode();
496
  if($attrCode==='color'||$attrCode==='manufacturer'||$attrCode==='size'){
497
+ $infoLocation = 'productInfo';
498
  } elseif($attr->getData('is_user_defined')) {
499
+ $infoLocation = 'attributes';
500
+ }
501
+ if($infoLocation!=='none'){
502
+ if($attr->getData('frontend_class')==='validate-number'){
503
+ if($attr->getFrontend()->getValue($product)!=='No'){
504
+ $product_model[$infoLocation][$attrCode] = floatval($attr->getFrontend()->getValue($product));
505
+ }
506
  } elseif($attr->getData('frontend_class')==='validate-digits'){
507
+ if($attr->getFrontend()->getValue($product)!=='No'){
508
+ $product_model[$infoLocation][$attrCode] = intval($attr->getFrontend()->getValue($product));
509
+ }
510
+ } else {
511
+ if($product->getAttributeText($attrCode)){
512
+ $product_model[$infoLocation][$attrCode] = $product->getAttributeText($attrCode);
513
+ }
514
  }
515
+ }
516
+ }
517
+ //Add the options captured earlier
518
+ if(count($options)){
519
+ $product_model['attributes']['options'] = $options;
520
  }
521
  } catch(Exception $e){
522
  }
606
  $product_model['price']['taxRate'] = ((float) $percent) / 100;
607
 
608
  // For configurable/grouped/composite products, add all associated products to 'linkedProduct'
609
+ if(!$inCart){
610
  if ($product->isConfigurable() || $product->isGrouped() || $product->isComposite()) {
611
 
612
  $product_model['linkedProduct'] = array();
633
  // Add related products to the data layer
634
  $min_price = 0.0;
635
  foreach($simple_collection as $simple_product){
636
+ array_push($product_model['linkedProduct'], $this->_getProductModel($simple_product, false));
637
  $simple_product_price = floatval($simple_product->getPrice());
638
  if ($simple_product_price && (!$min_price || $simple_product_price<$min_price)) {
639
  $min_price = $simple_product_price;
649
  unset($product_model['linkedProduct']);
650
  }
651
  }
652
+ }
653
 
654
  if ($this->_debug) {
655
  $product_model['more']['isConfigurable'] = $product->isConfigurable();
727
  */
728
 
729
  $line_items = array();
 
730
  try {
731
  foreach($items as $item) {
732
  $productId = $item->getProductId();
734
  // product needs to be visible
735
  if ($product->isVisibleInSiteVisibility()) {
736
 
737
+ $litem_model = $this->_getProductModel($item, true);
738
 
739
  if ($page_type == 'cart') {
740
  $litem_model['quantity'] = floatval($item->getQty());
801
  $product = $this->_getCurrentProduct();
802
  if (!$product) return false;
803
  $this->_product = array();
804
+ array_push($this->_product, $this->_getProductModel($product,false));
805
  } catch (Exception $e) {
806
  }
807
  }
858
 
859
  $cart = array();
860
  $quote = $basket->getQuote();
 
861
  // Set normal params
862
  $cart_id = $basket->getQuoteId();
863
  if ($cart_id) {
1070
 
1071
  if ($triggered_messaging_digital_data_layer_enabled==1) {
1072
  $this->_debug = (boolean)Mage::getStoreConfig('triggered_messaging/triggered_messaging_digital_data_layer_debug_enabled');
1073
+ $this->_userGroupExp = (boolean)Mage::getStoreConfig('triggered_messaging/triggered_messaging_digital_data_layer_user_group_enabled');
1074
 
1075
  $this->_setUser();
1076
  $this->_setPage();
app/code/community/TriggeredMessaging/DigitalDataLayer/etc/config.xml CHANGED
@@ -59,6 +59,7 @@
59
  <triggered_messaging>
60
  <triggered_messaging_digital_data_layer_enabled>1</triggered_messaging_digital_data_layer_enabled>
61
  <triggered_messaging_digital_data_layer_debug_enabled>0</triggered_messaging_digital_data_layer_debug_enabled>
 
62
  <triggered_messaging_script_enabled>1</triggered_messaging_script_enabled>
63
  <triggered_messaging_website_id></triggered_messaging_website_id>
64
  </triggered_messaging>
59
  <triggered_messaging>
60
  <triggered_messaging_digital_data_layer_enabled>1</triggered_messaging_digital_data_layer_enabled>
61
  <triggered_messaging_digital_data_layer_debug_enabled>0</triggered_messaging_digital_data_layer_debug_enabled>
62
+ <triggered_messaging_digital_data_layer_user_group_enabled>0</triggered_messaging_digital_data_layer_user_group_enabled>
63
  <triggered_messaging_script_enabled>1</triggered_messaging_script_enabled>
64
  <triggered_messaging_website_id></triggered_messaging_website_id>
65
  </triggered_messaging>
app/code/community/TriggeredMessaging/DigitalDataLayer/etc/system.xml CHANGED
@@ -49,6 +49,21 @@
49
  <TriggeredMessaging_DigitalDataLayer_Enabled>1</TriggeredMessaging_DigitalDataLayer_Enabled>
50
  </depends>
51
  </TriggeredMessaging_DigitalDataLayer_DebugEnabled>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  </fields>
53
  <expanded>1</expanded>
54
  </TriggeredMessaging_DigitalDataLayer_Settings>
49
  <TriggeredMessaging_DigitalDataLayer_Enabled>1</TriggeredMessaging_DigitalDataLayer_Enabled>
50
  </depends>
51
  </TriggeredMessaging_DigitalDataLayer_DebugEnabled>
52
+
53
+ <TriggeredMessaging_DigitalDataLayer_User_GroupEnabled translate="label">
54
+ <label>Enable User Group Exposure</label>
55
+ <frontend_type>select</frontend_type>
56
+ <source_model>adminhtml/system_config_source_yesno</source_model>
57
+ <config_path>triggered_messaging/triggered_messaging_digital_data_layer_user_group_enabled</config_path>
58
+ <comment><![CDATA[ This will expose the user group that any logged in user is a part of. Disable if you require this to be kept private. ]]></comment>
59
+ <sort_order>3</sort_order>
60
+ <show_in_default>1</show_in_default>
61
+ <show_in_website>1</show_in_website>
62
+ <show_in_store>1</show_in_store>
63
+ <depends>
64
+ <TriggeredMessaging_DigitalDataLayer_Enabled>1</TriggeredMessaging_DigitalDataLayer_Enabled>
65
+ </depends>
66
+ </TriggeredMessaging_DigitalDataLayer_User_GroupEnabled>
67
  </fields>
68
  <expanded>1</expanded>
69
  </TriggeredMessaging_DigitalDataLayer_Settings>
app/design/frontend/base/default/template/triggeredmessaging/digital_data_layer.phtml CHANGED
@@ -71,7 +71,7 @@ try {
71
  <?php endif;?>
72
  <?php else: ?>
73
  <script type="text/javascript">
74
- console.log("You have enabled the Triggered Messaging script from the Magento Admin Configuration Panel, but have not supplied a website ID. Please contact hello@triggeredmessaging.com if you would like some assistance.");
75
  </script>
76
  <?php endif;?>
77
  <!-- Triggered Messaging Script End -->
71
  <?php endif;?>
72
  <?php else: ?>
73
  <script type="text/javascript">
74
+ console.log("You have enabled the Triggered Messaging script from the Magento Admin Configuration Panel, but have not supplied a website ID. Please go to http://www.triggeredmessaging.com/contact for support on this.");
75
  </script>
76
  <?php endif;?>
77
  <!-- Triggered Messaging Script End -->
package.xml CHANGED
@@ -1,7 +1,7 @@
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,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-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>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>W3CDigitalDataLayerByTriggeredMessaging</name>
4
+ <version>0.3.6</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-21</date>
33
+ <time>12:23:35</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="c7604beaaf3a32531d5f9b166657ce87"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="8b98dee82241e0b69661bf4699cba334"/><file name="cache.xml" hash="1b6658073a8126cd655cb18109559f49"/><file name="config.xml" hash="12b7aeea72beab187d714cc8d2975ae2"/><file name="system.xml" hash="2b3b9142a583ae381520aa085ccf5a20"/></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="d3351778bc5f00c57a19c752865ff319"/><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>