1gem install june-analytics-ruby
To install the gem from Ruby Gems into a ruby app, simply run:
1gem install june-analytics-ruby
Now, you must configure the June SDK with a valid API key, which you can get from your June workspace.
1require 'june/analytics' 2 3Analytics = June::Analytics.new({ 4write_key: 'YOUR_WRITE_KEY' 5})
If you're using Rails, you can create a config/initializers/analytics_ruby.rb
file and add the following code:
1require 'june/analytics' 2 3Analytics = June::Analytics.new({ 4write_key: Rails.env.production? ? ENV['JUNE_WRITE_KEY'] : 'YOUR_TEST_WRITE_KEY', 5on_error: proc { |_status, msg| print msg }, 6stub: !Rails.env.production? 7})
You can use the identify
method to identify your users. Replace USER_ID
with the unique identifier for the user in your database.
1Analytics.identify(user_id: 'USER_ID', 2traits: { 3email: 'test@example.com' 4})
You can use the group
method to identify your companies. Replace GROUP_ID
and USER_ID
with the unique identifier for the company and user in your database.
1Analytics.group(user_id: 'USER_ID', 2group_id: 'GROUP_ID', 3traits: { 4name: 'Acme Inc' 5})
In order to track user behaviour, you can use the track
method.
Note: If you're identifying companies, you should pass the groupId
in the track context, as shown in the example below. Replace GROUP_ID
and USER_ID
with the unique identifier for the company and user in your database.
1Analytics.track(user_id: 'USER_ID', 2event: 'Created Account', 3properties: { 4plan: 'Pro' 5}, 6context: { 7groupId: 'GROUP_ID' 8})
Our SDK is based on Segment's SDK. You can find more documentation here: https://segment.com/docs/connections/sources/catalog/libraries/server/ruby