Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions app/code/community/Fooman/GoogleAnalyticsPlus/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
31 changes: 31 additions & 0 deletions app/code/community/Fooman/GoogleAnalyticsPlus/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
}
}
24 changes: 24 additions & 0 deletions app/code/community/Fooman/GoogleAnalyticsPlus/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@
</googleanalyticsplus_success_set_order>
</observers>
</checkout_multishipping_controller_success_action>
<controller_action_predispatch_checkout_cart_add>
<observers>
<googleanalyticsplus_checkout_cart_add>
<class>googleanalyticsplus/observer</class>
<method>checkoutCartAdd</method>
</googleanalyticsplus_checkout_cart_add>
</observers>
</controller_action_predispatch_checkout_cart_add>
<customer_login>
<observers>
<googleanalyticsplus_checkout_cart_add>
<class>googleanalyticsplus/observer</class>
<method>customerLogin</method>
</googleanalyticsplus_checkout_cart_add>
</observers>
</customer_login>
<customer_register_success>
<observers>
<googleanalyticsplus_checkout_cart_add>
<class>googleanalyticsplus/observer</class>
<method>customerRegistration</method>
</googleanalyticsplus_checkout_cart_add>
</observers>
</customer_register_success>
</events>
</frontend>
<default>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@
<?php if ($altUniversal):?>
ga('<?php echo Fooman_GoogleAnalyticsPlus_Block_Universal::TRACKER_TWO_NAME?>.send', 'pageview', '<?php echo $this->getPageName(); ?>');
<?php endif;?>

<?php $_productIdAddedToCart = Mage::helper('googleanalyticsplus')->pullProductIdAddedToCart();?>
<?php if($_productIdAddedToCart): ?>
ga('send', 'event', 'catalog', 'add-to-cart', '<?php echo $_productIdAddedToCart; ?>', '0');
<?php endif; ?>

<?php $_customerIdLoggedIn = Mage::helper('googleanalyticsplus')->pullCustomerIdLoggedIn();?>
<?php if($_customerIdLoggedIn): ?>
ga('send', 'event', 'customer', 'login', '<?php echo $_customerIdLoggedIn; ?>', '0');
<?php endif; ?>

<?php $_customerIdRegistered = Mage::helper('googleanalyticsplus')->pullCustomerIdRegistered();?>
<?php if($_customerIdRegistered): ?>
ga('send', 'event', 'customer', 'registration', '<?php echo $_customerIdRegistered; ?>', '0');
<?php endif; ?>
</script>

<?php if($this->isSuccessPage() && $this->sendEcommerceTracking()):?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
ga('<?php echo Fooman_GoogleAnalyticsPlus_Block_Universal::TRACKER_TWO_NAME?>.require', 'linkid');
<?php endif;?>
<?php endif;?>

</script>
<!-- End Google Analytics Part 1/2 -->
<?php endif; ?>