Bye Bye Google Analytics
August 7th, 2015
A few days ago, I got rid of Google Analytics on all of my websites, and moved all my analytics needs to a self–hosted instance of Open Web Analytics.
The main reason for doing this is the privacy of the visitors of the websites — while some people are okay with (or do not care/know about) being tracked by Google wherever they go, some might not be, and it is not much effort to run your own analytics server.
OWA is a very well maintained product, and is basically equal to Google Analytics in terms of core functionality. (Page views, Acquisition, Events/Actions, etc.) Open Web Analytics has a full comparison which you can have a look at and see if it has all the functionality you need.
Here is how I did it:
-
Acquire a server running PHP & MySQL I chose DigitalOcean (referral link) for this, as they offer cheap options which are perfect for the small needs of an analytics server. I set up the 5$/month option, running Ubuntu 14.04 and the LAMP (Linux, Apache, MySQL, PHP) stack.
- Create the database and user for Open Web Analytics
Assuming you went with the LAMP stack and are now using MySQL, this is what you have to do to get your server ready for OWA. First, create a database to store your analytics data.
CREATE DATABASE analytics;
Then create the user OWA is going to use to access the data.
CREATE USER 'openwebanalytics'@'localhost' IDENTIFIED BY 'somepassword';
Now the user exists, but they do not have access to the database. Lets fix that:
GRANT ALL PRIVILEGES ON analytics.* TO 'openwebanalytics'@'localhost';
Now we just need to reload the permission for the new setup to come into effect.
FLUSH PRIVILEGES;
- Download Open Web Analytics
If you do not have it already, install
git
on your server by runningapt-get install git
Change into your web servers root folder, which is
/var/www/html
on my dropletcd /var/www/html
and download OWA into that folder with git.
git clone [email protected]:padams/Open-Web-Analytics
Make sure the www-data user (which OWA uses) has the right file permissions set up before continuing by running the following commands (replacing /var/www/html with your web servers root folder):
sudo chown -R www-data:www-data /var/www/html sudo chmod -R 755 /var/www/html
-
Install Open Web Analytics OWA thankfully comes with a very handy installer, so you just have to open
http://yourdomain.com/install.php
in your browser and follow the steps. When asked for the database credentials, the database name isanalytics
, the usernameopenwebanalytics
and the password whatever you set it to. - Track your website with Open Web Analytics
The only step remaining is dropping the tracking code into your HTML files:
<script type="text/javascript"> //<![CDATA[ var owa_baseUrl = 'http://your.domain.com/path/to/owa/'; var owa_cmds = owa_cmds || []; owa_cmds.push(['setSiteId', 'your_site_id']); owa_cmds.push(['trackPageView']); owa_cmds.push(['trackClicks']); owa_cmds.push(['trackDomStream']); (function() { var _owa = document.createElement('script'); _owa.type = 'text/javascript'; _owa.async = true; _owa.src = owa_baseUrl + 'modules/base/js/owa.tracker-combined-min.js'; var _owa_s = document.getElementsByTagName('script')[0]; _owa_s.parentNode.insertBefore(_owa, _owa_s); }()); //]]> </script>
Don’t forget to replace the
owa_baseUrl
with your domain and to set the correct site id!
Congratulations, you are now tracking your website with Open Web Analytics!
This post was originally published on N-O-D-E.net.
Liked this post? Sign up for the weekly newsletter!
Be the first to know when a new article is posted and get an inside scoop on the most interesting news and the freshest links of the week. (I hate spam just as much as you do, so no spam, ever. Promise.)
Tweet this article