The meda gem currently provides a collector application that is used to gather analytics events from web browsers, mobile apps or back-end servers, and send page views and events to Google Analytics.
The collector is written in Sinatra and deployed with the puma webserver.
The collector application requires jRuby 1.7+ and Java 1.6+.
To store profile data, the collector uses MapDB, a pure-java embedded key-value store database. The jar files for MapDB are included in the meda gem, and are plaform independent.
To create your own collector application, create a new git repo that will use the meda gem.
Add a Gemfile to the repo, and bundle install. Note that your git user must have access to this github repo, or you must use a github url that includes the credentials of a github user that has access.
# Gemfile
source 'https://rubygems.org'
gem 'meda', :git => 'github.com/medullan/meda.git'
gem 'puma'The application configuration file (meda.yml) defines the location of the data files, log files and other essential functionality. Add this file in the root of the project, and it will be loaded automatically when the server starts. You should provide different configuration options for different Rack environments (RACK_ENV).
Check CONFIGURATION.md for comprehensive configuration information.
This example file demonstrates all acceptable configuration options.
# meda.yml
development:
disk_pool: 2
google_analytics_pool: 2
mapdb_path: db
data_path: data
log_path: log/development.log
log_level: 0
production:
disk_pool: 4
google_analytics_pool: 16
mapdb_path: db
data_path: meda_data
log_path: log/production.log
log_level: 1The dataset configuration file (datasets.yml) defines the buckets into which analytics data is collected, and how that data is treated. The data for each dataset is stored in a separate MapDB database, and also in a separate path on the filesystem.
Here is a sample file:
# datasets.yml (sample)
production:
token: afc0a6c8c73211e3aaf844fb42fffe8c
google_analytics:
record: true
tracking_id: UA-47758842
custom_dimensions:
age:
index: 1
gender:
index: 2
segment:
index: 3
staging:
token: b6822676c73211e3aaf844fb42fffe8c
google_analytics:
record: false
development:
token: c2e02c92c73211e3aaf844fb42fffe8c
google_analytics:
record: falseAdd a config.ru file to your project to configure the rack environment to run the collector. A sample file may look like this:
# config.ru
require 'rubygems'
require 'bundler/setup'
require 'meda'
require 'meda/collector'
run Meda::Collector::AppWe suggest running the collector in Puma. Puma is a multi-threaded web server that has great performance on jRuby! If you have added it to your Gemfile, then you can just run it like this:
$ puma --environment development --port 8000 --threads 0:4
$ puma --environment production --port 80 --threads 32:32Add specs for all new functionality. Run unit tests with RSpec.
$ bundle exec rspec -fd