From 91cf0a6fbaf49bf0a1f845c15432f7196c20377b Mon Sep 17 00:00:00 2001 From: Lucho Date: Thu, 11 May 2017 11:26:33 -0300 Subject: [PATCH 1/2] added add to cart, customer login and customer registration events --- .../GoogleAnalyticsPlus/Helper/Data.php | 50 +++++++++++++++++++ .../GoogleAnalyticsPlus/Model/Observer.php | 31 ++++++++++++ .../Fooman/GoogleAnalyticsPlus/etc/config.xml | 24 +++++++++ .../googleanalyticsplus/universal.phtml | 14 ++++++ 4 files changed, 119 insertions(+) diff --git a/app/code/community/Fooman/GoogleAnalyticsPlus/Helper/Data.php b/app/code/community/Fooman/GoogleAnalyticsPlus/Helper/Data.php index e7b9a50..347ec2a 100644 --- a/app/code/community/Fooman/GoogleAnalyticsPlus/Helper/Data.php +++ b/app/code/community/Fooman/GoogleAnalyticsPlus/Helper/Data.php @@ -79,4 +79,54 @@ public function getTrackingCurrency($object) } } + /** + * The product ID was last added to the cart + * + * @return int + */ + public function pullProductIdAddedToCart() + { + $productId = Mage::getModel('core/session')->getProductIdAddedToCart(); + + if ($productId) { + Mage::getModel('core/session')->unsProductIdAddedToCart(); + return $productId; + } else { + return null; + } + } + + /** + * The customer ID just logged in + * + * @return int + */ + public function pullCustomerIdLoggedIn() + { + $customerId = Mage::getModel('core/session')->getCustomerIdLoggedIn(); + + if ($customerId) { + Mage::getModel('core/session')->unsCustomerIdLoggedIn(); + return $customerId; + } else { + return null; + } + } + + /** + * The customer ID just registered + * + * @return int + */ + public function pullCustomerIdRegistered() + { + $customerId = Mage::getModel('core/session')->getCustomerIdRegistered(); + + if ($customerId) { + Mage::getModel('core/session')->unsCustomerIdRegistered(); + return $customerId; + } else { + return null; + } + } } diff --git a/app/code/community/Fooman/GoogleAnalyticsPlus/Model/Observer.php b/app/code/community/Fooman/GoogleAnalyticsPlus/Model/Observer.php index 240e7a8..ac6f4a2 100644 --- a/app/code/community/Fooman/GoogleAnalyticsPlus/Model/Observer.php +++ b/app/code/community/Fooman/GoogleAnalyticsPlus/Model/Observer.php @@ -20,4 +20,35 @@ public function setOrder($observer) { Mage::register('googleanalyticsplus_order_ids', $observer->getEvent()->getOrderIds(), true); } + + public function checkoutCartAdd($observer) + { + $product = Mage::getModel('catalog/product') + ->load(Mage::app()->getRequest()->getParam('product', 0)); + + if (!$product->getId()) + { + return false; + } + + Mage::getModel('core/session')->setProductIdAddedToCart( $product->getId() ); + } + + public function customerLogin($observer) + { + $customer = $observer->getCustomer(); + + if ($customer) { + Mage::getModel('core/session')->setCustomerIdLoggedIn( $customer->getId() ); + } + } + + public function customerRegistration($observer) + { + $customer = $observer->getCustomer(); + + if ($customer) { + Mage::getModel('core/session')->setCustomerIdRegistered( $customer->getId() ); + } + } } diff --git a/app/code/community/Fooman/GoogleAnalyticsPlus/etc/config.xml b/app/code/community/Fooman/GoogleAnalyticsPlus/etc/config.xml index 63be3c3..9d90a25 100644 --- a/app/code/community/Fooman/GoogleAnalyticsPlus/etc/config.xml +++ b/app/code/community/Fooman/GoogleAnalyticsPlus/etc/config.xml @@ -63,6 +63,30 @@ + + + + googleanalyticsplus/observer + checkoutCartAdd + + + + + + + googleanalyticsplus/observer + customerLogin + + + + + + + googleanalyticsplus/observer + customerRegistration + + + diff --git a/app/design/frontend/base/default/template/fooman/googleanalyticsplus/universal.phtml b/app/design/frontend/base/default/template/fooman/googleanalyticsplus/universal.phtml index e9c238f..7e45ed0 100644 --- a/app/design/frontend/base/default/template/fooman/googleanalyticsplus/universal.phtml +++ b/app/design/frontend/base/default/template/fooman/googleanalyticsplus/universal.phtml @@ -38,6 +38,20 @@ + pullProductIdAddedToCart();?> + + ga('send', 'event', 'catalog', 'add-to-cart', '', '0'); + + + pullCustomerIdLoggedIn();?> + + ga('send', 'event', 'customer', 'login', '', '0'); + + + pullCustomerIdRegistered();?> + + ga('send', 'event', 'customer', 'registration', '', '0'); + From 714e5198a0800ef8c803d351413a65301db89f66 Mon Sep 17 00:00:00 2001 From: Lucho Date: Thu, 11 May 2017 11:32:59 -0300 Subject: [PATCH 2/2] moved new events js to correct partial view --- .../googleanalyticsplus/universal-send.phtml | 15 +++++++++++++++ .../fooman/googleanalyticsplus/universal.phtml | 15 --------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/design/frontend/base/default/template/fooman/googleanalyticsplus/universal-send.phtml b/app/design/frontend/base/default/template/fooman/googleanalyticsplus/universal-send.phtml index 92b25e5..8ca7ba9 100644 --- a/app/design/frontend/base/default/template/fooman/googleanalyticsplus/universal-send.phtml +++ b/app/design/frontend/base/default/template/fooman/googleanalyticsplus/universal-send.phtml @@ -7,6 +7,21 @@ ga('.send', 'pageview', 'getPageName(); ?>'); + + pullProductIdAddedToCart();?> + + ga('send', 'event', 'catalog', 'add-to-cart', '', '0'); + + + pullCustomerIdLoggedIn();?> + + ga('send', 'event', 'customer', 'login', '', '0'); + + + pullCustomerIdRegistered();?> + + ga('send', 'event', 'customer', 'registration', '', '0'); + isSuccessPage() && $this->sendEcommerceTracking()):?> diff --git a/app/design/frontend/base/default/template/fooman/googleanalyticsplus/universal.phtml b/app/design/frontend/base/default/template/fooman/googleanalyticsplus/universal.phtml index 7e45ed0..e96bda5 100644 --- a/app/design/frontend/base/default/template/fooman/googleanalyticsplus/universal.phtml +++ b/app/design/frontend/base/default/template/fooman/googleanalyticsplus/universal.phtml @@ -37,21 +37,6 @@ ga('.require', 'linkid'); - - pullProductIdAddedToCart();?> - - ga('send', 'event', 'catalog', 'add-to-cart', '', '0'); - - - pullCustomerIdLoggedIn();?> - - ga('send', 'event', 'customer', 'login', '', '0'); - - - pullCustomerIdRegistered();?> - - ga('send', 'event', 'customer', 'registration', '', '0'); -