Question

When a user comes to my website I want to figure out from where he/she came?

For example:

 1. Google or other search engines 

 2. Direct type  

 3. in  email promotions  

Any suggestions will be appreciated.

Was it helpful?

Solution

Use the referrer.

Mage::app()->getRequest()->getServer('HTTP_REFERER')

you can observe the general predispatch event to catch it. controller_action_predispatch.
If there is no referrer then it's direct access.
If the referrer matches google then it's from google (Duh!).

For e-mail promotions you can include in the urls a GET parameter for each email campain and match it in the same event.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top