I posted the code just before </body> in the header and it didn't work. I tried doing the same in the footer. Does anyone have suggestion as to why this isn't working and what I could do to get it to start working??
You shouldn't have a </body> in your header. Are you sure your page is put together properly? Also - how long are you waiting before you decide its not working.
If you reckon you've posted it correctly within the header then you've just prolly assumed that Google Analytics works instantaneously. Like what the guy above asked, how long have you waited before you assumed that the tracker wasn't working?
I have noticed that my Analytics updates every ~12hours. You should wait at least that amount of time. What status is the code showing. If it is receiving data you are fine, just have to wait for the 12hours to pass to start logging data.
As an alternative, check out getclicky.com. It updates in Real Time and is a lot easier on the eye than the google tool. I use it on various websites and could not be happier!
The format should be checked properly of the tag which you have inserted and also look for the spaces it may not accept it because of that too.
What has worked for me over the years is to have the code pasted at the bottom of the page, just before the </body> and </html> tags. This way your page would load faster, since the markup is interpreted from top to bottom.