Overview
Google Analytics is a free web analytics application provided by Google, including SEO recommendations and live site traffic.
Setting up GA
Google Analytics can be enabled on newer, v5+ platforms using two lines in a .htaccess file.
- Visit Google Analytics to create a profile for the domain
- Once the profile is created, you will see sample code to insert:
<script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-99999000-1', 'auto'); ga('send', 'pageview'); </script>
- Write down your account number, bolded above, which follows the form UA-XXXXXXXX-X
- It is unnecessary to add the sample code above. This will be added automatically via mod_pagespeed in the following step
- Once the profile is created, you will see sample code to insert:
- Create a file, if it does not exist, named
.htaccess
in the document root for the domain to enable statistics reporting - Add the following lines:
ModPagespeedEnableFilters insert_ga
ModPagespeedAnalyticsID UA-XXXXXXXX-X
- Where UA-XXXXXXX-X is the account number previously generated by Google
- Voila! Wait 24 hours for statistics to generate within Google Analytics’ dashboard