Ruby On Rails
Last updated
Last updated
If you are installing Sandstorm in your Rails app, the JavaScript Library may actually be more appropriate for your frontend tracking. Consider using the Analytical RubyGem to help ease integration of multiple analytics products into your Rails app.
RubyGem link: GitHub link:
This is an example on how to integrate Sandstorm into a Ruby on Rails application using the basic Ruby Library.
Begin by placing the Ruby Library script in your lib/ directoy.
In the controller you wish to use, create a before_filter
Identify the user you want to track
Record your events and properties That’s it! Let’s look at each individual step in more detail.
Simply place the km.rb
file you downloaded in to your lib/
directory. Copying the script in your lib/
directory allows Rails to source the Sandstorm code. There is no need to require
anything.
Initialize Sandstorm before making any requests by calling KM.init
. You can include this in a Rails initializer, or create a before_filter
:
Ruby
There are two types of users to track here. You can track identified users, or unidentified users. The Ruby Library, unlike the JavaScript Library does not automatically provide a way to track anonymous/unidentified users. However, we often would like to track anonymous users, and then later after they have logged in, or better yet, signed up, continue keeping track of them. The following is an example how you can, through cookies, and KM.alias continue keeping track of such users.
Ruby
You can refer back to the for example API calls.