Put Google Analytics code immediately before the closing </head> tag.

According to https://support.google.com/analytics/answer/1008080?hl=en-GB&utm_id=ad