{"id":23081115,"url":"https://github.com/userlist/userlist-rails","last_synced_at":"2025-08-15T23:31:13.988Z","repository":{"id":43823133,"uuid":"117992291","full_name":"userlist/userlist-rails","owner":"userlist","description":"Rails integration for Userlist","archived":false,"fork":false,"pushed_at":"2024-03-21T11:48:26.000Z","size":158,"stargazers_count":11,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-12-16T04:36:34.688Z","etag":null,"topics":["rails","ruby","userlist"],"latest_commit_sha":null,"homepage":"http://userlist.com","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/userlist.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-01-18T14:19:23.000Z","updated_at":"2024-08-30T20:11:21.000Z","dependencies_parsed_at":"2023-12-14T14:29:39.534Z","dependency_job_id":"4f989427-4cad-44f3-9240-de6d27cfa033","html_url":"https://github.com/userlist/userlist-rails","commit_stats":null,"previous_names":["userlistio/userlist-rails"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/userlist%2Fuserlist-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/userlist%2Fuserlist-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/userlist%2Fuserlist-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/userlist%2Fuserlist-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/userlist","download_url":"https://codeload.github.com/userlist/userlist-rails/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229970532,"owners_count":18152682,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rails","ruby","userlist"],"created_at":"2024-12-16T13:47:12.741Z","updated_at":"2024-12-16T13:47:13.463Z","avatar_url":"https://github.com/userlist.png","language":"Ruby","readme":"# Userlist for Ruby on Rails [![Build Status](https://github.com/userlist/userlist-rails/workflows/Tests/badge.svg)](https://github.com/userlist/userlist-rails)\n\nThis gem helps with integrating [Userlist](http://userlist.com) into Ruby on Rails applications.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'userlist-rails'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install userlist-rails\n\n## Configuration\n\nThe only required configuration is the Push API key. You can get your Push API key via the [Push API settings](https://app.userlist.com/settings/push) in your Userlist account.\n\nConfiguration values can either be set via an initializer or as environment variables. The environment take precedence over configuration values from the initializer. Please refer to the [userlist](http://github.com/userlist/userlist-ruby) gem for additional configuration options.\n\nConfiguration via environment variables:\n\n```shell\nUSERLIST_PUSH_KEY=VvB7pjDrv0V2hoaOCeZ5rIiUEPbEhSUN\nUSERLIST_PUSH_ID=6vPkJl44cm82y4aLBIzaOhuEHJd0Bm7b\n```\n\nConfiguration via an initializer:\n\n```ruby\n# config/initializer/userlist.rb\nUserlist.configure do |config|\n  config.push_key = 'VvB7pjDrv0V2hoaOCeZ5rIiUEPbEhSUN'\n  config.push_id = '6vPkJl44cm82y4aLBIzaOhuEHJd0Bm7b'\nend\n```\n\nIn addition to the configuration options of the [userlist](http://github.com/userlist/userlist-ruby#configuration) gem, the following options are available.\n\n| Name            | Default value                | Description                                                                                                          |\n| --------------- | ---------------------------- | -------------------------------------------------------------------------------------------------------------------- |\n| `user_model`    | `nil`                        | The user model to use. Will be automatically set when `auto_discover` is `true`                                      |\n| `company_model` | `nil`                        | The company model to use. Will be automatically set when `auto_discover` is `true`                                   |\n| `relationship_model` | `nil`                        | The relationship model to use. Will be automatically infered from the user and company models                                   |\n| `auto_discover` | `true`                       | The gem will try to automatically identify your `User` and `Company` models. Possible values are `true` and `false`. |\n| `script_url`    | `https://js.userlist.com/v1` | The script url to load the Userlist in-app messages script from.                                                     |\n\n### Disabling in development and test environments\n\nAs sending test and development data into data into Userlist isn't very desirable, you can disable transmissions by setting the push strategy to `:null`.\n\n```ruby\n# config/initializer/userlist.rb\nUserlist.configure do |config|\n  config.push_strategy = :null unless Rails.env.production?\nend\n```\n\n## Usage\n\n\u003e ⚠️ **Important:** If you're using [Segment](https://segment.com) in combination with this gem, please make sure that both are using the same user identifier. By default, this gem will send `\"user-#{id}\"` (a combination of the user's primary key in the database and the `user-` prefix) as identifier. Either customize the `userlist_identifier` method on your User model, or ensure that you use the same identifier in your Segment integration.\n\n### Tracking Users\n\n#### Sending user data automatically\n\nBy default, this gem will automatically detect your `User` model and create, update, and delete the corresponding user inside of Userlist. To customize the `identifier`, `email`, or `properties` transmitted for a user, you can overwrite the according methods in your `User` model.\n\n```ruby\nclass User \u003c ApplicationRecord\n  def userlist_properties\n    { first_name: first_name, last_name: last_name }\n  end\n\n  def userlist_identifier\n    \"user-#{id}\"\n  end\n\n  def userlist_email\n    email\n  end\nend\n```\n\n#### Sending user data manually\n\nTo manually send user data into Userlist, use the `Userlist::Push.users.push` method.\n\n```ruby\nUserlist::Push.users.push(user)\n```\n\nIt's also possible to customize the payload sent to Userlist by passing a hash instead of the user object.\n\n```ruby\nUserlist::Push.users.push(identifier: user.id, email: user.email, properties: { first_name: user.first_name, last_name: user.last_name })\n```\n\n#### Ignoring users\n\nFor cases where you don't want to send specific user to Userlist you can add a `userlist_push?` method. Whenever this method doesn't return a falsey value, this user will not be sent to Userlist. This also applies to any events or relationships this user is involved in.\n\n```ruby\nclass User \u003c ApplicationRecord\n  def userlist_push?\n    !deleted? \u0026\u0026 !guest?\n  end\nend\n```\n\n#### Deleting users\n\nIt's also possible to delete a user from Userlist, using the `Userlist::Push.users.delete` method.\n\n```ruby\nUserlist::Push.users.delete(user)\n```\n\n\n### Tracking Companies\n\n#### Sending company data automatically\n\nBy default, this gem will automatically detect your company model (like `Account`, `Company`, `Team`, `Organization`) and create, update, and delete the corresponding company inside of Userlist. To customize the `identifier`, `name`, or `properties` transmitted for a company, you can overwrite the according methods in your company model.\n\n```ruby\nclass Account \u003c ApplicationRecord\n  def userlist_properties\n    { projects: projects.count }\n  end\n\n  def userlist_identifier\n    \"account-#{id}\"\n  end\n\n  def userlist_name\n    name\n  end\nend\n```\n\n\n#### Sending company data manually\n\nTo manually send company data into Userlist, use the `Userlist::Push.companies.push` method.\n\n```ruby\nUserlist::Push.companies.push(company)\n```\n\nIt's also possible to customize the payload sent to Userlist by passing a hash instead of the company object.\n\n```ruby\nUserlist::Push.companies.push(identifier: company.id, name: company.name, properties: { projects: company.projects.count })\n```\n\n\n#### Ignoring companies\n\nFor cases where you don't want to send specific company to Userlist you can add a `userlist_push?` method. Whenever this method doesn't return a falsey value, this company will not be sent to Userlist. This also applies to any events or relationships this company is involved in.\n\n```ruby\nclass Account \u003c ApplicationRecord\n  def userlist_push?\n    !deleted? \u0026\u0026 active_subscription?\n  end\nend\n```\n\n#### Deleting companies\n\nIt's also possible to delete a company from Userlist, using the `Userlist::Push.companies.delete` method.\n\n```ruby\nUserlist::Push.companies.delete(company)\n```\n\n### Tracking relationships\n\nUserlist supports n:m relationships between users and companies. This gem will try to figure out the model your application uses to describe these relationships by looking at the associations defined in your user and company models. When sending a user to Userlist, this gem will try to automatically include the user's relationships as well. This includes information about the relationships and companies this user is associated with, but not information about other users associated with any of the companies. This works the other way around as well. When sending a company, it'll try to automatically include the company's relationships, but not any information about the associated users' other companies.\n\n```ruby\nuser = User.create(email: 'foo@example.com')\nuser.companies.create(name: 'Example, Inc.')\n\nUserlist::Push.users.push(user)\n\n# Payload sent to Userlist\n{\n  identifier: 'user-1',\n  email: 'foo@example.com',\n  relationships: [\n    {\n      user: 'user-identifier',\n      company: {\n        identifier: 'company-identifier',\n        name: 'Example, Inc.',\n      }\n    }\n  ]\n}\n```\n\nSimilar to users and events, these relationships may define a `userlist_properties` method to provide addition properties that describe the relationship.\n\n```ruby\nclass Membership \u003c ApplicationRecord\n  belongs_to :user\n  belongs_to :account\n\n  def userlist_properties\n    { role: role }\n  end\nend\n```\n\n\n#### Customizing relationship lookup\n\nIt's possible to customize the way this gem looks up relationships for users and companies by specifying a `userlist_relationships` method on the user and/or company model.  \n\n```ruby\nclass User \u003c ApplicationRecord\n  def userlist_relationships\n    memberships.where(role: 'owner')\n  end\nend\n```\n\nIf you don't have a dedicated model describing the relationship, you can return a hash including both the user and the company model.\n\n```ruby\nclass User \u003c ApplicationRecord\n  def userlist_relationships\n    [\n      {\n        user: self,\n        company: account\n      }\n    ]\n  end\nend\n```\n\n#### Ignoring relationships\n\nThis gem automatically ignore relationship if either the user or the company is ignored. However, in some cases it might be desirable to ignore relationships even when they connect to valid objects. A typical example for this are pending invitations. To support this use case, you can provide a `userlist_push?` method. Whenever this method doesn't return a falsey value, this relationship will not be sent to Userlist.\n\n```ruby\nclass Membership \u003c ApplicationRecord\n  belongs_to :user\n  belongs_to :account\n\n  def userlist_push?\n    pending?\n  end\nend\n```\n\n#### Deleting relationships\n\nIt's also possible to delete a relationship from Userlist, using the `Userlist::Push.relationships.delete` method.\n\n```ruby\nUserlist::Push.relationships.delete(membership)\n```\n\n### Tracking Events\n\nTo track custom events use the `Userlist::Push.events.push` method. Events can be related to a user, a company, or both.\n\n```ruby\nUserlist::Push.events.push(name: 'project_created', user: current_user, company: current_account, properties: { project_name: project.name })\n```\n\n### Enabling in-app messages\n\nIn order to use in-app messages, please set both the `push_key` and `push_id` configuration variables. Afterwards, include the `userlist_script_tag` helper into your application's layout for signed in users.\n\n```erb\n\u003c%= userlist_script_tag %\u003e\n```\n\nBy default, the helper will try to use the `current_user` helper to read the currently signed in user. You can change the default bebahvior by passing a different user. The passed object must respond to the `userlist_identifier` method.\n\n```erb\n\u003c%= userlist_script_tag(user) %\u003e\n```\n\n### Batch importing\n\nYou can import (and update) all your existing users and companies into Userlist by running the import rake task:\n\n```shell\nrake userlist:import\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at \u003chttps://github.com/userlist/userlist-rails\u003e. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Userlist::Rails project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/userlist/userlist-rails/blob/master/CODE_OF_CONDUCT.md).\n\n## What is Userlist?\n\n[![Userlist](https://userlist.com/images/external/userlist-logo-github.svg)](https://userlist.com/)\n\n[Userlist](https://userlist.com/) allows you to onboard and engage your SaaS users with targeted behavior-based campaigns using email or in-app messages.\n\nUserlist was started in 2017 as an alternative to bulky enterprise messaging tools. We believe that running SaaS products should be more enjoyable. Learn more [about us](https://userlist.com/about-us/).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuserlist%2Fuserlist-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuserlist%2Fuserlist-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuserlist%2Fuserlist-rails/lists"}