2

I have been asked to add some javascript twitter tracking code on my site which should track when a new customer registers.

In my store there is no dedicated page for a successful signup for me to place this code, it just directs the customer to their acccount dashboard.

I have had a look at the event when a customer registers and it seems that it is called in:

Mage > Customer > controllers > AccountController.php

In line 526:

protected function _welcomeCustomer(Mage_Customer_Model_Customer $customer, $isJustConfirmed = false)
{

    $this->_getSession()->addSuccess(
        $this->__('Thank you for registering with %s.', Mage::app()->getStore()->getFrontendName())
    );

I thought by adding my javascript code onto the register success message like so it would add the tracking code onto the page:

protected function _welcomeCustomer(Mage_Customer_Model_Customer $customer, $isJustConfirmed = false)
{

    $tracking = '<div id="track"><script ....</script></div>';

    $this->_getSession()->addSuccess(
        $this->__('Thank you for registering with %s.', Mage::app()->getStore()->getFrontendName() . $tracking)
    );

But it doesn't seem to be tracking with this. Is this correct or is there another way of doing so?

odd_duck
  • 1,396
  • 4
  • 28
  • 47

1 Answers1

2

You can hook on customer_register_success event and set a session variable or a cookie indicating user has registered.

Example:

class Foo_Bar_Model_Observer
{
    public function customerRegisterSuccess($observer)
    {
        Mage::getSingleton('core/session')->setData('customer_register', true);
    }
}

If you need customer object you can access it by calling $observer->getEvent()->getCustomer();

On the next page load you can check if the session variable exists and print your javscript code if it does. Just remember to unset session data afterwards.

Lord Skeletor
  • 4,038
  • 1
  • 16
  • 19