Application for providing an endpoint for in-app events. Events are then passed off to redis for storage in kafka. Some other features of note:
- SSL Termination is done by the application
- Load balancing can be easily done by increasing the number of dynos
- Geoip and device detection are explicitly not done. These are subsequently handled by the kafkastore
- Event types (determined by the request path) can be anything although some base events are assumed.
- Kafka topic is determined by the subdomain of the request.
This application has the same purpose as the click tracker but handles in-app events. The click tracker has more logic since it also has to handle redirects to application stores (i.e. google and apple).
Hence the code is extremely concise. The only thing to note here is that the subdomain determines the kafka topic to which the event is written to. Request path determines the event type. The specific event type is the string after the final '/' (slash).
This means that these two paths represent the same install
event /fubar/ist
and /som/moe/rpa/ist
. By convention the path
should be /t/ist
, i.e. with a leading /t
.
The string that is pushed to redis is structured as follows (all values are separeted by a single space):
"%s %i %s %s %s %s" % [request.ip,
Time.now.to_i,
request.host.split(".").first,
request.path,
if_blank(request.query_string, "p"),
request.user_agent])
- Request IP which is later converted to a country by the kafkastore using geoip lookup.
- Timestamp in seconds since epoch when the request was recieved by the tracker.
- Kafka topic to store the message. In this case, the subdomain of the request host.
- Event type which is represented by the request path.
- Original query string of the request or if blank, a single 'p'.
- User agent is appended to the end. This the later converted to device information by the kafkastore. Note: the user agent can contain spaces, the user agent is assumed to be everything after query string.
If this format should change, then the kafkastore needs updating, along with the click tracker.
Easiest way to deploy this, is to use heroku!
Generate a .env
and then fill it with values:
prompt> rake appjson:to_dotenv
prompt> $EDITOR .env
Start the application:
prompt> foreman start