After posting on Google+ about my blog post on the measurement of offline stores with Google Universal Analytics, I got a dare by user Damion Brown from Melbourne, Australia, to track what his dog was doing using a similar method.
Damion: I’m sorry, mate. I’m afraid I have bad news and good news.
- The bad news is: I don’t own a dog so I’m not sure as to what I’d want to track.
- The good news is: I can give you pointers on how to do it. I have done enough tinkering in the last 2 weeks so I’ll let by blog readers do it this time around. You guys get to test (and prove) the concept yourself!
In this experiment, you will attempt the following: track your dog’s location (in 5 minute increments), in relationship to your house, with Google Universal Analytics.
I have a few ideas about that and I’ll be sharing them after the jump.
This suggestion is a bit more high-tech than the previous proof-of-concept project.
This concept involves dog collars, 3G and satellites. Not the kick-ass tag management solution, I’m talking about those things that clutter the Earth’s lower orbit.
Yes, i’m talking about tracking your dog with a GPS-enabled collar via Google Analytics over 3G (phew).
My suggested process involves the following steps:
Step 1: Define your location
Using your GPS-enabled smartphone and determine the GPS coordinates for your humble abode.
Mine is Lat. 44.5406233, Long. 4.7618274 give or take a couple meters for precision. If not sure, use a street address-based GPS location website such as http://www.whatsmygps.com/.
Step 2: Pimp your doggie
Now let’s bring in my imaginary dog. I call him Sparky because the poor thing has no hind legs and balls of steel.
Now we need to give Sparky superpowers of measurement. Let’s go shopping!
You’re probably going to need the following items:
- One of our trusty Raspberry Pi mini-computers. Use a Model B for improved USB ports. Don’t forget the power supply.
- A 3G USB dongle – won’t work on Raspberry Pi A according to this post
- A working SIM card with a standing subscription with your favorite ISP
- A GPS chip – complete instructions and buying guide
You’ll need the GPS chip to gather your dog’s location and the 3G dongle to communicate with the Google Analytics mothership. On the software side of things, you will need a GPS server and client (gpsd).
Hack this all together. Your turn to be creative. Now hang this to your dog’s collar on in one of those fancy doggie backpacks. Sparky should be ready to be released into the wild (your backyard) to measure and report his position.
Step 3: Who let the dog out?
Now we need to ping your GPS every so often and it should return a set of coordinates with latitude and longitude. Ironically for Google Analytics tracking of your dog’s pimped-out GPS 3G collar, the alternative system for lat/long coordinates is called… *drumroll*… UTM 😀
The GPS client you installed on your Raspberry Pi should return the coordinates for you. It looks like it has a Python API. Heck, it will even give you a JSON feed!
Now apply a bit of math to calculate the distance between your home’s GPS coordinates and your dog’s current coordinates. Store that value in a Python variable, determine the direction from your home (N, S, E, W, etc.) and get ready for doggie to phone home.
Step 4: Sending data to Google Universal Analytics
Using the same method I used for PDF tracking with Google Universal Analytics, let’s define our UA endpoint:
http://www.google-analytics.com/collect<br />?v=1 // site/app version<br />&t=event // GA hit type (event here)<br />&tid=UA-7634164-5 // GA profile ID<br />&cid=555 // anonymous visitor ID<br />&ec=DoggyTrack // Event - Category<br />&ea=Ping // Event - Action<br />&el=SW // Event - Label<br />&ev=12 // Event - Value - Distance from home
Now let’s call this endpoint on a regular basis, every few seconds or so – matching the GPS requests – using wget:
wget -q -O /tmp/pixel.gif "$endpoint"
Set it as a cron task and pronto! Now you should get reports that list the distance as event value and direction as event label. Reports (regular or custom) can also show you the average distance (value) your dog strays away from home in any given direction.
Step 5: Profit!
Sounds pretty simple, right? Then go get it done and do send pics of your pimped out analytics doggie!
I can already hear you say:
Hey but can’t you just shove a 3G/4G-enabled smartphone in the doggie’s pouch and have the web browser on the phone refresh a page with Google Analytics tagging until the battery dies out and still get stats?
- Location stats are not that great with geoloc, even with Google Analytics.
- Google Analytics geolocation reports do not provide this level of geoloc refinement down to the meter, only GPS does.
- Google Analytics doesn’t know where your house is. Yet.
I hope you’ll have as much fun trying this as I did with the mock online store with webcams project. You will see that is is fun to work with Raspberry Pis!
Like I said, post your pictures with your dog and screenshots on the Google+ Google Analytics Community!
Comments? Constructive criticism? Do drop me a line using the box below!