I've been interested for some time in the idea of tracking my life with Google Analytics.
Let me take a step back for a moment. I'm in no way wanting to track myself to the depth and intricacy that Stephen Wolfram does. And while I like the idea of something like Exist, which pulls all sorts of everything together into one place, it seems a bit mechanical and invasive.
It all started out as a vague desire to want to track the music I was listening to, but recently it all got catalysed with the Fitbit I got for Christmas. This gave me the kick up the backside that I needed to put some time in to get everything together, and it turned out that it was a pretty simple method.
So here goes.
This post will show you how to set up your Fitbit to track in Google Analytics, as well as your music listening history via Last.fm. Finally, as a bonus, there's a web app that you can use to send data about your drinking habits to Google Analytics. Yes, drinking habits.
Let's get started.
Stuff You'll Need
- A Fitbit, together with a login and password so you can access your account on a desktop computer
- A Last.fm account UPDATE: As of 25 March, Last.fm no longer connects to IFTTT. So tracking your music plays isn't possible. I'll keep an ear out for a workaround and will update here if anything materialises :(
- A new Google Analytics Property ID
You'll also need to get a Client ID to send hits to Google Analytics via the Measurement Protocol.
This is dead easy, much simpler than it sounds. Head over to https://ga-dev-tools.appspot.com/hit-builder/, log in and authenticate if it asks you to, and click the Refresh icon next to the cid field:

This will generate a long string, something like e52356a6-cf56-4156-aaa1-564c2656e699. Hang onto this, as we'll need it when we send the hits to Google Analytics.
Welcome To IFTTT
IFTTT stands for If This, Then That. It's a web automation service that has been around for a few years now, and by authenticating it with various services, you can automate a lot of cool stuff.
For example, you can set IFTTT to send you an email every time someone tags you in a photo on Facebook. Or you can send links to a Google Doc every time you star them in Pocket.
You can even hook it up with your phone, so that each time your device exits or leaves a certain location, you can send a timestamped entry to Google Drive spreadsheet. Useful for tracking how much time you spend at the office. These hookups are called Recipes in IFTTT-land.
Anyway, we're interested in Fitbit stuff. Luckily, IFTTT supports a bunch of Fitbit features, and getting setup is pretty straightforward. So let's go ahead and make our first Recipe.
Your First Recipe
The first Recipe will send your daily Fitbit step count to Google Analytics.
Create an IFTTT account, and you should see something like this on your dashboard:

Hit the Create a Recipe button, and in the massive list of connectable services, select Fitbit. (Yes, everything you see there can be sent to GA using the method in this blog post!)

A whole bunch of Fitbit features are supported, but the one we want is Activity Summary which includes your Daily Step Count:

Click on Daily Activity Summary, then on the next screen select Create Trigger:

What we end up with next is pretty awesome. Having defined the THIS we now need to define the THAT:

Go ahead and click on THAT, then search for the Maker Action Channel:

I'll Maker Man Of You Yet, Son
The Maker Channel is a little slice of genius. I absolutely adore it; it's so simple.
Essentially, the job of the Maker Channel is to visit a URL. That's it. You might tell it to visit a certain secret page on your website, and use a pageview counter to count how many times something happened.
What's super-awesome for us is that we can use it to send a hit to Google Analytics via the Measurement Protocol -- and IFTTT makes this incredibly easy.
Set Maker to Make A Web Request, and you should see something like this:

The setup and content of the URL is where the magic happens. As long as you pay attention and set it up correctly, you'll be fine.
Building The URL
To get it working, you need to change two things on the following URL:
https://www.google-analytics.com/collect?v=1&t=event&tid=UA-XXXX-X&cid=XXX-XXXX-XXXX&qt=14400000&ec=Fitbit&ea=Activity&el=Steps&ev={{TotalSteps}}
You've likely spotted what needs changing; replace the UA-XXXX-X
with the UA account of your Google Analytics profile, and replace the cid with the value you got (and kept safely) earlier.
There are some other parameters in here. The qt=14400000 is Queue Time, which allows us to backdate the hit. The reason for this is that Fitbit tends to push its update shortly after midnight, which means that your step count for Monday would be recorded by Google Analytics as occurring on a Tuesday. Adding qt=14400000 pushes the Event back four hours (this is the maximum amount you can backdate a hit, which I've chosen because there could be times you're out of mobile signal in the wee small hours and we want GA to have the best chance possible of assigning the correct date.)
The ec=, ea= and el= are the Event Category, Event Action, and Event Label that will appear in Google Analytics reports:

For the ev= (which, you guess correctly, is Event Value) we can send the number of steps you take.
IFTTT supports some dynamic elements in the URL, which you can access by clicking the conical flask icon in the top right:

This will send the total number of steps as Event Value, which is super awesome:

NOTE: Sometimes, Fitbit will send the notification twice; which means the Event Value gets doubled. This is annoying, and I can't work out if it's a Fitbit thing or an IFTTT thing, but either way if you use Average Value in your reports, multiple hits don't bork your data. And yes, look how active I was on March 7th.
Make sure the Method is set to GET and the Content Type is set to text/plain. We don't need any content in the Body, so we can leave that blank.
Save and you're done!
What Else Can You Do With Fitbit And IFTTT?
I'm glad you asked. You can do tons more.
Using the same Trigger, you can send the number of Calories Burned each day, by swapping ev={{TotalSteps}} with ev={{TotalCaloriesBurned}. Remember to change the name of your Events too, and you're good to go:

Or, using the Trigger for Steps Goal Met, you can send an Event on the days when you hit your Step Goal:

Steps Are Too Active. I Like To Sleep.
Buddy, I like sleep too! Luckily IFTTT can send your daily sleep amount to Google Analytics.
To get this working, you'll need to use the New Sleep Logged Fitbit Trigger, and the following URL in the Maker channel:
https://www.google-analytics.com/collect?v=1&t=event&tid=UA-XXXX-X&cid=XXX-XXXX-XXXX&ec=Fitbit&ea=Sleep&el=Time%20Asleep&ev={{TotalTimeSleptInSeconds}}&cmX={{TotalTimeSleptInSeconds}}
We're using the TotalTimeSleptInSeconds function here, which is fine as Event Value, but works much better as a Custom Metric. Instead of the raw number of seconds, it breaks down into hours, minutes and seconds:

To get this working, you'll need to head to the Admin / Property Settings screen in your Google Analytics account, and create a Custom Dimension like this one:

Set the Scope to Hit, the Formatting Type to Time, make sure it's Active, and you're done.
The important bit is the Index of the Custom Metric. If it's the only one you've set up, the Index will be 1. In my case, it's 2.

Replace the cmX with the number for your Custom Metric; cm2 in my case, cm1 in your likely case.
Tracking Music Played In Google Analytics
UPDATE: As of 25 March, IFTTT no longer integrates with last.fm which means the below method won't work. I'll update here if I hear of a workaround :(
This is probably one of my favourite bits of this type of tracking: what music have I been listening to?

It's super-easy to set up, and if you've done the Fitbit hookup already then you're pretty much already there.
For the Trigger Channel, select Last.fm and for the Action Channel, set Maker again:

Set the URL parameters that you used in the Fitbit tracking, and make the following changes:
https://www.google-analytics.com/collect?v=1&t=event&tid=UA-XXXXXX-X&cid=XXX&ec=Music&ea={{Artist}}&el={{TrackName}}
For this Recipe, as well as changing the UA and cid, we're going to change the Event Category to Music, then use the Artist and Track Name fields to dynamically pull info from Last.fm.
How Awesome Is This
It's brilliant, I love this a lot. I can find, for instance, exactly when my existential crises were happening:

It turns out one of my recent crises happened just in the run up to co-organising MeasureCamp Melbourne. Who'dathunkit?
Because music is being sent to Google Analytics as an Event, it means that Real Time reports are really awesome, like a Now Playing feature:

(Yes, Tuff Love are awesome. I've just discovered them. They're a bit like Sleeper.)
Tracking Drinks
Tracking your drink intake uses a different method -- it's a web app, in beta (yes, beta) developed by the wonderful Max Yodgee from Data Runs Deep.
It's free, it's called HappyOver, and you can find it at http://happyover.com.au

When you create an account, it gives you the option to add a UA number to send drink unit data and dollar spend value to Google Analytics:

Here's the Google Analytics report showing it in action:

NOTE: don't worry, I had many more drinks that this over the last month. These represent the times when I remembered to use HappyOver.com.au
The Unexamined Life Is Not Worth Living
I'm not entirely sure I agree with Plato on this just yet, but I'm loving the ability to look back over stats from different sources, even if it's a bit early to draw any conclusions.
Tracking music is what really interests me, I just wish I'd started doing it sooner. Pinpointing exactly when and where my Stevie Wonder phases (which are extremely passionate and extremely brief) occur would be lots of fun.
Overall though, I've seen this as a fun exercise in using the Measurement Protocol in a way that anyone can plug n'play. Truly Universal Analytics should be just that.