Analytics

In earlier chapters, we built the tutorial application and deployed it
for hosting on Heroku.

We’ve left something out. Though not obvious, it’s very important:
analytics.

Analytics services provide reports about website traffic and usage.

You’ll use the data to increase visits and improve your site. Analytics
close the communication loop with your users; your website puts out a
message and analytics reports show how visitors respond.

Google Analytics is the best known tracking service. It is free, easy to
use, and familiar to most web developers. In this chapter we’ll
integrate Google Analytics with the tutorial application.

There are several ways to install Google Analytics for Rails. The
article on Analytics for Rails looks at various approaches and explains
how Google Analytics works.

For this tutorial, we’ll use the Segment.io service. The service
provides an API to send analytics data to dozens of different services,
including Google Analytics.
Deploy

When you are ready to deploy to Heroku, you must recompile assets and
commit to the Git repo:

$ git add -A
$ git commit -m "analytics"
$ rake assets:precompile
$ git add -A
$ git commit -m "assets compiled for Heroku"
$ git push

Then you can deploy to Heroku:

$ git push heroku master

When you visit the site, you should see real-time tracking of data sent
to Segment.io in the Segment.io dashboard.

Log into your Google Analytics account to see real-time tracking of
visits to your website. Under “Standard Reports” see “Real-Time
Overview.” You’ll see data within seconds after visiting any page.