Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Analytics for Ruby

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 229
    Comment on it

    To integrate analytics into Rails application analytics-ruby gem can be used. By using this gem we can identify users and track their activity.

    To install into gemfile:

    gem 'analytics-ruby', :require => "segment"

     

    After that initialize the gem with your Segment source’s Write Key and an optional error handler in config/initializers/analytics_ruby.rb

    require 'segment/analytics'
    
    Analytics = Segment::Analytics.new({
        write_key: 'PUT_YOUR_WRITE_KEY',
        on_error: Proc.new { |status, msg| print msg }
    })

     

    Now identify the user using identify method. It includes a unique User ID and any optional traits about the user.

    Analytics.identify(
        {
            user_id: user.id,
            traits: {
                email: user.email,
                first_name: user.first_name,
                last_name: user.last_name
            }
        }
    )

     

    To track a user event

    Analytics.track(
        {
            user_id: user.id,
            event: 'Logged in'
        }
    )

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: