There are quite a few reasons for why you should be tracking the time you’ve spent on your projects, just read through one of the many websites that sell time tracking tools. If you are tech savvy, you might actually prefer having access to an easy to use and free API that allows you to do just that.
At the end of this tutorial, you will be able to automatically keep track of how much time you’ve spent at your office (or wherever), without ever having to interact with a time tracking tool.
If you convince your team to also follow this tutorial, you could analyse who’s at the office during which time of the day and for how long, or quickly see who’s currently there.
The Tracking API
Luckily, there’s a free time tracking API on GitHub that you can use for automated time tracking. It’s a simple JSON API hosted on the Google App Engine, providing endpoints for our use case.
The API can handle 3 basic objects:
- Users, representing the one who is using the API (e.g. you)
- Topics, representing whatever you want to track (e.g. a project or location)
- Actions, representing tracking events (e.g. starting or stopping to work)
First of all, you’ll need to create a user and a topic, so that your activities can be assigned to you and your project. Fire the following web requests to create a new user called “John Doe” and a new topic named “Work”:
Each of these requests will return a JSON representation of the object you just created. Make sure that you save these, as you will need the ids of these objects for tracking. And that’s it, your good to go and may start tracking now!
To actually track something, simply call the following endpoint:
This time, you’ll need to replace “123” and “456” with your user id and topic id (the ones you created during the setup). The request above would create an action named “start”, you would want to fire it each time you start working on your project. In order to let the API know that you stopped working on your project, simply fire:
Keep in mind that you should always use the same two actions if you want to get any meaningful results later. Actions that make sense could be:
- start and stop
- pause and resume
- arrive and leave
If you are working with a team, make sure that everyone uses the same topic id.
Automate using IFTTT
Let’s say you want to automatically add an action to the API whenever you arrive at your office location:
- Create a new recipe
Create a trigger
- Select the Android / iOS Location channel
- Select the You enter an area trigger
- Select your office location
Create an action
- Select the Maker channel
- Select the Make a web request action
- Enter the API request for adding an action as URL
- Set the request Method to GET
- Name and save your recipe
Now every time you arrive at your office, IFTTT will automatically add an action to the tracking API. For this to make any sense, you also need to create a recipe that triggers when you leave your office.
Analyse what you tracked
After you’ve created some actions, you might want to check what the API recorded for you:
You could use the returned data to draw some fancy charts on a website or simply calculate how much time you’ve spent on a project in the last month. If you want to filter the returned actions, you can add some of these parameters to the request:
- topicId to filter the actions by topic (e.g. “456”)
- name to filter the actions by name (e.g. “start”)
- minimumTimestamp to get actions after (e.g. “1468413570000”)
- maximumTimestamp to get actions before (e.g. “1468417170000”)
- limit to limit the number of returned actions (e.g. “50”)
- offset to skip some actions (e.g. “25”)