When you're first setting up Google Analytics for your website, you'll want to do some testing in your local or test environment. The good news is: testing of the transmission is fast. The bad news is: testing the processing is not. This post describes the process.
Here's what you need:
- A google analytics account. It's free, no big deal.
- A profile. The default one will do fine. In profile creation, when it asks for your Website's URL, go ahead and enter the real, production domain name. It doesn't matter.
var _gaq = _gaq || ;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/u/ga_debug.js';
var s = document.getElementsByTagName('script'); s.parentNode.insertBefore(ga, s);
UA-000000000-0 is your Google Analytics account identifier. When you copy and paste the code from Google that'll be populated with real numbers, just for you.
_gaq.push(['_setDomainName', 'none']); is the magic make-it-work flag for local testing. This says, ignore the domain name in the URL and just post the data.
u/ga_debug.js is where the real work happens; in real life (production) this will say ga.js. For testing, use the debug version of the script. Notice the extra /u in front of the script name; the debug script is in a slightly different spot.
The debug script will print useful information to the console every time information is transmitted to Google. Look for this in the debug console (command-alt-I in Chrome or Safari on a Mac):
- Check Google Analytics Real-Time to see whether your visit has been recognized. (Click on Home in the orange header, then Real-Time on the left, then Overview.) This tells you that Google Analytics is receiving data.
- Now comes the hard part: waiting. Seriously, you have to wait a whole day to see the page views you generated. Then you can play around with the reporting, filtering, site search config, etc etc. While the data transmitted is received and recorded immediately, it is not processed for three hours or so, and more processing occurs overnight.
Keep in mind that when you change Google Analytics configuration (like site search query parameters), that affects only records that have not been processed. Once data is processed and stored, it doesn't get re-processed with updated rules. Testing configuration means make a change; generate the relevant traffic; come back tomorrow.