nudgespot - Version 1.0.0

Version Notes

First stable version

Download this release

Release Info

Developer Nudgespot Technologies Inc
Extension nudgespot
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/Nudgespot/Connect/Helper/Data.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+ class Nudgespot_Connect_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ }
app/code/community/Nudgespot/Connect/Model/Observer.php ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Nudgespot_Connect_Model_Observer extends Mage_Core_Model_Abstract {
4
+
5
+ public $token;
6
+
7
+ public function __construct($token_string) {
8
+ $this->token = Mage::getStoreConfig('nudgespot/settings/nudgespot_api_token');
9
+ }
10
+
11
+ function host() {
12
+ $api_secret = Mage::getStoreConfig('nudgespot/settings/nudgespot_api_secret');
13
+ // return 'https://api:' . $api_secret . '@api.nudgespot.com';
14
+ return 'http://api:' . $api_secret . '@staging.nudgespot.com';
15
+ }
16
+
17
+ function getCategoryName($productId) {
18
+ $product = Mage::getModel('catalog/product')->load($productId);
19
+ $category_name = "";
20
+ $cats = $product->getCategoryIds();
21
+ $cnt = 0;
22
+ foreach ($cats as $category_id) {
23
+ $_cat = Mage::getModel('catalog/category')->load($category_id);
24
+ $cnt++;
25
+ if ($cnt == count($cats))
26
+ $category_name.=$_cat->getName();
27
+ else
28
+ $category_name.=$_cat->getName() . ",";
29
+ }
30
+ return $category_name;
31
+ }
32
+
33
+ function getItem($cart, &$item) {
34
+ $productId = $item->getProduct()->getId();
35
+ $name = addslashes($item->getProduct()->getName());
36
+ $category = addslashes($this->getCategoryName($productId));
37
+ $qty = $cart->getItemQty($item->getProduct()->getId());
38
+ $price = $item->getProduct()->getPrice();
39
+ return array('id' => $productId, 'name' => $name, 'category' => $category, 'price' => $price, 'quantity' => $qty);
40
+ }
41
+
42
+ public function trackAddToCart($observer) {
43
+ Mage::log('Nudgespot:: Add to cart');
44
+ $event = $observer->getEvent();
45
+ $cart = Mage::getModel('checkout/cart')->getQuote();
46
+ $items = $cart->getAllItems();
47
+ $cart = Mage::getSingleton('checkout/cart');
48
+ $cart_items = array();
49
+ foreach ($items as &$item) {
50
+ array_push($cart_items, $this->getItem($cart, $item));
51
+ }
52
+ $this->track('update_cart', array('items' => $cart_items,
53
+ 'cart_count' => $cart->getItemsCount(),
54
+ 'cart_total' => $cart->getQuote()->getGrandTotal()), null);
55
+ }
56
+
57
+ public function trackReview($observer) {
58
+ $event = $observer->getEvent();
59
+ $action = $event->getControllerAction();
60
+ $post_data = $action->getRequest()->getPost();
61
+ if (isset($post_data['detail'])) {
62
+ $this->track('review_product', array('nickname' => $post_data['nickname'],
63
+ 'title' => $post_data['title'],
64
+ 'distinct_id' => $this->getCustomerIdentity()), null);
65
+ }
66
+ }
67
+
68
+ public function getCustomerIdentity() {
69
+ if (Mage::getSingleton('customer/session')->isLoggedIn()) {
70
+ $c = Mage::getSingleton('customer/session')->getCustomer();
71
+ $customer = Mage::getModel('customer/customer')->load($c->getId());
72
+ $person = array();
73
+ $person = $this->getCustomerTrackInfo($customer);
74
+ return $customer->getEmail();
75
+ } else {
76
+ return null;
77
+ }
78
+ }
79
+
80
+ public function trackOrder($observer) {
81
+ $order = $observer->getEvent()->getOrder();
82
+ $quote = $order->getQuote();
83
+ $guest = $order->getCustomerIsGuest();
84
+ if ($guest == 1) {
85
+ $customer_email = $order->getCustomerEmail();
86
+ } else {
87
+ $customer_id = $order->getCustomerId();
88
+ $customer = Mage::getModel('customer/customer')->load($customer_id);
89
+ $customer_email = $customer->getEmail();
90
+ }
91
+ $customer_id = $order->getCustomerId();
92
+ $customer = Mage::getModel('customer/customer')->load($customer_id);
93
+ $customer_email = $customer->getEmail();
94
+ $items = $order->getItemsCollection();
95
+ $order_items = array();
96
+ Mage::log("Purchase event");
97
+ foreach ($order->getItemsCollection() as $item) {
98
+ $product_id = $item->getProductId();
99
+ $product = Mage::getModel('catalog/product')
100
+ ->setStoreId(Mage::app()->getStore()->getId())
101
+ ->load($product_id);
102
+ $productId = $item->getProduct()->getId();
103
+ $name = addslashes($item->getProduct()->getName());
104
+ $category = addslashes($this->getCategoryName($productId));
105
+ $price = $item->getProduct()->getPrice();
106
+ $order_items[] = array('id' => $productId, 'name' => $name, 'category' => $category, 'price' => $price);
107
+ }
108
+ $order_date = $quote->getUpdatedAt();
109
+ $order_date = str_replace(' ', 'T', $order_date);
110
+ $revenue = $quote->getBaseGrandTotal();
111
+ $this->track('purchase', array('items' => $order_items,
112
+ 'order_date' => $order_date,
113
+ 'order_total' => $revenue), $customer_email);
114
+ }
115
+
116
+ public function trackCustomerSave($observer) {
117
+ $customer = $observer->getCustomer();
118
+ if ($customer->isObjectNew() && !$customer->getCustomerAlreadyProcessed()) {
119
+ $customer->setCustomerAlreadyProcessed(true);
120
+ $person = array();
121
+ $person = $this->getCustomerTrackInfo($customer);
122
+ }
123
+ }
124
+
125
+ public function getCustomerTrackInfo($customer) {
126
+ $person = array();
127
+ $person['email'] = $customer->getEmail();
128
+ $person['first_name'] = $customer->getFirstname();
129
+ $person['last_name'] = $customer->getLastname();
130
+ $person['created'] = $customer->getCreatedAt();
131
+ $person['distinct_id'] = $customer->getEmail();
132
+ return $person;
133
+ }
134
+
135
+ public function trackCustomerFromCheckout($observer) {
136
+ $order = $observer->getEvent()->getOrder();
137
+ $quoteId = $order->getQuoteId();
138
+ $quote = Mage::getModel('sales/quote')->load($quoteId);
139
+ $method = $quote->getCheckoutMethod(true);
140
+ if ($method == 'register') {
141
+ $customer_id = $order->getCustomerId();
142
+ $customer = Mage::getModel('customer/customer')->load($customer_id);
143
+ $customer_email = $customer->getEmail();
144
+ $this->track('register', array(), $customer_email);
145
+ }
146
+ }
147
+
148
+ public function trackCustomerRegisterSuccess($observer) {
149
+ $customer = $observer->getCustomer();
150
+ $customer_email = $customer->getEmail();
151
+ $this->track('register', array(), $customer_email);
152
+ }
153
+
154
+ public function trackCoupon($observer) {
155
+ $action = $observer->getEvent()->getControllerAction();
156
+ $coupon_code = trim($action->getRequest()->getParam('coupon_code'));
157
+ if (isset($coupon_code) && !empty($coupon_code)) {
158
+ $this->track('use_coupon', array('code' => $coupon_code, 'distinct_id' => $this->getCustomerIdentity()), null);
159
+ }
160
+ return $this;
161
+ }
162
+
163
+ public function alias($identifier) {
164
+ $params['event'] = '$create_alias';
165
+ $visitorData = Mage::getSingleton('core/session')->getVisitorData();
166
+ $params['properties']['distinct_id'] = $visitorData['visitor_id'];
167
+ $params['properties']['$initial_referrer'] = '$direct';
168
+ $params['properties']['$initial_referring_domain'] = '$direct';
169
+ $params['properties']['alias'] = $identifier;
170
+ $params['properties']['token'] = $this->token;
171
+ $url = $this->host() . 'track/?data=';
172
+ $json = json_encode($params);
173
+ $this->apiCall($json);
174
+ // exec("curl '" . $url . "-X POST -H Content-Type: application/json -d '" . json_encode($params) . "' >/dev/null 2>&1 &");
175
+ }
176
+
177
+ public function track($event, $properties = array(), $customer = null) {
178
+ if (empty($customer)) {
179
+ $customer = $this->getCustomerIdentity();
180
+ if (empty($customer)) {
181
+ Mage::log("Event '" . $event . "' cannot be tracked, user info not available");
182
+ return;
183
+ }
184
+ }
185
+ Mage::log("Tracking '" . $event . "' by " . $customer);
186
+ $user = array();
187
+ $user['email'] = $customer;
188
+ $params = array(
189
+ 'event' => $event,
190
+ 'properties' => $properties,
191
+ 'user' => $user
192
+ );
193
+
194
+ $params['properties']['token'] = $this->token;
195
+ $url = $this->host() . '/activities';
196
+ Mage::log("curl '" . $url . "' -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -d '" . json_encode(array('activity' => $params)) . "' >/dev/null 2>&1 &");
197
+ // exec("curl '" . $url . "' -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -d '" . json_encode(array('activity' => $params)) . "' >/dev/null 2>&1 &");
198
+ $json = json_encode(array('activity' => $params));
199
+ $this->apiCall($json);
200
+ }
201
+
202
+ public function apiCall($json) {
203
+ $url = $this->host() . '/activities';
204
+ $header[] = "Content-Type: application/json";
205
+ $header[] = "Accept: application/json";
206
+ $header[] = "Content-Length: " . strlen($json);
207
+ $ch = curl_init();
208
+ curl_setopt($ch, CURLOPT_URL, $url);
209
+ curl_setopt($ch, CURLOPT_POST, 1);
210
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
211
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
212
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
213
+ curl_exec($ch);
214
+ curl_close($ch);
215
+ }
216
+ }
app/code/community/Nudgespot/Connect/etc/config.xml ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <config>
3
+ <modules>
4
+ <Nudgespot_Connect>
5
+ <version>1.0.0</version>
6
+ </Nudgespot_Connect>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <nudgespot>
11
+ <class>Nudgespot_Connect_Model</class>
12
+ </nudgespot>
13
+ </models>
14
+ <helpers>
15
+ <nudgespot>
16
+ <class>Nudgespot_Connect_Helper</class>
17
+ </nudgespot>
18
+ </helpers>
19
+ </global>
20
+ <frontend>
21
+ <layout>
22
+ <updates>
23
+ <nudgespot module="nudgespot">
24
+ <file>nudgespot.xml</file>
25
+ </nudgespot>
26
+ </updates>
27
+ </layout>
28
+ <events>
29
+ <sales_order_place_after>
30
+ <observers>
31
+ <nudgespot_order_save>
32
+ <type>singleton</type>
33
+ <class>Nudgespot_Connect_Model_Observer</class>
34
+ <method>trackOrder</method>
35
+ </nudgespot_order_save>
36
+ </observers>
37
+ </sales_order_place_after>
38
+ <sales_order_place_before>
39
+ <observers>
40
+ <nudgespot_customer_register_from_checkout>
41
+ <type>singleton</type>
42
+ <class>Nudgespot_Connect_Model_Observer</class>
43
+ <method>trackCustomerFromCheckout</method>
44
+ </nudgespot_customer_register_from_checkout>
45
+ </observers>
46
+ </sales_order_place_before>
47
+ <customer_register_success>
48
+ <observers>
49
+ <nudgespot_customer_register_success>
50
+ <type>model</type>
51
+ <class>Nudgespot_Connect_Model_Observer</class>
52
+ <method>trackCustomerRegisterSuccess</method>
53
+ </nudgespot_customer_register_success>
54
+ </observers>
55
+ </customer_register_success>
56
+ <checkout_cart_add_product_complete>
57
+ <observers>
58
+ <nudgespot_add_to_cart>
59
+ <type>singleton</type>
60
+ <class>Nudgespot_Connect_Model_Observer</class>
61
+ <method>trackAddToCart</method>
62
+ </nudgespot_add_to_cart>
63
+ </observers>
64
+ </checkout_cart_add_product_complete>
65
+ <checkout_cart_update_items_after>
66
+ <observers>
67
+ <nudgespot_add_to_cart>
68
+ <type>singleton</type>
69
+ <class>Nudgespot_Connect_Model_Observer</class>
70
+ <method>trackAddToCart</method>
71
+ </nudgespot_add_to_cart>
72
+ </observers>
73
+ </checkout_cart_update_items_after>
74
+ <controller_action_predispatch_checkout_cart_couponPost>
75
+ <observers>
76
+ <nudgespot_add_coupon_from_cart>
77
+ <type>singleton</type>
78
+ <class>Nudgespot_Connect_Model_Observer</class>
79
+ <method>trackCoupon</method>
80
+ </nudgespot_add_coupon_from_cart>
81
+ </observers>
82
+ </controller_action_predispatch_checkout_cart_couponPost>
83
+ <controller_action_predispatch_onestepcheckout_index_add_coupon>
84
+ <observers>
85
+ <nudgespot_add_coupon>
86
+ <type>singleton</type>
87
+ <class>Nudgespot_Connect_Model_Observer</class>
88
+ <method>trackCoupon</method>
89
+ </nudgespot_add_coupon>
90
+ </observers>
91
+ </controller_action_predispatch_onestepcheckout_index_add_coupon>
92
+
93
+ </events>
94
+ </frontend>
95
+ <adminhtml>
96
+ <acl>
97
+ <resources>
98
+ <admin>
99
+ <children>
100
+ <system>
101
+ <children>
102
+ <config>
103
+ <children>
104
+ <nudgespot>
105
+ <title>Nudgespot Settings</title>
106
+ </nudgespot>
107
+ </children>
108
+ </config>
109
+ </children>
110
+ </system>
111
+ </children>
112
+ </admin>
113
+ </resources>
114
+ </acl>
115
+ </adminhtml>
116
+ </config>
app/code/community/Nudgespot/Connect/etc/system.xml ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <nudgespot translate="label" module="nudgespot">
5
+ <label>Nudgespot</label>
6
+ <tab>advanced</tab>
7
+ <frontend_type>text</frontend_type>
8
+ <sort_order>990</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+ <groups>
13
+ <settings translate="label">
14
+ <label>Nudgespot Settings</label>
15
+ <frontend_type>text</frontend_type>
16
+ <sort_order>1</sort_order>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <show_in_store>1</show_in_store>
20
+ <fields>
21
+ <nudgespot_api_token translate="label,comment">
22
+ <label>API Token</label>
23
+ <comment><![CDATA[You can find this in your Nudgespot account's <a href="https://app.nudgespot.com/settings">settings page</a>.]]></comment>
24
+ <frontend_type>text</frontend_type>
25
+ <sort_order>1</sort_order>
26
+ <show_in_default>1</show_in_default>
27
+ <show_in_website>1</show_in_website>
28
+ <show_in_store>1</show_in_store>
29
+ </nudgespot_api_token>
30
+
31
+ <nudgespot_api_secret translate="label,comment">
32
+ <label>API Secret</label>
33
+ <comment><![CDATA[You can find this in your Nudgespot account's <a href="https://app.nudgespot.com/settings">settings page</a>.]]></comment>
34
+ <frontend_type>text</frontend_type>
35
+ <sort_order>2</sort_order>
36
+ <show_in_default>1</show_in_default>
37
+ <show_in_website>1</show_in_website>
38
+ <show_in_store>1</show_in_store>
39
+ </nudgespot_api_secret>
40
+ </fields>
41
+ </settings>
42
+ </groups>
43
+ </nudgespot>
44
+ </sections>
45
+ </config>
package.xml ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>nudgespot</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/mit-license.php">Massachusetts Institute of Technology License (MITL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Nudgespot lets you communicate with your customers (via email/sms), based on their interactions on your store.</summary>
10
+ <description>This extension connects Magento to Nudgespot. Nudgespot simplifies all your interactions with your customers. &#xD;
11
+ &#xD;
12
+ Using Nudgespot, you can:&#xD;
13
+ &#xD;
14
+ 1. Send newsletter style messages via email, SMS or push notifications.&#xD;
15
+ 2. Send messages based on what your customers do (or don't) on your store. Examples: cart abandonment emails, birthday greeting/offers, etc&#xD;
16
+ 3. Look up customers by their interactions, and send targeted messages to them. Example: Notify accessories available to customers that bought certain camera.&#xD;
17
+ &#xD;
18
+ How it works:&#xD;
19
+ &#xD;
20
+ This extension tracks activities of your customers on your store. You can then go to your Nudgespot dashboard and:&#xD;
21
+ &#xD;
22
+ 1. Trigger messages based on rules.&#xD;
23
+ 2. Send a broadcast style message to all or certain groups of customers.&#xD;
24
+ 3. Look up customers based on any attributes, or even based on their interactions.&#xD;
25
+ 4. Add customers to lists, and let Nudgespot automatically add/remove them from them, based on rules you specify.&#xD;
26
+ &#xD;
27
+ The extension currently tracks the following activities:&#xD;
28
+ * Cart updates&#xD;
29
+ * Purchase&#xD;
30
+ * Register&#xD;
31
+ * Reviews&#xD;
32
+ * Search&#xD;
33
+ </description>
34
+ <notes>First stable version</notes>
35
+ <authors><author><name>Nudgespot Technologies Inc</name><user>nudgespot</user><email>magento@nudgespot.com</email></author></authors>
36
+ <date>2015-07-07</date>
37
+ <time>21:53:30</time>
38
+ <contents><target name="magecommunity"><dir name="Nudgespot"><dir name="Connect"><dir name="Helper"><file name="Data.php" hash="3315efa1c0610633ef05df9c74f23b72"/></dir><dir name="Model"><file name="Observer.php" hash="75dd1bb6ffb0bcf093041bf0758b2650"/></dir><dir name="etc"><file name="config.xml" hash="3eaca0c05e316dba9c6c1e73c34afd7b"/><file name="system.xml" hash="e64c57cc37fcd0425188291760cd43e2"/></dir></dir></dir></target></contents>
39
+ <compatible/>
40
+ <dependencies><required><php><min>5.5.0</min><max>5.6.0</max></php></required></dependencies>
41
+ </package>