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-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 e9c238f..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,7 +37,6 @@ ga('.require', 'linkid'); -