Let's set up some event tracking on Alchemist Camp!
This video has 3 parts:
- What to track (the 5 most important user actions) - at 0:34
- The tools (Keenex, Geolix, UAInspector) - at 3:53
- Coding it! - at 7:17
You can see the video for a longer explanation but we'll be tracking some data that we don't necessarily have a use for, since past data can be used in the future in ways that aren't immediately apparent. However, in line with advice Emmet Shear (of Twitch fame) gave about analytics a few years ago, we're not going to get carried away tracking as much as we can. Instead we're going to track the most important 5 or so events. For Alchemist Camp, those are as follows: page views, subscription changes, page shares and referrals.
The reason we're using Keen instead of something like Mix Panel is that it's a bit lower level. This makes it both cheaper and more flexible and it's a good choice for developers in general.
Libraries we'll use
The last two libraries are for extracting useful information from IP addresses and user agent strings to enrich our event data.
We create a
Plug that gets the data we want to track from our
Conn, builds a JSON object and then sends it to Keen. That plug goes into the
:browser pipeline in our router. Finally, after getting everything working, we make the event logging asynchronous by using