analytics - Version 2.0.1

Version Notes

Download this release

Release Info

Developer Segment
Extension analytics
Version 2.0.1
Comparing to
See all releases


Code changes from version 2.0.0 to 2.0.1

app/code/community/Segment/Analytics/Block/Template.php CHANGED
@@ -8,16 +8,16 @@ class Segment_Analytics_Block_Template extends Mage_Core_Block_Template
8
  ->setVarName($var_name)
9
  ->toHtml();
10
  }
11
-
12
  public function renderDataAsJsonObject($key=false)
13
  {
14
  $data = $key ? $this->getData($key) : $this->getData();
15
  return $this->getLayout()->createBlock('segment_analytics/json')
16
  ->setData($data)
17
  ->setAsRawObject(true)
18
- ->toHtml();
19
  }
20
-
21
  public function getContextJson()
22
  {
23
  $renderer = $this->getLayout()->createBlock('segment_analytics/json')
@@ -25,19 +25,23 @@ class Segment_Analytics_Block_Template extends Mage_Core_Block_Template
25
  'library'=> array(
26
  'name'=>'analytics-magento',
27
  'version'=>(string) Mage::getConfig()->getNode()->modules->Segment_Analytics->version
28
- )));
29
  return $renderer->toJsonString();
30
  }
31
 
32
  /**
33
  * Ensure safe JSON string, even for Magento systems still
34
  * running on PHP 5.2
35
- */
36
  public function getPropertyAsJavascriptString($prop)
37
  {
38
- $data = (string) $this->getData($prop);
39
- $data = json_encode($data);
40
- $data = preg_replace('%[^ $:"\'a-z>0-9_-]%six','',$data);
 
 
 
 
41
  return $data;
42
  }
43
  }
8
  ->setVarName($var_name)
9
  ->toHtml();
10
  }
11
+
12
  public function renderDataAsJsonObject($key=false)
13
  {
14
  $data = $key ? $this->getData($key) : $this->getData();
15
  return $this->getLayout()->createBlock('segment_analytics/json')
16
  ->setData($data)
17
  ->setAsRawObject(true)
18
+ ->toHtml();
19
  }
20
+
21
  public function getContextJson()
22
  {
23
  $renderer = $this->getLayout()->createBlock('segment_analytics/json')
25
  'library'=> array(
26
  'name'=>'analytics-magento',
27
  'version'=>(string) Mage::getConfig()->getNode()->modules->Segment_Analytics->version
28
+ )));
29
  return $renderer->toJsonString();
30
  }
31
 
32
  /**
33
  * Ensure safe JSON string, even for Magento systems still
34
  * running on PHP 5.2
35
+ */
36
  public function getPropertyAsJavascriptString($prop)
37
  {
38
+ $data = (string) $this->getData($prop);
39
+ if ($prop == 'user_id' && empty($data)) {
40
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
41
+ $data = (string) $customer->getId();
42
+ }
43
+ $data = json_encode($data);
44
+ $data = preg_replace('%[^ $:"\'a-z>0-9_-]%six','',$data);
45
  return $data;
46
  }
47
  }
app/code/community/Segment/Analytics/Helper/Data.php CHANGED
@@ -89,6 +89,11 @@ class Segment_Analytics_Helper_Data extends Mage_Core_Helper_Abstract
89
 
90
  public function getNormalizedProductInformation($product)
