{"action":"opened","issue":{"url":"https://api.github.com/repos/wvuweb/cleanslate-cms/issues/164","labels_url":"https://api.github.com/repos/wvuweb/cleanslate-cms/issues/164/labels{/name}","comments_url":"https://api.github.com/repos/wvuweb/cleanslate-cms/issues/164/comments","events_url":"https://api.github.com/repos/wvuweb/cleanslate-cms/issues/164/events","html_url":"https://github.com/wvuweb/cleanslate-cms/issues/164","id":85190585,"number":164,"title":"Google Analytics Code in <head> of HTML","user":{"login":"dustinmazon","id":1126703,"avatar_url":"https://avatars.githubusercontent.com/u/1126703?v=3","gravatar_id":"","url":"https://api.github.com/users/dustinmazon","html_url":"https://github.com/dustinmazon","followers_url":"https://api.github.com/users/dustinmazon/followers","following_url":"https://api.github.com/users/dustinmazon/following{/other_user}","gists_url":"https://api.github.com/users/dustinmazon/gists{/gist_id}","starred_url":"https://api.github.com/users/dustinmazon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dustinmazon/subscriptions","organizations_url":"https://api.github.com/users/dustinmazon/orgs","repos_url":"https://api.github.com/users/dustinmazon/repos","events_url":"https://api.github.com/users/dustinmazon/events{/privacy}","received_events_url":"https://api.github.com/users/dustinmazon/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/wvuweb/cleanslate-cms/labels/discussion","name":"discussion","color":"006b75"}],"state":"open","locked":false,"assignee":{"login":"adamjohnson","id":575865,"avatar_url":"https://avatars.githubusercontent.com/u/575865?v=3","gravatar_id":"","url":"https://api.github.com/users/adamjohnson","html_url":"https://github.com/adamjohnson","followers_url":"https://api.github.com/users/adamjohnson/followers","following_url":"https://api.github.com/users/adamjohnson/following{/other_user}","gists_url":"https://api.github.com/users/adamjohnson/gists{/gist_id}","starred_url":"https://api.github.com/users/adamjohnson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamjohnson/subscriptions","organizations_url":"https://api.github.com/users/adamjohnson/orgs","repos_url":"https://api.github.com/users/adamjohnson/repos","events_url":"https://api.github.com/users/adamjohnson/events{/privacy}","received_events_url":"https://api.github.com/users/adamjohnson/received_events","type":"User","site_admin":false},"milestone":null,"comments":0,"created_at":"2015-06-04T17:11:48Z","updated_at":"2015-06-04T17:11:48Z","closed_at":null,"body":"# The Question\r\n\r\nShould we continue to load the GA script just before the `</body>` or should we place it in the `<head>` of the document?\r\n\r\n# The Research\r\n\r\nI would like to present the facts and rationalization as to why we should place the script in the `<head>` vs just before the `</body>`.\r\n\r\n## Google Analytics Documentation\r\n\r\n- https://support.google.com/analytics/answer/1008080?hl=en#GA\r\n\r\n![screen shot 2015-06-04 at 11 47 29 am](https://cloud.githubusercontent.com/assets/1126703/7988081/8e4961ee-0aaf-11e5-83f7-6deec83a7b2f.png)\r\n\r\n- https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced\r\n\r\n![screen shot 2015-06-04 at 12 07 45 pm](https://cloud.githubusercontent.com/assets/1126703/7988628/5979a5ca-0ab2-11e5-8264-9c89785a086f.png)\r\n\r\n>SUMMARY: We are using the new Universal Analytics code which is loaded asynchronously. Google recommends loading the tracking code in the `<head>` of the document.\r\n\r\n***\r\n\r\n## Other Articles Supporting `<head>` Insertion\r\n\r\n- http://stackoverflow.com/questions/26755664/where-to-put-your-google-analytics-code\r\n\r\n![screen shot 2015-06-04 at 12 42 21 pm](https://cloud.githubusercontent.com/assets/1126703/7989407/4cbee78c-0ab7-11e5-9523-aacb6351f5a1.png)\r\n\r\n- http://www.lunametrics.com/blog/2012/02/09/where-put-google-tracking-code/\r\n\r\n![screen shot 2015-06-04 at 12 51 12 pm](https://cloud.githubusercontent.com/assets/1126703/7989628/d4b3c26a-0ab8-11e5-8db2-51ffd7a11849.png)\r\n\r\n![screen shot 2015-06-04 at 12 53 59 pm](https://cloud.githubusercontent.com/assets/1126703/7989630/d6c5d4da-0ab8-11e5-84fe-80c1d8aa041a.png)\r\n\r\n>SUMMARY: We are not using custom variables and will be using event tracking so we should probably move the GA code to the `<head>` of the document to allow for more accurate metrics.\r\n\r\n## Ease of Webmaster Tools Setup\r\n\r\n- https://support.google.com/webmasters/answer/185871?hl=en&ref_topic=4564314\r\n\r\nTo make setting up sites with Webmaster Tools more time efficient, we should place the async GA code in the `<head>`.\r\n\r\n## Testing Page Speed Test\r\n\r\n- https://developers.google.com/speed/pagespeed/insights/?url=tour.wvu.edu&tab=mobile\r\n\r\nWhen I run the page speed test nothing comes up about the GA code slowing down the performance. I think the async GA code isn't really a major problem.\r\n\r\n# Conclusion\r\n\r\nThere are 4 points I would like to highlight for my suggestion of moving the GA code to the `<head>`:\r\n\r\n1. Placing the GA code in the `<body>` or footer is an antiquated technique. The new Universal GA code loads async which doesn't prevent the page from loading the `<body>` or page content so there is no reason to load it at the bottom of the page.\r\n1. It will be easier to set up Webmaster Tools.\r\n1. Our GA data will be more accurate for those individuals with slower connections. \r\n1. Google knows what they are doing when it comes to performance, so why not listen to them and their documentation?"}}