Google Analytics is one of the most popular analytics engines for understanding what’s happening on a website. Magento Commerce includes Google Analytics code, so all you have to do is enable the functionality and enter your Google Analytics account ID.
Where to find your tracking code within Google Analytics
To access your tracking code from within your Google Analytics account:
- Log in to Google Analytics at http://www.google.com/analytics
- From the Overview page, select the account that has the profile for the tracking code you’re looking for, as the code is profile-specific.
- Select the profile from the accounts Overview page.
- From that profile’s Actions column, click Edit
- At the top right of the ‘Main Website Profile Information’ box, click Check Status
- Your tracking code can be copied and pasted from the text box in the Instructions for adding tracking section
The tracking/account ID has two parts:
- the X’s (UA-XXXXXXXX-YY) represent your account number
- the Y’s (UA-XXXXXXXXX-YY) represent profile numbers within your account.
The complete string (UA-XXXXX-YY) is referred to interchangeably as your web property ID or UA number
Where to add your Google Web Property ID or UA within Magento
- Login to your Magento Admin Area
- Navigate to System -> Configuration -> Google API
- Choose the ‘Configuration Scope’ from the drop down in the top left of the page. As with most options for Magento Commerce, value and settings can be set at the global level (Default Config), Website level, or the Store View level. Depending on how you want to track your Magento installation using Google Analytics depends on the scope you choose. If you have one Google Analytics profile with a single UA number, then choose the “Default Config” scope and your Google Analytics account will report against all Websites and Store Views as one. If you only have 1 website and 1 store view configured within Magento then choose this option. If you want to monitor each Magento Website individually you need to have multiple Google Analytics Profiles, one profile for each Magento Website. Each Profile creates a unique key so you can generate a Google API UA Number for each website you wish to monitor. If you want to go one step further and track each store view within Google Analytics you need to generate one Google Analytics Profile for each Magento Store View, then choose the appropriate ‘Store View’ from the drop-down within Magento.
- Expand the “Google Analytics” area and you’ll see a drop-down which allows you to enable or disable Google Analytics tracking. You’ll also see a text input area labeled “Account Number” which is where you need to insert your Google web property ID/UA number.
- Save the configuration and you’re done
Note to 184.108.40.206 users
If you are using Magento Commerce 220.127.116.11 you need to be aware that Google Analytics is broken in this version because of Bug ID 8658. You can read and track this bug here – http://www.magentocommerce.com/bug-tracking/issue?issue=8658
The issue is resolved in 18.104.22.168 and later and doesn’t affect 22.214.171.124 or earlier. The fix is very simple to implement. Edit app/code/core/Mage/GoogleAnalytics/Block/Ga.php and on line 179 add:
Alternatively download the fixed version from SVN http://svn.magentocommerce.com/source/branches/1.4-trunk/app/code/core/Mage/GoogleAnalytics/Block/Ga.php