91
  {
 
 
 
 
 
92
  //if passed id, load the product
93
  if(!is_array($product))
94
  {
89
 
90
  public function getNormalizedProductInformation($product)
91
  {
92
+ // If passed object, convert to array
93
+ if (is_object($product)) {
94
+ $product = $product->getData();
95
+ }
96
+
97
  //if passed id, load the product
98
  if(!is_array($product))
99
  {
app/code/community/Segment/Analytics/Model/Controller/Addtocart.php CHANGED
@@ -3,9 +3,11 @@ class Segment_Analytics_Model_Controller_Addtocart extends Segment_Analytics_Mod
3
  {
4
  public function getBlock($block)
5
  {
6
- $product = $block->getProduct();
 
 
7
 
8
- $product = Mage::helper('segment_analytics')
9
  ->getNormalizedProductInformation($product);
10
 
11
  $block->setProduct($product);
3
  {
4
  public function getBlock($block)
5
  {
6
+ $params = $block->getParams();
7
+ $product = Mage::getModel('catalog/product_api')
8
+ ->info($params['product_id']);
9
 
10
+ $product = Mage::helper('segment_analytics')
11
  ->getNormalizedProductInformation($product);
12
 
13
  $block->setProduct($product);
app/code/community/Segment/Analytics/Model/Controller/Removefromcart.php CHANGED
@@ -3,9 +3,11 @@ class Segment_Analytics_Model_Controller_Removefromcart extends Segment_Analytic
3
  {
4
  public function getBlock($block)
5
  {
6
- $product = $block->getProduct();
 
 
7
 
8
- $product = Mage::helper('segment_analytics')
9
  ->getNormalizedProductInformation($product);
10
 
11
  $block->setProduct($product);
3
  {
4
  public function getBlock($block)
5
  {
6
+ $params = $block->getParams();
7
+ $product = Mage::getModel('catalog/product_api')
8
+ ->info($params['product_id']);
9
 
10
+ $product = Mage::helper('segment_analytics')
11
  ->getNormalizedProductInformation($product);
12
 
13
  $block->setProduct($product);
app/code/community/Segment/Analytics/Model/Observer.php CHANGED
@@ -86,7 +86,7 @@ class Segment_Analytics_Model_Observer
86
  $product = $observer->getProduct();
87
  $front = Segment_Analytics_Model_Front_Controller::getInstance();
88
  $front->addDeferredAction('addtocart',
89
- array('product'=>$product)
90
  );
91
  }
92
 
@@ -95,7 +95,7 @@ class Segment_Analytics_Model_Observer
95
  $product = $observer->getQuoteItem()->getProduct();
96
  $front = Segment_Analytics_Model_Front_Controller::getInstance();
97
  $front->addDeferredAction('removefromcart',
98
- array('product'=>$product)
99
  );
100
  }
101
 
86
  $product = $observer->getProduct();
87
  $front = Segment_Analytics_Model_Front_Controller::getInstance();
88
  $front->addDeferredAction('addtocart',
89
+ array('params'=>array('product_id'=>$product->getId()))
90
  );
91
  }
92
 
95
  $product = $observer->getQuoteItem()->getProduct();
96
  $front = Segment_Analytics_Model_Front_Controller::getInstance();
97
  $front->addDeferredAction('removefromcart',
98
+ array('params'=>array('product_id'=>$product->getId()))
99
  );
100
  }
101
 
app/code/community/Segment/Analytics/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Segment_Analytics>
5
- <version>2.0.0</version>
6
  </Segment_Analytics>
7
  </modules>
8
  <frontend>
2
  <config>
3
  <modules>
4
  <Segment_Analytics>
5
+ <version>2.0.1</version>
6
  </Segment_Analytics>
7
  </modules>
8
  <frontend>
app/design/frontend/base/default/template/segment_analytics/removefromcart.phtml CHANGED
@@ -1,6 +1,6 @@
1
  <?php //echo $this->renderDataAsJsonVar('segment_analytics_removefromcart'); ?>
2
  <script type="text/javascript">
3
- analytics.track('Added Product',
4
  <?php echo $this->renderDataAsJsonObject('product'); ?>,
5
  <?php echo $this->getContextJson(); ?>);
6
  </script>
1
  <?php //echo $this->renderDataAsJsonVar('segment_analytics_removefromcart'); ?>
2
  <script type="text/javascript">
3
+ analytics.track('Removed Product',
4
  <?php echo $this->renderDataAsJsonObject('product'); ?>,
5
  <?php echo $this->getContextJson(); ?>);
6
  </script>
package.xml CHANGED
@@ -1,2 +1,2 @@
1
  <?xml version="1.0"?>
2
- <package><name>analytics</name><version>2.0.0</version><stability>stable</stability><license>MIT</license><channel>community</channel><extends></extends><summary>Segment lets you integrate 100+ analytics and marketing tools without writing any code yourself!</summary><description>Analytics for Magento is a Magento extension by Segment that lets you integrate any analytics or marketing tool you want with the flick of a switch! No code required. When you turn on the plugin, Segment automatically starts tracking important actions, like when users view items, add products to carts, and complete orders. To send this data along to your preferred tools, just go to the Segment control panel and toggle them on. This will save you months of time installing analytics.</description><notes></notes><authors><author><name>Segment</name><user>segmentio</user><email>friends@segment.io</email></author></authors><date>2015-09-01</date><time>21:54:54</time><compatible></compatible><dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies><contents><target name="mage"><dir name="app"><dir name="code"><dir name="community"><dir name="Segment"><dir name="Analytics"><dir name="Block"><file name="Json.php" hash="77a1bf5dc11b0379bac45ffe92503920"/><file name="Template.php" hash="ad6f341d5288024dadcfa052b94f1cc5"/></dir><dir name="controllers"><file name="IndexController.php" hash="f25a06d702a86f32d0e3667b7a52e51c"/></dir><dir name="etc"><file name="adminhtml.xml" hash="a4f61645101a34f67e08215a2a8c2bb1"/><file name="config.xml" hash="58a1ee8a97092b0e0414183989e3b273"/><file name="system.xml" hash="a745c1dbe5d9333a58b7cf7a6e7ceb7a"/></dir><dir name="Helper"><file name="Data.php" hash="b8ae3d96c1d28afe773ffc0e581c0d2e"/></dir><dir name="Model"><file name="Observer.php" hash="9e348fb5c96a2e07571c11547e245554"/><file name="Session.php" hash="b704f5a8e83a1e88710cce75c14ca8b2"/><dir name="Controller"><file name="Addedtowishlist.php" hash="d7554a3dfeba4389403da77cd8b9b577"/><file name="Addtocart.php" hash="1f3d616574e893384e8bc1d7c9be24f3"/><file name="Alias.php" hash="01957c9ecb7bd18ebbf6b683aa1e26d8"/><file name="Amlistfav.php" hash="77c241aeb10e847809c261fb987ea231"/><file name="Base.php" hash="dbd5d3c31ca986fab5874ba436d92a0a"/><file name="Customerloggedin.php" hash="b90cac939fb3c2cf26bbd7ebc21b0d15"/><file name="Customerloggedout.php" hash="b62011136bff4bd4ffcece4f89e1c5f3"/><file name="Customerregistered.php" hash="bab7b09c54e80aea887b762730bace85"/><file name="Filteredproducts.php" hash="d9f5aa27812bcb2707765c8295daa33d"/><file name="Identity.php" hash="21ab2b0330c9e0b08b73e8fe643322f8"/><file name="Init.php" hash="880bd8d529a07f6a04616e2c98664fe8"/><file name="Layerednavfilter.php" hash="e687405d3e661929fd8ddaf07d1a4e34"/><file name="Orderplaced.php" hash="184d0591c167a9b134d43e7cd39df3cf"/><file name="Page.php" hash="1877a140c41d0fffa30f691fe19ca807"/><file name="Removefromcart.php" hash="49c69353991c5477eb8fa6d845c978c2"/><file name="Reviewedproduct.php" hash="7e5b66d243c7ac56f9e2e1cfc1a4778a"/><file name="Searchedproducts.php" hash="b7cbb325af5125831577be64c38d38b7"/><file name="Subscribenewsletter.php" hash="53bfffba6959a93f815aae40c90a12a5"/><file name="Viewedproduct.php" hash="eb7c8ad13434f25ce1b5b51583308e4a"/><file name="Viewedreviews.php" hash="154c63d724e842afdf8aa018bd551146"/></dir><dir name="Front"><file name="Controller.php" hash="15ad3f72050f44af9bf1eef6311221a4"/></dir><dir name="Observer"><file name="Admin.php" hash="79fdf309e9be6cfa414c76aabff01d03"/><file name="Layered.php" hash="df5693db18782d72e12c8712f20b1031"/><file name="Review.php" hash="8ae59c8446076c1e8876fff3e0a15edf"/></dir><dir name="Query"><file name="Totalpurchased.php" hash="ffb2adc54cfb045d2206a5637cb1c980"/><file name="Totalspent.php" hash="38981ad7ad5aa871d158a1f57062a123"/></dir><dir name="Resource"><file name="Setup.php" hash="05b44bd356c73b475c570b4f39858847"/></dir></dir><dir name="sql"><dir name="segment_analytics_setup"><file name="install-0.0.2.php" hash="6ed374aa1a926ea2da213b7b48688b81"/><file name="upgrade-0.0.2-0.0.3.php" hash="4f5832020a9db0fee5311ed0bfe06df9"/></dir></dir></dir></dir></dir></dir><dir name="design"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="segment_analytics"><file name="welcome-container.phtml" hash="675be69e78118174cc1913bdee1f5eb0"/><file name="welcome.phtml" hash="0a68687ebe8c5ca880387489f1ea2670"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="segment_analytics"><file name="addedtowishlist.phtml" hash="510ea8734d75965f337fb7196ea86591"/><file name="addtocart.phtml" hash="255717ea240821659740e0277971a56b"/><file name="alias.phtml" hash="3e2f76491ca3870b7145d95613489515"/><file name="amlistfav.phtml" hash="8950bdf6d8bf6a758c3a27261dbcfeea"/><file name="customerloggedin.phtml" hash="b6459b72a3af74500c3e0fd600b9b66d"/><file name="customerloggedout.phtml" hash="301129446323a55d7ae1e6cd62603fba"/><file name="customerregistered.phtml" hash="2ae49ebdc261a2ac12666e3f8c88007b"/><file name="filteredproducts.phtml" hash="7bfea3e857aa5cf94d80ac560569215c"/><file name="identity.phtml" hash="de92c0c1f9ee5667188b462d8bae8a33"/><file name="image-frontend.phtml" hash="a82ed48dfcfef10b4e78a03872bda182"/><file name="init.phtml" hash="50ba787142268624339c493b36f057f0"/><file name="layerednavfilter.phtml" hash="c3f57076a76864e8d7c1f939de687b00"/><file name="orderplaced.phtml" hash="1cbe1c7731bb30848bf0cf1204c6e895"/><file name="page.phtml" hash="e50ce55425f8b2725ae22a675e10d575"/><file name="removefromcart.phtml" hash="081276a9ba92dfea39d96ee23ceb52d4"/><file name="review-frontend.phtml" hash="de336d1ad12ffe5cf041c041590c01a1"/><file name="reviewedproduct.phtml" hash="322faa7da6e7b93e236ebff643dd45c3"/><file name="searchedproducts.phtml" hash="bbe966c2b2069ab4cacc204435686c6f"/><file name="share-frontend.phtml" hash="d8a2f53dfb00c271ea653861df7caacc"/><file name="subscribenewsletter.phtml" hash="796e37fa23ec051fd8ff62e80ddb8301"/><file name="viewedproduct.phtml" hash="63948db8120cffa034f291fb295bb1ad"/><file name="viewedreviews.phtml" hash="2e433131130d2f7580f25e3b3d3b03c7"/></dir></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="Segment_Analytics.xml" hash="b594b15ca2fb8187ab8fb49673c91e03"/></dir></dir></dir></target></contents></package>
1
  <?xml version="1.0"?>
2
+ <package><name>analytics</name><version>2.0.1</version><stability>stable</stability><license>MIT</license><channel>community</channel><extends></extends><summary>Segment lets you integrate 100+ analytics and marketing tools without writing any code yourself!</summary><description>Analytics for Magento is a Magento extension by Segment that lets you integrate any analytics or marketing tool you want with the flick of a switch! No code required. When you turn on the plugin, Segment automatically starts tracking important actions, like when users view items, add products to carts, and complete orders. To send this data along to your preferred tools, just go to the Segment control panel and toggle them on. This will save you months of time installing analytics.</description><notes></notes><authors><author><name>Segment</name><user>segmentio</user><email>friends@segment.io</email></author></authors><date>2015-09-17</date><time>16:41:35</time><compatible></compatible><dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies><contents><target name="mage"><dir name="app"><dir name="code"><dir name="community"><dir name="Segment"><dir name="Analytics"><dir name="Block"><file name="Json.php" hash="77a1bf5dc11b0379bac45ffe92503920"/><file name="Template.php" hash="20684f302b7116a4cbc5f9546de8b8de"/></dir><dir name="controllers"><file name="IndexController.php" hash="f25a06d702a86f32d0e3667b7a52e51c"/></dir><dir name="etc"><file name="adminhtml.xml" hash="a4f61645101a34f67e08215a2a8c2bb1"/><file name="config.xml" hash="e4a7436c9e4737732f71b93a2f5d870f"/><file name="system.xml" hash="a745c1dbe5d9333a58b7cf7a6e7ceb7a"/></dir><dir name="Helper"><file name="Data.php" hash="871e8f2c7f41b20f3d342a67e9f8cd7d"/></dir><dir name="Model"><file name="Observer.php" hash="8df7f02fc7119ad065e2ec8d7fd13596"/><file name="Session.php" hash="b704f5a8e83a1e88710cce75c14ca8b2"/><dir name="Controller"><file name="Addedtowishlist.php" hash="d7554a3dfeba4389403da77cd8b9b577"/><file name="Addtocart.php" hash="aa3df1029bfbc7d247be74dd1048e43d"/><file name="Alias.php" hash="01957c9ecb7bd18ebbf6b683aa1e26d8"/><file name="Amlistfav.php" hash="77c241aeb10e847809c261fb987ea231"/><file name="Base.php" hash="dbd5d3c31ca986fab5874ba436d92a0a"/><file name="Customerloggedin.php" hash="b90cac939fb3c2cf26bbd7ebc21b0d15"/><file name="Customerloggedout.php" hash="b62011136bff4bd4ffcece4f89e1c5f3"/><file name="Customerregistered.php" hash="bab7b09c54e80aea887b762730bace85"/><file name="Filteredproducts.php" hash="d9f5aa27812bcb2707765c8295daa33d"/><file name="Identity.php" hash="21ab2b0330c9e0b08b73e8fe643322f8"/><file name="Init.php" hash="880bd8d529a07f6a04616e2c98664fe8"/><file name="Layerednavfilter.php" hash="e687405d3e661929fd8ddaf07d1a4e34"/><file name="Orderplaced.php" hash="184d0591c167a9b134d43e7cd39df3cf"/><file name="Page.php" hash="1877a140c41d0fffa30f691fe19ca807"/><file name="Removefromcart.php" hash="1645493a903cb223cfdb3496c4e8bc3d"/><file name="Reviewedproduct.php" hash="7e5b66d243c7ac56f9e2e1cfc1a4778a"/><file name="Searchedproducts.php" hash="b7cbb325af5125831577be64c38d38b7"/><file name="Subscribenewsletter.php" hash="53bfffba6959a93f815aae40c90a12a5"/><file name="Viewedproduct.php" hash="eb7c8ad13434f25ce1b5b51583308e4a"/><file name="Viewedreviews.php" hash="154c63d724e842afdf8aa018bd551146"/></dir><dir name="Front"><file name="Controller.php" hash="15ad3f72050f44af9bf1eef6311221a4"/></dir><dir name="Observer"><file name="Admin.php" hash="79fdf309e9be6cfa414c76aabff01d03"/><file name="Layered.php" hash="df5693db18782d72e12c8712f20b1031"/><file name="Review.php" hash="8ae59c8446076c1e8876fff3e0a15edf"/></dir><dir name="Query"><file name="Totalpurchased.php" hash="ffb2adc54cfb045d2206a5637cb1c980"/><file name="Totalspent.php" hash="38981ad7ad5aa871d158a1f57062a123"/></dir><dir name="Resource"><file name="Setup.php" hash="05b44bd356c73b475c570b4f39858847"/></dir></dir><dir name="sql"><dir name="segment_analytics_setup"><file name="install-0.0.2.php" hash="6ed374aa1a926ea2da213b7b48688b81"/><file name="upgrade-0.0.2-0.0.3.php" hash="4f5832020a9db0fee5311ed0bfe06df9"/></dir></dir></dir></dir></dir></dir><dir name="design"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="segment_analytics"><file name="welcome-container.phtml" hash="675be69e78118174cc1913bdee1f5eb0"/><file name="welcome.phtml" hash="0a68687ebe8c5ca880387489f1ea2670"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="segment_analytics"><file name="addedtowishlist.phtml" hash="510ea8734d75965f337fb7196ea86591"/><file name="addtocart.phtml" hash="255717ea240821659740e0277971a56b"/><file name="alias.phtml" hash="3e2f76491ca3870b7145d95613489515"/><file name="amlistfav.phtml" hash="8950bdf6d8bf6a758c3a27261dbcfeea"/><file name="customerloggedin.phtml" hash="b6459b72a3af74500c3e0fd600b9b66d"/><file name="customerloggedout.phtml" hash="301129446323a55d7ae1e6cd62603fba"/><file name="customerregistered.phtml" hash="2ae49ebdc261a2ac12666e3f8c88007b"/><file name="filteredproducts.phtml" hash="7bfea3e857aa5cf94d80ac560569215c"/><file name="identity.phtml" hash="de92c0c1f9ee5667188b462d8bae8a33"/><file name="image-frontend.phtml" hash="a82ed48dfcfef10b4e78a03872bda182"/><file name="init.phtml" hash="50ba787142268624339c493b36f057f0"/><file name="layerednavfilter.phtml" hash="c3f57076a76864e8d7c1f939de687b00"/><file name="orderplaced.phtml" hash="1cbe1c7731bb30848bf0cf1204c6e895"/><file name="page.phtml" hash="e50ce55425f8b2725ae22a675e10d575"/><file name="removefromcart.phtml" hash="17654d6abf0df721b8dcc854092af09d"/><file name="review-frontend.phtml" hash="de336d1ad12ffe5cf041c041590c01a1"/><file name="reviewedproduct.phtml" hash="322faa7da6e7b93e236ebff643dd45c3"/><file name="searchedproducts.phtml" hash="bbe966c2b2069ab4cacc204435686c6f"/><file name="share-frontend.phtml" hash="d8a2f53dfb00c271ea653861df7caacc"/><file name="subscribenewsletter.phtml" hash="796e37fa23ec051fd8ff62e80ddb8301"/><file name="viewedproduct.phtml" hash="63948db8120cffa034f291fb295bb1ad"/><file name="viewedreviews.phtml" hash="2e433131130d2f7580f25e3b3d3b03c7"/></dir></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="Segment_Analytics.xml" hash="b594b15ca2fb8187ab8fb49673c91e03"/></dir></dir></dir></target></contents></package>