├── History.md
├── Install.md
├── Readme.md
├── app
├── code
│ └── community
│ │ └── Segment
│ │ └── Analytics
│ │ ├── Block
│ │ ├── Json.php
│ │ └── Template.php
│ │ ├── Helper
│ │ └── Data.php
│ │ ├── Model
│ │ ├── Controller
│ │ │ ├── Addedtowishlist.php
│ │ │ ├── Addtocart.php
│ │ │ ├── Alias.php
│ │ │ ├── Amlistfav.php
│ │ │ ├── Base.php
│ │ │ ├── Customerloggedin.php
│ │ │ ├── Customerloggedout.php
│ │ │ ├── Customerregistered.php
│ │ │ ├── Filteredproducts.php
│ │ │ ├── Identity.php
│ │ │ ├── Init.php
│ │ │ ├── Layerednavfilter.php
│ │ │ ├── Orderplaced.php
│ │ │ ├── Page.php
│ │ │ ├── Removefromcart.php
│ │ │ ├── Reviewedproduct.php
│ │ │ ├── Searchedproducts.php
│ │ │ ├── Subscribenewsletter.php
│ │ │ ├── Viewedproduct.php
│ │ │ └── Viewedreviews.php
│ │ ├── Front
│ │ │ └── Controller.php
│ │ ├── Observer.php
│ │ ├── Observer
│ │ │ ├── Admin.php
│ │ │ ├── Layered.php
│ │ │ └── Review.php
│ │ ├── Query
│ │ │ ├── .DS_Store
│ │ │ ├── Totalpurchased.php
│ │ │ └── Totalspent.php
│ │ ├── Resource
│ │ │ └── Setup.php
│ │ └── Session.php
│ │ ├── controllers
│ │ └── IndexController.php
│ │ ├── etc
│ │ ├── adminhtml.xml
│ │ ├── config.xml
│ │ └── system.xml
│ │ └── sql
│ │ └── segment_analytics_setup
│ │ ├── install-0.0.2.php
│ │ └── upgrade-0.0.2-0.0.3.php
├── design
│ ├── adminhtml
│ │ └── default
│ │ │ └── default
│ │ │ └── template
│ │ │ └── segment_analytics
│ │ │ ├── welcome-container.phtml
│ │ │ └── welcome.phtml
│ └── frontend
│ │ └── base
│ │ └── default
│ │ └── template
│ │ └── segment_analytics
│ │ ├── addedtowishlist.phtml
│ │ ├── addtocart.phtml
│ │ ├── alias.phtml
│ │ ├── amlistfav.phtml
│ │ ├── customerloggedin.phtml
│ │ ├── customerloggedout.phtml
│ │ ├── customerregistered.phtml
│ │ ├── filteredproducts.phtml
│ │ ├── identity.phtml
│ │ ├── image-frontend.phtml
│ │ ├── init.phtml
│ │ ├── layerednavfilter.phtml
│ │ ├── orderplaced.phtml
│ │ ├── page.phtml
│ │ ├── removefromcart.phtml
│ │ ├── review-frontend.phtml
│ │ ├── reviewedproduct.phtml
│ │ ├── searchedproducts.phtml
│ │ ├── share-frontend.phtml
│ │ ├── subscribenewsletter.phtml
│ │ ├── viewedproduct.phtml
│ │ └── viewedreviews.phtml
└── etc
│ └── modules
│ └── Segment_Analytics.xml
├── bin
└── build
├── dist
├── analytics-2.0.1.tgz
├── analytics-latest.tgz
└── var
│ └── connect
│ └── analytics.xml
└── support
├── MagentoTarToConnect
├── README.md
├── _cli_stub.php
├── build.xml
├── example-config.php
├── magento-tar-to-connect.php
└── vendor
│ └── magento
│ └── downloader
│ └── lib
│ └── Mage
│ ├── Archive
│ ├── Abstract.php
│ ├── Helper
│ │ └── File.php
│ ├── Interface.php
│ └── Tar.php
│ └── Exception.php
└── config.php
/History.md:
--------------------------------------------------------------------------------
1 | 2.0.1 / 2015-09-17
2 | ==================
3 | * Identified and fixed bug affecting added/removed product behavior
4 |
5 | 2.0.0 / 2015-09-01
6 | ==================
7 |
8 | * The identify logic was filtering the userId from its usable data before it could render it into the `userId` field of its call. This meant that we weren't reliably rendering the userId in the one identify call we were firing on registration. That's been **fixed.**
9 | * `Added Product` and `Removed Product` only used to pass SKU; now they pass the full product info dictionary
10 | * Call identify on every page when the user is logged in, not just on registration
11 | * Allow store owner to optionally flush a.js `user()` object with [`analytics.reset()`](https://segment.com/docs/libraries/analytics.js/#reset-logout) after customers log out (defaults to false)
12 | * Allow store owner to optionally pass product properties which they'd like to **omit** from their product info dictionary (the same one used to populate `Completed Order`, `Viewed Product`, `Added Product`, and `Removed Product` properties). This allows them to deny fields from being rendered in analytics calls.
13 | * Strips all `null` K/V pairs from product properties by default.
14 | * Customer log out used to trigger two `Logged Out` events due to a redundant logout mechanism that would attempt to grab the customers id to use post-logout. That mechanism has been removed. If a user opts not to flush (# 4 above), then analytics.js will handle caching and use of the resilient `userId`. If they do flush, then they will deliberately not have that id after logout.
15 |
16 | 1.1.0 / 2015-08-20
17 | ==================
18 |
19 | * fix duplicate category bug
20 | * remove debug logging
21 | * add intro text
22 | * adding functionality to record discounts and revenue
23 | * removing code that accidentally overwrites casting of Magento product info into Segment API friendly product info
24 |
25 | 1.0.0 - August 23, 2014
26 | -----------------------
27 | * first stable release
28 |
29 | 0.0.1 - July 14, 2014
30 | ---------------------
31 | * initial release
32 |
--------------------------------------------------------------------------------
/Install.md:
--------------------------------------------------------------------------------
1 | Installing Extension
2 | --------------------------------------------------
3 |
4 | Analytics for Magento is distributed as a Magento Connect `tgz` file. This means there's three ways to install it.
5 |
6 | - Directly via a Magento Connect extension key **NOTE**: Link to Connect page when it's setup.
7 |
8 | - By uploading the `tgz` extension via the Magento Connect Manager
9 |
10 | - By copying the extension source manually to your Magento system.
11 |
12 | ## Magento Connect Key Instructions
13 |
14 | - Log into to your Magento Connect Account
15 |
16 | - Browse to the Analytics for Magento page on Magento Connect (**NOTE**: Link to page when ready)
17 |
18 | - Click the Install Now button
19 |
20 | - Copy the Extension Key
21 |
22 | - Log into your Magento Admin console
23 |
24 | - Browse to `System -> Magento Connect -> Magento Connect Manager`
25 |
26 | - Re-enter your credentials
27 |
28 | - Paste the extension key from above into the field labeled *Paste Extension Key to Install*
29 |
30 | - Click the install button
31 |
32 | - Magento Connect will install the package into your system
33 |
34 | ## Uploading the Extension
35 |
36 | - Download the extension from the [releases page](https://github.com/segmentio/analytics-magento/releases)
37 |
38 | - Log into your Magento Admin console
39 |
40 | - Browse to `System -> Magento Connect -> Magento Connect Manager`
41 |
42 | - Re-enter your credentials
43 |
44 | - Click the Choose File button
45 |
46 | - Select the downloaded `tgz` extension from your file system
47 |
48 | - Click Upload
49 |
50 | - Click Install Now
51 |
52 | - Magento Connect will install the package into your system
53 |
54 | ## Copying Extension Source
55 |
56 | - Ensure your Magento Cache is off, and that Magento is not running in compilation mode
57 |
58 | - Copy the contents of the extension's `app` folder to your server. Be sure you're uploading the contents of the folder, and not replacing your entire system's app folder
59 |
60 | - With the Magento cache off or cleared, browse to `System -> Configuration -> Advanced` and ensure the `Segment_Analytics` extension is installed
61 |
62 | - If you're using the Magento class compiler, recompile your classes
63 |
64 | - If you're using the Magento cache, reenable it
65 |
66 | ## Post Installation Steps
67 |
68 | After installing the extension, you may enter your Segment key at
69 |
70 | System -> Configuration -> Analytics
71 |
72 | If this page returns a 404 (common during a manual install) logout and log back in to clear your cached Magento session.
--------------------------------------------------------------------------------
/Readme.md:
--------------------------------------------------------------------------------
1 |
2 | # Analytics for Magento
3 |
4 | > **NOTE**: Official support from Segment for this plugin is **deprecated**. We are currently looking for community maintainers. The current version of this plugin should be free of bugs but any existing and future development will be paused for the time being. We recommend exploring and using third party alternatives. **Specifically, the folks at Windsor Circle are maintaining an [active fork of the plugin](https://github.com/windsor-circle/analytics-magento) driving towards support for Magento 2.** If you have any questions, please send us an email at friends@segment.com!
5 |
6 | **Analytics for Magento** is a Magento extension for [Segment](https://segment.com) that lets you send data to any analytics tool you want without writing any code yourself!
7 |
8 | - [Installing](#installing)
9 | - [Support](#support)
10 | - [Developing](#developing)
11 | - [Deploying](#deploying)
12 |
13 |
14 | ## Installing
15 |
16 | To get up and running, check out our documentation at [DEPRECATED] [https://segment.com/docs/plugins/magento](https://segment.com/docs/plugins/magento). Installation takes less than five minutes!
17 |
18 |
19 | ## Support
20 |
21 | If you run into issues, be sure to check out the [documentation](https://segment.com/docs/plugins/magento), and you can always reach out to our [support team](https://segment.com/support) for help!
22 |
23 |
24 | ## Developing
25 |
26 | _Note: this section only applies if you are interested in contributing improvements to our Magento extension's source code. You don't need to read this to use the extension in your own store._
27 |
28 | TODO: We don't yet have detailed instructions for installing a local development version of Magento.
29 |
30 |
31 | ## Deploying
32 |
33 | _Note: this section only applies to Segment teammates, and details how we deploy new versions of the extension to the Magento Connect marketplace for end users of the extension to download._
34 |
35 | Before deploying, make sure to pull in the latest changes from the remote repository:
36 |
37 | $ git pull origin master
38 |
39 | The first step after making your changes to the extension source is to tag a new release of the extension. To do that, first bump the version number in [`app/etc/modules/Segment_Analytics.xml`](app/code/community/Segment/Analytics/etc/config.xml).
40 |
41 | Then, update [`History.md`](History.md) with a summary of your changes.
42 |
43 | Once you've bumped the version and updated the changelog, you need to rebuild the distribution files in [`dist/`](dist/) by running the build script:
44 |
45 | $ bin/build
46 |
47 | Then commit those changes, and tag the release (where `X.X.X` is the number of the newest version):
48 |
49 | $ git commit -am 'X.X.X'
50 | $ git tag 'X.X.X'
51 | $ git push origin master
52 | $ git push origin X.X.X
53 |
54 | Once you've done that, you'll need to log into our [Magento Connect]() account, and navigate to **Your Account > Developers > Manage Extensions** and click the **Edit** button on the **Analytics for Magento** extension. That will take you to the extension editing page. From there, click the **Versions** tab and then the **Add new version** button.
55 |
56 | Fill out the form for adding a new version, supplying the `X.X.X` version number as the **Release Notes Title** as well, and the list from [`History.md`](History.md) as the **Release Notes**. For the **Versions** check `1.7` and above. Then click the **Continue to upload** button.
57 |
58 | On the upload form page click **Choose File** and find the `analytics-magento-X.X.X` file on your computer from the [`dist/`](dist) directory, then hit **Upload and save**.
59 |
60 | And you're finally done!
61 |
62 |
63 | ## Resources
64 |
65 | - [Analytics for Magento Listing](http://www.magentocommerce.com/magento-connect/extension-171.html) - Our extension's listing on Magento Connect.
66 | - [Magento Tar to Connect](http://alanstorm.com/magento_connect_from_tar) - The script we use to build Magento Connect compatible files.
67 | - [Magento Extension Design Guidelines](http://info.magento.com/rs/magentocommerce/images/0448_Connect_DevStyleguide_v6.pdf?mkt_tok=3RkMMJWWfF9wsRokvK7BZKXonjHpfsX94%2B0oWKSg38431UFwdcjKPmjr1YEGTcZ0dvycMRAVFZl5nQFZHeWbaI9D9fhQDlOxXQ%3D%3D) - Guidelines for extensions to adhere to.
68 |
69 |
70 | ## License
71 |
72 | Copyright © 2014 Segment <friends@segment.com>
73 |
74 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
75 |
76 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
77 |
78 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
79 |
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Block/Json.php:
--------------------------------------------------------------------------------
1 | getVarName();
7 | $json = $this->toJsonString();
8 |
9 | if($this->getAsRawObject())
10 | {
11 | return $json;
12 | }
13 |
14 | return '';
17 | }
18 |
19 | public function toJsonString($data=false)
20 | {
21 | $data = $data ? $data : $this->getDataWithoutExtras();
22 | $json = Mage::helper("core")->jsonEncode($data);
23 | $json = preg_replace('%[\r\n]%','',$json);
24 | return $json;
25 | }
26 |
27 | public function getDataWithoutExtras()
28 | {
29 | $data = $this->getData();
30 | unset($data['type']);
31 | unset($data['module_name']);
32 | unset($data['var_name']);
33 | unset($data['as_raw_object']);
34 | return $data;
35 | }
36 | }
37 |
38 |
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Block/Template.php:
--------------------------------------------------------------------------------
1 | getLayout()->createBlock('segment_analytics/json')
7 | ->setData($this->getData())
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')
24 | ->setData(array(
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:
--------------------------------------------------------------------------------
1 | getStore()->isAdmin();
17 | }
18 |
19 | public function isEnabled()
20 | {
21 | return !$this->isAdmin() && $this->getWriteKey();
22 | }
23 |
24 | public function getCategoryNamesFromIds($ids)
25 | {
26 | $ids = is_array($ids) ? $ids : array($ids);
27 | $categories = Mage::getModel('catalog/category')->getCollection()
28 | ->addAttributeToSelect('name')
29 | ->addFieldToFilter('entity_id', array('in'=>$ids));
30 |
31 | $names = array();
32 | foreach($categories as $category)
33 | {
34 | $names[] = $category->getName();
35 | }
36 | return $names;
37 | }
38 |
39 | /**
40 | * Changes standard page titles per segment API. Hopefully
41 | * this is kept to a minimum
42 | * @todo refactor if this goes beyond page
43 | */
44 | public function getNormalizedPageTitle($title)
45 | {
46 | if(strpos($title, $this->__('Search results for')) !== false)
47 | {
48 | $title = 'Search Results';
49 | }
50 |
51 | return $title;
52 | }
53 |
54 | public function getNormalizedCustomerInformation($data)
55 | {
56 | $swap = array(
57 | 'firstname'=>'first_name',
58 | 'lastname'=>'last_name');
59 |
60 | //nomalize items from $swap
61 | foreach($swap as $old=>$new)
62 | {
63 | if(!array_key_exists($old, $data))
64 | {
65 | continue;
66 | }
67 | $data[$new] = $data[$old];
68 | unset($data[$old]);
69 | }
70 |
71 | //normalize dates
72 | $data = $this->_normalizeDatesToISO8601($data);
73 |
74 | //only
75 | $fields = trim(Mage::getStoreConfig('segment_analytics/options/customer_traits'));
76 | $to_send = preg_split('%[\n\r]%', $fields, -1, PREG_SPLIT_NO_EMPTY);
77 |
78 | $data_final = array();
79 | foreach($to_send as $field)
80 | {
81 | $data_final[$field] = array_key_exists($field, $data) ? $data[$field] : null;
82 | }
83 |
84 | $data_final = $this->getDataCastAsBooleans($data_final);
85 |
86 | return $data_final;
87 |
88 | }
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 | {
100 | $product = Mage::getModel('catalog/product_api')->info($product);
101 | }
102 |
103 | //calculate revenue, if present
104 | $product['id'] = $product['product_id'];
105 | if(array_key_exists('cost',$product))
106 | {
107 | $product['revenue'] = $product['price'] - $product['cost'];
108 | }
109 |
110 | //ensure category names/labels are sent along
111 | $categories = Mage::getModel('catalog/category')->getCollection()
112 | ->addAttributeToSelect('name')
113 | ->addFieldToFilter('entity_id', array('in'=>$product['category_ids']));
114 | foreach($categories as $category)
115 | {
116 | $product['categories'][] = $category->getName();
117 | }
118 |
119 | //cast numerics as floats per segment requirements
120 | $as_float = array('price','weight');
121 | foreach($as_float as $key)
122 | {
123 | if(!array_key_exists($key, $product)) { continue; }
124 | $product[$key] = (float) $product[$key];
125 | }
126 |
127 | //segments wants "id" not product_id
128 | if(array_key_exists('product_id', $product))
129 | {
130 | $product['id'] = $product['product_id'];
131 | unset($product['product_id']);
132 | }
133 |
134 | $denylist = trim(Mage::getStoreConfig('segment_analytics/options/product_properties'));
135 | $deniedFields = preg_split('%[\n\r]%', $denylist, -1, PREG_SPLIT_NO_EMPTY);
136 |
137 | foreach($deniedFields as $key)
138 | {
139 | if(!array_key_exists($key, $product)) { continue; }
140 | unset($product[$key]);
141 | }
142 |
143 | $product = $this->getDataCastAsBooleans($product);
144 | $product = array_filter($product, function($v, $k) {
145 | return !is_null($v);
146 | });
147 | return $this->_normalizeDatesToISO8601($product);
148 | }
149 |
150 | /**
151 | * Central place for casting of '1' and '0' as boolean
152 | * where we know it needs to happen. Segment API requirement
153 | */
154 | public function getDataCastAsBooleans($data)
155 | {
156 | $keys_boolean = array('has_options','is_active','customer_is_guest','customer_note_notify',
157 | 'email_sent','forced_shipment_with_invoice','paypal_ipn_customer_notified','is_virtual',
158 | 'is_qty_decimal', 'no_discount','is_nominal');
159 | foreach($keys_boolean as $key)
160 | {
161 | if(!array_key_exists($key, $data)) { continue; }
162 | $data[$key] = (boolean) $data[$key];
163 | }
164 | return $this->_normalizeDatesToISO8601($data);
165 | }
166 |
167 | protected function _normalizeDatesToISO8601($data)
168 | {
169 | $date_fields = array('created_at', 'updated_at');
170 | foreach($date_fields as $key)
171 | {
172 | if(!array_key_exists($key, $data))
173 | {
174 | continue;
175 | }
176 | $data[$key] = date(DATE_ISO8601,strToTime($data[$key]));
177 | }
178 | return $data;
179 | }
180 |
181 | public function normalizeReviewwData($data)
182 | {
183 | return $this->_normalizeDatesToISO8601($data);
184 | }
185 | }
186 |
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Controller/Addedtowishlist.php:
--------------------------------------------------------------------------------
1 | getParams();
7 | $info = Mage::getModel('catalog/product_api')
8 | ->info($params['product_id']);
9 |
10 | $info = Mage::helper('segment_analytics')
11 | ->getNormalizedProductInformation($info);
12 |
13 | $want = array('sku', 'price', 'name');
14 | foreach($info as $key=>$value)
15 | {
16 | if(!in_array($key, $want)){continue;}
17 | $params[$key] = $value;
18 | }
19 |
20 | $block->setParams($params);
21 | return $block;
22 | }
23 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Controller/Addtocart.php:
--------------------------------------------------------------------------------
1 | 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);
14 |
15 | return $block;
16 | }
17 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Controller/Alias.php:
--------------------------------------------------------------------------------
1 | _getCustomerSession();
7 | if($customer->getCustomer()->getData('is_segment_aliased'))
8 | {
9 | return false;
10 | }
11 | $customer->getCustomer()->setData('is_segment_aliased','1')->save();
12 | $block->setUserId($customer->getId());
13 | return $block;
14 | }
15 |
16 |
17 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Controller/Amlistfav.php:
--------------------------------------------------------------------------------
1 | info($block->getProductId());
7 | $info = Mage::helper('segment_analytics')
8 | ->getNormalizedProductInformation($info);
9 | $block->setParams($info);
10 | return $block;
11 | }
12 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Controller/Base.php:
--------------------------------------------------------------------------------
1 | _getDefaultBlock();
11 | return $this->getBlock($block);
12 | }
13 |
14 | protected function _getDefaultBlock()
15 | {
16 | $key = Mage::helper('segment_analytics')->getWriteKey();
17 | $block = $this->getLayout()->createBlock('segment_analytics/template')
18 | ->setTemplate('segment_analytics/'.$this->getName().'.phtml')
19 | ->setKey($key);
20 | if(is_array($this->getData()))
21 | {
22 | $block->addData($this->getData());
23 | }
24 | return $block;
25 | }
26 |
27 | public function setData($value)
28 | {
29 | $this->_data = $value;
30 | return $this;
31 | }
32 |
33 | public function getData()
34 | {
35 | return $this->_data;
36 | }
37 |
38 | public function setName($value)
39 | {
40 | $this->_name = $value;
41 | return $this;
42 | }
43 |
44 | public function getName()
45 | {
46 | return $this->_name;
47 | }
48 |
49 | public function getLayout()
50 | {
51 | return Mage::getSingleton('core/layout');
52 | }
53 |
54 | public function getFullActionName($delimiter='_')
55 | {
56 | return $this->getRequest()->getRequestedRouteName().$delimiter.
57 | $this->getRequest()->getRequestedControllerName().$delimiter.
58 | $this->getRequest()->getRequestedActionName();
59 | }
60 |
61 | public function getRequest()
62 | {
63 | return Mage::app()->getRequest();
64 | }
65 |
66 |
67 | protected function _getCustomerSession()
68 | {
69 | return Mage::getSingleton('customer/session');
70 | }
71 |
72 | protected function _getCustomer()
73 | {
74 | $customer = Mage::getSingleton('customer/session')->getCustomer();
75 |
76 | //pull entire customer, including eav attributes not initially populated
77 | $full_customer = Mage::getModel('customer/customer')->getCollection()
78 | ->addAttributeToSelect('*')->addFieldToFilter('entity_id', $customer->getId())
79 | ->getFirstItem();
80 | return $full_customer;
81 | }
82 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Controller/Customerloggedin.php:
--------------------------------------------------------------------------------
1 | _getCustomer();
7 | $block->setUserId($customer->getId());
8 |
9 | $data = $block->getData();
10 | $data = Mage::helper('segment_analytics')->getNormalizedCustomerInformation($data);
11 | $block->setData($data);
12 |
13 | return $block;
14 | }
15 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Controller/Customerloggedout.php:
--------------------------------------------------------------------------------
1 | getCustomer();
7 | foreach(array('password_hash') as $key)
8 | {
9 | if(!array_key_exists($key, $customer)) { continue; }
10 | unset($customer[$key]);
11 | }
12 | $customer = Mage::helper('segment_analytics')->getNormalizedCustomerInformation($customer);
13 | $block->setUserId($customer['entity_id']);
14 | return $block;
15 | }
16 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Controller/Customerregistered.php:
--------------------------------------------------------------------------------
1 | getData();
7 | $data = Mage::helper('segment_analytics')->getNormalizedCustomerInformation($data);
8 | $block->setData($data);
9 | return $block;
10 | }
11 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Controller/Filteredproducts.php:
--------------------------------------------------------------------------------
1 | _getCustomer();
7 |
8 | if(!$customer->getId())
9 | {
10 | return false;
11 | }
12 |
13 | $gender_label = $customer->getResource()
14 | ->getAttribute('gender')
15 | ->getSource()
16 | ->getOptionText($customer->getData('gender'));
17 |
18 | $address = Mage::getModel('customer/address')->load(
19 | $customer->getDefaultBilling()
20 | );
21 |
22 | $block->setUserId($customer->getId())
23 | ->addData($customer->getData())
24 | ->setFullName($customer->getName())
25 | ->setName($customer->getName())
26 | ->setEmail($customer->getEmail())
27 | ->setGroupId($customer->getGroupId())
28 | ->setTaxClassId($customer->getTaxClassId())
29 | ->setSharedStoreIds((array)$customer->getSharedStoreIds())
30 | ->setSharedWebsiteIds((array)$customer->getSharedWebsiteIds())
31 | ->setGender($gender_label)
32 | ->setFirstName($customer->getFirstname())
33 | ->setLastName($customer->getLastname())
34 | ->setMiddleName($customer->getMiddlename())
35 | ->setTotalOrders(
36 | Mage::getSingleton('segment_analytics/query_totalpurchased')
37 | ->fetchTotalOrders($customer->getId())
38 | )
39 | ->setTotalSpent(
40 | Mage::getSingleton('segment_analytics/query_totalspent')
41 | ->fetchTotalSpent($customer->getId())
42 | )
43 | ->unsetData('password_hash')
44 | ->unsetData('firstname')
45 | ->unsetData('lastname')
46 | ->unsetData('middlename');
47 |
48 | if($address)
49 | {
50 | $region = Mage::getModel('directory/region')->load($address->getRegionId());
51 | $street = $address->getStreet();
52 | $street = implode("\n", $street);
53 | $block
54 | ->setData('city', $address->getCity())
55 | ->setData('country', $address->getCountryId())
56 | ->setData('postalCode', $address->getPostcode())
57 | ->setData('state', $region->getCode())
58 | ->setData('street', $street);
59 | }
60 | $data = $block->getData();
61 | $data = Mage::helper('segment_analytics')->getNormalizedCustomerInformation($data);
62 | $block->setData($data);
63 | return $block;
64 | }
65 |
66 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Controller/Init.php:
--------------------------------------------------------------------------------
1 | getParams();
7 |
8 | $params['category'] = Mage::helper('segment_analytics')
9 | ->getCategoryNamesFromIds($params['request']['id']);
10 | $block->setParams($params);
11 |
12 | return $block;
13 | }
14 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Controller/Orderplaced.php:
--------------------------------------------------------------------------------
1 | getParams();
7 |
8 | $info = Mage::getModel('sales/order_api')
9 | ->info($params['increment_id']);
10 |
11 | $params['total'] = (float) $info['grand_total'];
12 | $params['revenue'] = (float) $info['subtotal'];
13 | $params['status'] = $info['status'];
14 | $params['shipping'] = (float) $info['shipping_amount'];
15 | $params['tax'] = (float) $info['tax_amount'];
16 | $params['discount'] = (-1 * (float) $info['discount_amount']);
17 | $params['products'] = array();
18 | foreach($info['items'] as $item)
19 | {
20 | $tmp = array();
21 | $tmp['sku'] = $item['sku'];
22 | $tmp['name'] = $item['name'];
23 | $tmp['price'] = (float) $item['price'];
24 | $tmp['quantity'] = (float) $item['qty_ordered'];
25 | $tmp['product_id'] = (int) $item['product_id'];
26 |
27 | $params['products'][] = $tmp;
28 | }
29 |
30 |
31 | //the serialized information
32 | $block->setParams($params);
33 |
34 | return $block;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Controller/Page.php:
--------------------------------------------------------------------------------
1 | _getCategoryNames();
7 | $product = $this->_getCurrentProduct();
8 | if($names)
9 | {
10 | $block->setCategoryNames($names)
11 | ->setPageTitle('Category Listing')
12 | ->setFullCategoryName(implode(' -> ',$names));
13 | return $block;
14 | }
15 |
16 | if($product)
17 | {
18 | $block->setPageName('Product');
19 | return $block;
20 | }
21 |
22 | $title = Mage::getSingleton('core/layout')->getBlock('head')->getTitle();
23 | $title = Mage::helper('segment_analytics')->getNormalizedPageTitle($title);
24 |
25 | $block->setPageName($title);
26 |
27 | return $block;
28 | }
29 |
30 | protected function _getCurrentProduct()
31 | {
32 | return Mage::registry('product');
33 | }
34 |
35 | protected function _getCategoryPageHandles()
36 | {
37 | return array('catalog_category_view');
38 | }
39 |
40 | protected function _getCategoryNames()
41 | {
42 |
43 | if(!in_array($this->getFullActionName(), $this->_getCategoryPageHandles()))
44 | {
45 | return;
46 | }
47 |
48 | $current_category = Mage::registry('current_category');
49 | $category = $current_category;
50 | if(!$current_category)
51 | {
52 | return;
53 | }
54 | $ids = array($category->getId());
55 | $categories = array($category);
56 | while($parent_id = $category->getParentId())
57 | {
58 | $ids[] = $parent_id;
59 | $category = Mage::getModel('catalog/category')->load($parent_id);
60 | $categories[] = $category;
61 | }
62 | //pop off root
63 | array_pop($categories);
64 | $names = array();
65 | foreach($categories as $category)
66 | {
67 | $names[] = $category->getName();
68 | }
69 | $names = array_reverse($names);
70 | return $names;
71 | }
72 |
73 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Controller/Removefromcart.php:
--------------------------------------------------------------------------------
1 | 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);
14 |
15 | return $block;
16 | }
17 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Controller/Reviewedproduct.php:
--------------------------------------------------------------------------------
1 | getReview();
7 | unset($review['customer_id']);
8 | unset($review['form_key']);
9 | $review = Mage::helper('segment_analytics')->normalizeReviewwData($review);
10 | $block->setReview($review);
11 | return $block;
12 | }
13 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Controller/Searchedproducts.php:
--------------------------------------------------------------------------------
1 | getParams();
7 | // $product = Mage::getModel('catalog/product_api')->info($params['id']);
8 |
9 | $product = Mage::helper('segment_analytics')
10 | ->getNormalizedProductInformation($params['id']);
11 |
12 | $block->setParams($product);
13 | return $block;
14 | }
15 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Controller/Viewedreviews.php:
--------------------------------------------------------------------------------
1 | getParams();
7 |
8 | $info = Mage::getModel('catalog/product_api')
9 | ->info($params['id']);
10 |
11 | $info = Mage::helper('segment_analytics')
12 | ->getNormalizedProductInformation($info);
13 |
14 | $want = array('sku', 'price', 'name');
15 | foreach($info as $key=>$value)
16 | {
17 | if(!in_array($key, $want)){continue;}
18 | $params[$key] = $value;
19 | }
20 |
21 | $block->setParams($params);
22 | return $block;
23 | }
24 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Front/Controller.php:
--------------------------------------------------------------------------------
1 | action = $action;
27 | $o_action->data = $action_data;
28 |
29 | $session = $this->_getSession();
30 | $deferred = $session->getDeferredActions();
31 | $deferred = $deferred ? $deferred : array();
32 | $deferred[] = $o_action;
33 | $session->setDeferredActions($deferred);
34 |
35 | return $this;
36 | }
37 |
38 | public function clearDeferredActions()
39 | {
40 | Mage::getSingleton('segment_analytics/session')
41 | ->setDeferredActions(array())
42 | ->setDeferredActionsData(array());
43 | #Mage::Log("Cleared Deferred Action");
44 | return $this;
45 | }
46 |
47 | public function getDeferredActions()
48 | {
49 | $actions = Mage::getSingleton('segment_analytics/session')
50 | ->getDeferredActions();
51 | $actions = $actions ? $actions : array();
52 | return $actions;
53 | }
54 |
55 | protected function _getSession()
56 | {
57 | return Mage::getSingleton('segment_analytics/session');
58 | }
59 |
60 | public function addAction($action,$data=array())
61 | {
62 | $this->_actions[] = $action;
63 | $this->_actionsData[$action] = $data;
64 | return $this;
65 | }
66 |
67 | public function getBlocks()
68 | {
69 | $blocks[] = array();
70 | foreach($this->_actions as $action)
71 | {
72 | $class = 'Segment_Analytics_Model_Controller_' . ucwords($action);
73 | $controller = new $class;
74 | $controller->setName($action)
75 | ->setData($this->_actionsData[$action]);
76 | $blocks[$action][] = $controller->dispatch();
77 | }
78 |
79 | foreach($this->getDeferredActions() as $action)
80 | {
81 | $class = 'Segment_Analytics_Model_Controller_' . ucwords($action->action);
82 | $controller = new $class;
83 | $controller->setName($action->action)
84 | ->setData($action->data);
85 | $blocks[$action->action][] = $controller->dispatch();
86 | }
87 |
88 | //reorder based on sort priority, filter out !blocks
89 | $blocks_ordered = array();
90 | $sort_order = $this->getSortOrder();
91 | $orders = array_keys($sort_order);
92 | sort($orders);
93 | foreach($orders as $order)
94 | {
95 | $action = $sort_order[$order];
96 | if(!array_key_exists($action, $blocks)) { continue; }
97 | $blocks_ordered[$action] = $blocks[$action];
98 | unset($blocks[$action]);
99 | }
100 |
101 | //now any blocks not included in the sort order
102 | foreach($blocks as $block)
103 | {
104 | $blocks_ordered[] = $block;
105 | }
106 | $this->clearDeferredActions();
107 |
108 | //flatten array
109 | $final = array();
110 | foreach($blocks_ordered as $array)
111 | {
112 | foreach($array as $block)
113 | {
114 | $final[] = $block;
115 | }
116 |
117 | }
118 | return $final;
119 | }
120 |
121 | protected function getSortOrder()
122 | {
123 | return array(
124 | 10=>'init',
125 | 30=>'alias',
126 | 20=>'page',
127 | 40=>'identity',
128 | );
129 | }
130 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Observer.php:
--------------------------------------------------------------------------------
1 | getBlock('before_body_end');
18 | if(!$before_body_end)
19 | {
20 | Mage::Log("No before body end in " . __METHOD__);
21 | return;
22 | }
23 |
24 | if(!Mage::helper('segment_analytics')->isEnabled())
25 | {
26 | return;
27 | }
28 |
29 | $container = $layout->createBlock('core/text_list', self::CONTAINER_BLOCKNAME);
30 | $before_body_end->append($container);
31 | $front = Segment_Analytics_Model_Front_Controller::getInstance();
32 | $blocks = $front->getBlocks();
33 |
34 | foreach($blocks as $block)
35 | {
36 | if(!$block) { continue; }
37 | $items = $block = is_array($block) ? $block : array($block);
38 |
39 | foreach($items as $block)
40 | {
41 | $container->append($block);
42 | }
43 | }
44 | #Mage::Log("Finished addContainerBlocks");
45 | }
46 |
47 | /**
48 | * Adds the "always" items
49 | */
50 | public function addFrotnendScripts($observer)
51 | {
52 | $layout = $observer->getLayout();
53 | if(!$layout)
54 | {
55 | return;
56 | }
57 | if(!Mage::helper('segment_analytics')->isEnabled())
58 | {
59 | return;
60 | }
61 |
62 | $front = Segment_Analytics_Model_Front_Controller::getInstance();
63 | $front->addAction('init');
64 | $front->addDeferredAction('identity');
65 | $front->addAction('page');
66 | }
67 |
68 | public function loggedIn($observer)
69 | {
70 | $front = Segment_Analytics_Model_Front_Controller::getInstance();
71 | $front->addDeferredAction('alias');
72 | $front->addDeferredAction('identity');
73 | $front->addDeferredAction('customerloggedin');
74 | }
75 |
76 | public function loggedOut($observer)
77 | {
78 | $front = Segment_Analytics_Model_Front_Controller::getInstance();
79 | $front->addDeferredAction('customerloggedout', array(
80 | 'customer'=>$this->_getCustomerData()
81 | ));
82 | }
83 |
84 | public function addToCart($observer)
85 | {
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 |
93 | public function removeFromCart($observer)
94 | {
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 |
102 | public function customerRegistered($observer)
103 | {
104 | $customer = $observer->getCustomer();
105 | $front = Segment_Analytics_Model_Front_Controller::getInstance();
106 | $front->addDeferredAction('customerregistered',
107 | array('customer_id'=>$customer->getEntityId())
108 | );
109 | }
110 |
111 | public function loadedSearch($observer)
112 | {
113 | $o = $observer->getDataObject();
114 | if(!$o){return;}
115 | $front = Segment_Analytics_Model_Front_Controller::getInstance();
116 | $front->addDeferredAction('searchedproducts',
117 | array('query'=>$o->getQueryText())
118 | );
119 | }
120 |
121 | public function categoryViewForFiltering($observer)
122 | {
123 | $action = $observer->getAction();
124 | if(!$action){ return; }
125 |
126 | $request = $action->getRequest();
127 | if(!$request) { return; }
128 |
129 | $params = $request->getParams();
130 |
131 | //use presense of "dir" to flag for filtering.
132 | //no need for an action handle check
133 | if(!array_key_exists('dir', $params))
134 | {
135 | return;
136 | }
137 |
138 | $front = Segment_Analytics_Model_Front_Controller::getInstance();
139 | $front->addDeferredAction('filteredproducts',
140 | array('params'=>$params)
141 | );
142 |
143 | }
144 |
145 | public function productView($observer)
146 | {
147 | $action = $observer->getAction();
148 | if(!$action){ return; }
149 |
150 | $request = $action->getRequest();
151 | if(!$request) { return; }
152 |
153 | $params = $request->getParams();
154 |
155 | if (!in_array($action->getFullActionName(), array('catalog_product_view')))
156 | {
157 | return;
158 | }
159 |
160 | $front = Segment_Analytics_Model_Front_Controller::getInstance();
161 | $front->addDeferredAction('viewedproduct',
162 | array('params'=>$params)
163 | );
164 | }
165 |
166 | public function favSaved($observer)
167 | {
168 | $front = Segment_Analytics_Model_Front_Controller::getInstance();
169 | $item = $observer->getData('data_object');
170 |
171 | if($item->getResourceName() == 'amlist/item')
172 | {
173 | $front->addDeferredAction('amlistfav',
174 | array('product_id'=>$item->getData('product_id'))
175 | );
176 | }
177 | }
178 |
179 | public function reviewView($observer)
180 | {
181 | $action = $observer->getAction();
182 | if(!$action){ return; }
183 |
184 | $request = $action->getRequest();
185 | if(!$request) { return; }
186 |
187 | $params = $request->getParams();
188 |
189 | if (!in_array($action->getFullActionName(), array('review_product_list')))
190 | {
191 | return;
192 | }
193 |
194 | $front = Segment_Analytics_Model_Front_Controller::getInstance();
195 | $front->addDeferredAction('viewedreviews',
196 | array('params'=>$params)
197 | );
198 |
199 | }
200 |
201 | public function newsletterSubscriber($observer)
202 | {
203 | $subscriber = $observer->getDataObject();
204 | if(!$subscriber->getSubscriberStatus())
205 | {
206 | return;
207 | }
208 |
209 | $front = Segment_Analytics_Model_Front_Controller::getInstance();
210 | $front->addDeferredAction('subscribenewsletter',
211 | array('subscriber'=>$subscriber->getData())
212 | );
213 | }
214 |
215 | public function wishlistAddProduct($observer)
216 | {
217 | $product = $observer->getProduct();
218 | $wishlist = $observer->getWishlist();
219 |
220 | $front = Segment_Analytics_Model_Front_Controller::getInstance();
221 | $front->addDeferredAction('addedtowishlist',
222 | array('params'=>array('product_id'=>$product->getId()))
223 | );
224 |
225 | }
226 |
227 | public function viewedImageFrontendTrack($observer)
228 | {
229 | if(!Mage::helper('segment_analytics')->isEnabled())
230 | {
231 | return;
232 | }
233 |
234 | $action = $observer->getAction();
235 | if(!$action){ return; }
236 |
237 | $layout = Mage::getSingleton('core/layout');
238 |
239 | $content = $layout->getBlock('content');
240 | if(!$content) { return; }
241 |
242 | $content->append(
243 | $layout->createBlock('segment_analytics/template')
244 | ->setTemplate('segment_analytics/image-frontend.phtml')
245 | );
246 | }
247 |
248 | public function orderPlaced($observer)
249 | {
250 | $front = Segment_Analytics_Model_Front_Controller::getInstance();
251 | $front->addDeferredAction('orderplaced',
252 | array('params'=>array(
253 | 'order_id'=>$observer->getOrder()->getId(),
254 | 'increment_id'=>$observer->getOrder()->getIncrementId(),
255 | ))
256 | );
257 | }
258 |
259 | public function logBlockHtml($observer)
260 | {
261 | if($observer->getBlock()->getNameInLayout() != self::CONTAINER_BLOCKNAME)
262 | {
263 | return;
264 | }
265 |
266 | #Mage::Log($observer->getTransport()->getHtml(), Zend_Log::INFO, 'segment.log');
267 | }
268 |
269 | public function addClickedShareJavascript($observer)
270 | {
271 | $action = $observer->getAction();
272 | if(!$action){ return; }
273 |
274 | if($action->getFullActionName() != 'catalog_product_view')
275 | {
276 | return;
277 | }
278 |
279 | $layout = Mage::getSingleton('core/layout');
280 |
281 | $content = $layout->getBlock('content');
282 | if(!$content)
283 | {
284 | return;
285 | }
286 |
287 | $block = $layout->createBlock('segment_analytics/template')
288 | ->setTemplate('segment_analytics/share-frontend.phtml');
289 |
290 | $content->append($block);
291 | }
292 |
293 | public function addClickedReviewTabJavascript($observer)
294 | {
295 | $action = $observer->getAction();
296 | if(!$action){ return; }
297 |
298 | if($action->getFullActionName() != 'catalog_product_view')
299 | {
300 | return;
301 | }
302 |
303 | $layout = Mage::getSingleton('core/layout');
304 |
305 | $content = $layout->getBlock('content');
306 | if(!$content)
307 | {
308 | return;
309 | }
310 | $block = $layout->createBlock('segment_analytics/template')
311 | ->setTemplate('segment_analytics/review-frontend.phtml');
312 |
313 | $content->append($block);
314 | }
315 |
316 | protected function _getCustomer()
317 | {
318 | $customer = Mage::getSingleton('customer/session')->getCustomer();
319 |
320 | //pull entire customer, including eav attributes not initially populated
321 | $full_customer = Mage::getModel('customer/customer')->getCollection()
322 | ->addAttributeToSelect('*')->addFieldToFilter('entity_id', $customer->getId())
323 | ->getFirstItem();
324 |
325 | return $full_customer;
326 | }
327 |
328 | protected function _getCustomerData()
329 | {
330 | $customer = $this->_getCustomer();
331 | if($customer)
332 | {
333 | $customer = Mage::helper('segment_analytics')->getNormalizedCustomerInformation($customer->getData());
334 | return $customer;
335 | }
336 | return array();
337 | }
338 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Observer/Admin.php:
--------------------------------------------------------------------------------
1 | getAction();
7 | if(!$action)
8 | {
9 | return;
10 | }
11 |
12 | if($action->getRequest()->getParam('section') !== 'segment_analytics')
13 | {
14 | return;
15 | }
16 |
17 | $layout = Mage::getSingleton('core/layout');
18 | $content = $layout->getBlock('content');
19 |
20 | if(!$content)
21 | {
22 | return;
23 | }
24 |
25 | $json = new stdClass;
26 | $json->content = $layout->createBlock('adminhtml/template')
27 | ->setTemplate('segment_analytics/welcome.phtml')
28 | ->toHtml();
29 | }
30 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Observer/Layered.php:
--------------------------------------------------------------------------------
1 | getAction();
15 | if(!$action){ return; }
16 |
17 | if (!in_array($action->getFullActionName(), array('catalog_category_view')))
18 | {
19 | return;
20 | }
21 |
22 | $front = Segment_Analytics_Model_Front_Controller::getInstance();
23 | $front->addDeferredAction('layerednavfilter',
24 | array('params'=>array('request'=>Mage::app()->getRequest()->getParams()))
25 | );
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Observer/Review.php:
--------------------------------------------------------------------------------
1 | getObject();
8 | }
9 |
10 | public function reviewedProduct($observer)
11 | {
12 | $review = self::$_review;
13 | if(!$review->getId())
14 | {
15 | return;
16 | }
17 |
18 | $front = Segment_Analytics_Model_Front_Controller::getInstance();
19 | $front->addDeferredAction('reviewedproduct',
20 | array('review'=>$review->getData())
21 | );
22 | }
23 |
24 |
25 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Query/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/segment-boneyard/analytics-magento/HEAD/app/code/community/Segment/Analytics/Model/Query/.DS_Store
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Query/Totalpurchased.php:
--------------------------------------------------------------------------------
1 | getConnection('core_read');
8 | $sql = 'SELECT count(customer_id) as total FROM ' . $core_resource->getTableName('sales/order') . ' ' .
9 | 'WHERE customer_id = ?';
10 | $query = $read->query($sql,$customer_id);
11 |
12 | $result = $query->execute();
13 | $row = $query->fetch();
14 |
15 | return array_key_exists('total', $row) ? $row['total'] : 0;
16 | }
17 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Query/Totalspent.php:
--------------------------------------------------------------------------------
1 | getConnection('core_read');
8 | $sql = 'SELECT sum(grand_total) as total FROM ' . $core_resource->getTableName('sales/order') . ' ' .
9 | 'WHERE customer_id = ?';
10 | $query = $read->query($sql,$customer_id);
11 | $result = $query->execute();
12 | $row = $query->fetch();
13 |
14 | return array_key_exists('total', $row) ? $row['total'] : 0;
15 |
16 | }
17 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/Model/Resource/Setup.php:
--------------------------------------------------------------------------------
1 | init('segment_analytics');
11 | }
12 | }
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/controllers/IndexController.php:
--------------------------------------------------------------------------------
1 | loadLayout();
6 | $this->renderLayout();
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/app/code/community/Segment/Analytics/etc/adminhtml.xml:
--------------------------------------------------------------------------------
1 |
3 | Analytics for Magento is a Magento extension for Segment that lets you send data to any analytics tool you want without writing any code yourself! 4 |
-------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/addedtowishlist.phtml: -------------------------------------------------------------------------------- 1 | renderDataAsJsonVar("segment_analytics_addedtowishlist");?> 2 | 8 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/addtocart.phtml: -------------------------------------------------------------------------------- 1 | renderDataAsJsonVar('segment_analytics_addtocart'); ?> 2 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/alias.phtml: -------------------------------------------------------------------------------- 1 | renderDataAsJsonVar('segment_analytics_alias'); ?> 2 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/amlistfav.phtml: -------------------------------------------------------------------------------- 1 | renderDataAsJsonVar("segment_analytics_amlistfav");?> 2 | 7 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/customerloggedin.phtml: -------------------------------------------------------------------------------- 1 | renderDataAsJsonVar('segment_analytics_customerloggedin'); ?> 2 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/customerloggedout.phtml: -------------------------------------------------------------------------------- 1 | renderDataAsJsonVar('segment_analytics_customerloggedout'); 2 | $flush = Mage::helper('segment_analytics')->flushAfterLogout(); 3 | ?> 4 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/customerregistered.phtml: -------------------------------------------------------------------------------- 1 | renderDataAsJsonVar('segment_analytics_customerregistered'); ?> 2 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/filteredproducts.phtml: -------------------------------------------------------------------------------- 1 | renderDataAsJsonVar('segment_analytics_filtered'); ?> 2 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/identity.phtml: -------------------------------------------------------------------------------- 1 | renderDataAsJsonVar('segment_analytics_identity'); 3 | 4 | $json_to_send = Mage::helper('core')->jsonDecode($this->renderDataAsJsonObject()); 5 | unset($json_to_send['key']); 6 | unset($json_to_send['user_id']); 7 | 8 | if(array_key_exists('gender', $json_to_send) && $json_to_send['gender'] === false) 9 | { 10 | unset($json_to_send['gender']); 11 | } 12 | $json_to_send = Mage::helper('core')->jsonEncode($json_to_send); 13 | ?> 14 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/image-frontend.phtml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/init.phtml: -------------------------------------------------------------------------------- 1 | renderDataAsJsonVar('segment_analytics_init'); ?> 2 | 3 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/layerednavfilter.phtml: -------------------------------------------------------------------------------- 1 | renderDataAsJsonVar("segment_analytics_layerednavfilter");?> 2 | 7 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/orderplaced.phtml: -------------------------------------------------------------------------------- 1 | renderDataAsJsonVar("segment_analytics_orderplaced");?> 2 | 7 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/page.phtml: -------------------------------------------------------------------------------- 1 | renderDataAsJsonVar('segment_analytics_page');?> 2 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/removefromcart.phtml: -------------------------------------------------------------------------------- 1 | renderDataAsJsonVar('segment_analytics_removefromcart'); ?> 2 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/review-frontend.phtml: -------------------------------------------------------------------------------- 1 | setReviewLabel(Mage::helper('core')->__('Reviews')) 5 | ->renderDataAsJsonVar('segment_analytics_frontend_review'); 6 | ?> 7 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/reviewedproduct.phtml: -------------------------------------------------------------------------------- 1 | renderDataAsJsonVar("segment_analytics_reviewedproduct");?> 2 | 7 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/searchedproducts.phtml: -------------------------------------------------------------------------------- 1 | renderDataAsJsonVar('segment_analytics_searched'); ?> 2 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/share-frontend.phtml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/subscribenewsletter.phtml: -------------------------------------------------------------------------------- 1 | renderDataAsJsonVar("segment_analytics_subscribenewsletter");?> 2 | 7 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/viewedproduct.phtml: -------------------------------------------------------------------------------- 1 | renderDataAsJsonVar("segment_analytics_viewedproduct"); 4 | ?> 5 | 10 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/segment_analytics/viewedreviews.phtml: -------------------------------------------------------------------------------- 1 | renderDataAsJsonVar("segment_analytics_viewedreviews");?> 2 | 7 | -------------------------------------------------------------------------------- /app/etc/modules/Segment_Analytics.xml: -------------------------------------------------------------------------------- 1 | 2 |