{"id":13416409,"url":"https://github.com/charlotte-ruby/impressionist","last_synced_at":"2025-05-14T01:06:32.414Z","repository":{"id":1374565,"uuid":"1326875","full_name":"charlotte-ruby/impressionist","owner":"charlotte-ruby","description":"Rails Plugin that tracks impressions and page views","archived":false,"fork":false,"pushed_at":"2024-08-14T12:42:53.000Z","size":749,"stargazers_count":1537,"open_issues_count":80,"forks_count":309,"subscribers_count":31,"default_branch":"master","last_synced_at":"2025-04-01T21:16:33.448Z","etag":null,"topics":["counts-impressions","impression","impressions-table","logging-impressions","ruby","unique-impressions"],"latest_commit_sha":null,"homepage":"","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/charlotte-ruby.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.rdoc","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-02-04T04:10:22.000Z","updated_at":"2025-03-31T14:33:49.000Z","dependencies_parsed_at":"2024-09-21T05:02:25.382Z","dependency_job_id":"bad44905-be40-4c66-9817-d4d75ea66cf4","html_url":"https://github.com/charlotte-ruby/impressionist","commit_stats":{"total_commits":372,"total_committers":51,"mean_commits":7.294117647058823,"dds":0.7768817204301075,"last_synced_commit":"96e150959b09f01148a83e1478e7ef038dbff825"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlotte-ruby%2Fimpressionist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlotte-ruby%2Fimpressionist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlotte-ruby%2Fimpressionist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlotte-ruby%2Fimpressionist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/charlotte-ruby","download_url":"https://codeload.github.com/charlotte-ruby/impressionist/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247934841,"owners_count":21020729,"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":["counts-impressions","impression","impressions-table","logging-impressions","ruby","unique-impressions"],"created_at":"2024-07-30T21:00:58.419Z","updated_at":"2025-04-08T22:19:05.656Z","avatar_url":"https://github.com/charlotte-ruby.png","language":"Ruby","readme":"![Impressionist Logo](https://github.com/charlotte-ruby/impressionist/raw/master/logo.png)\n\n[![Main](https://github.com/charlotte-ruby/impressionist/actions/workflows/main.yml/badge.svg)](https://github.com/charlotte-ruby/impressionist/actions/workflows/main.yml)\n[![Code Climate](https://codeclimate.com/github/charlotte-ruby/impressionist.png)](https://codeclimate.com/github/charlotte-ruby/impressionist)\n\nWE ARE LOOKING FOR MAINTAINERS.  CONTACT @johnmcaliley IF YOU ARE INTERESTED IN HELPING\n=======================================================================================\n\nimpressionist\n=============\n\nA lightweight plugin that logs impressions per action or manually per model\n\n--------------------------------------------------------------------------------\n\nWhat does this thing do?\n------------------------\nLogs an impression... and I use that term loosely.  It can log page impressions\n(technically action impressions), but it is not limited to that. You can log\nimpressions multiple times per request.  And you can also attach it to a model.\nThe goal of this project is to provide customizable stats that are immediately\naccessible in your application as opposed to using Google Analytics and pulling\ndata using their API.  You can attach custom messages to impressions.  No\nreporting yet.. this thingy just creates the data.\n\nWhat about bots?\n----------------\nThey are ignored.  1200 known bots have been added to the ignore list as of\nFebruary 1, 2011.  Impressionist uses this list:\nhttp://www.user-agents.org/allagents.xml\n\nInstallation\n------------\nAdd it to your Gemfile\n\n    #rails 6\n    gem 'impressionist'\n    \n    #rails 5 or lower\n    gem 'impressionist', '~\u003e1.6.1'\n\nInstall with Bundler\n\n    bundle install\n\nGenerate the impressions table migration\n\n    rails g impressionist\n\nRun the migration\n\n    rake db:migrate\n\nThe following fields are provided in the migration:\n\n    t.string   \"impressionable_type\"  # model type: Widget\n    t.integer  \"impressionable_id\"    # model instance ID: @widget.id\n    t.integer  \"user_id\"              # automatically logs @current_user.id\n    t.string   \"controller_name\"      # logs the controller name\n    t.string   \"action_name\"          # logs the action_name\n    t.string   \"view_name\"            # TODO: log individual views (as well as partials and nested partials)\n    t.string   \"request_hash\"         # unique ID per request, in case you want to log multiple impressions and group them\n    t.string   \"session_hash\"         # logs the rails session\n    t.string   \"ip_address\"           # request.remote_ip\n    t.text     \"params\"               # request.params, except action name, controller name and resource id\n    t.string   \"referrer\"             # request.referer\n    t.string   \"message\"              # custom message you can add\n    t.datetime \"created_at\"           # I am not sure what this is.... Any clue?\n    t.datetime \"updated_at\"           # never seen this one before either....  Your guess is as good as mine?? ;-)\n\nUsage\n-----\n\n1. Log all actions in a controller\n\n        WidgetsController \u003c ApplicationController\n          impressionist\n        end\n\n2. Specify actions you want logged in a controller\n\n        WidgetsController \u003c ApplicationController\n          impressionist :actions=\u003e[:show,:index]\n        end\n\n3. Make your models impressionable.  This allows you to attach impressions to\n   an AR model instance.  Impressionist will automatically log the Model name\n   (based on action_name) and the id (based on params[:id]), but in order to\n   get the count of impressions (example: @widget.impression_count), you will\n   need to make your model impressionable\n\n        class Widget \u003c ActiveRecord::Base\n          is_impressionable\n        end\n\n4. Log an impression per model instance in your controller.  Note that it is\n   not necessary to specify \"impressionist\" (usage #1) in the top of you\n   controller if you are using this method.  If you add \"impressionist\" to the\n   top of your controller and also use this method in your action, it will\n   result in 2 impressions being logged (but associated with one request_hash).\n   If you're using [friendly_id](https://github.com/norman/friendly_id) be sure\n   to log impressionist this way, as params[:id] will return a string(url slug)\n   while impressionable_id is a Integer column in database. Also note that you\n   have to take step #3 for the Widget model for this to work.\n\n        def show\n          @widget = Widget.find\n          impressionist(@widget, \"message...\") # 2nd argument is optional\n        end\n\n5. Get unique impression count from a model.  This groups impressions by\n   request_hash, so if you logged multiple impressions per request, it will\n   only count them one time.  This unique impression count will not filter out\n   unique users, only unique requests\n\n        @widget.impressionist_count\n        @widget.impressionist_count(:start_date=\u003e\"2011-01-01\",:end_date=\u003e\"2011-01-05\")\n        @widget.impressionist_count(:start_date=\u003e\"2011-01-01\")  #specify start date only, end date = now\n\n6. Get the unique impression count from a model filtered by IP address.  This\n   in turn will give you impressions with unique request_hash, since rows with\n   the same request_hash will have the same IP address.\n\n        @widget.impressionist_count(:filter=\u003e:ip_address)\n\n7. Get the unique impression count from a model filtered by params.  This\n   in turn will give you impressions with unique params.\n\n        @widget.impressionist_count(:filter =\u003e :params)\n\n8. Get the unique impression count from a model filtered by session hash.  Same\n   as #6 regarding request hash.  This may be more desirable than filtering by\n   IP address depending on your situation, since filtering by IP may ignore\n   visitors that use the same IP.  The downside to this filtering is that a\n   user could clear session data in their browser and skew the results.\n\n        @widget.impressionist_count(:filter=\u003e:session_hash)\n\n9. Get total impression count.  This may return more than 1 impression per http\n   request, depending on how you are logging impressions\n\n        @widget.impressionist_count(:filter=\u003e:all)\n\n10. Get impression count by message.  This only counts impressions of the given message.\n\n        @widget.impressionist_count(:message=\u003e\"pageview\", :filter=\u003e:all)\n\nLogging impressions for authenticated users happens automatically.  If you have\na current_user helper or use @current_user in your before_filter (or before_action in Rails \u003e= 5.0) to set your\nauthenticated user, current_user.id will be written to the user_id field in the\nimpressions table.\n\nAdding a counter cache\n----------------------\nImpressionist makes it easy to add a `counter_cache` column to your model. The\nmost basic configuration looks like:\n\n    is_impressionable :counter_cache =\u003e true\n\nThis will automatically increment the `impressions_count` column in the\nincluded model. \u003cb\u003eNote: You'll need to add that column to your model. If you'd\nlike specific a different column name, you can:\u003c/b\u003e\n\n    is_impressionable :counter_cache =\u003e true, :column_name =\u003e :my_column_name\n\nIf you'd like to include only unique impressions in your count:\n\n    # default will be filtered by ip_address\n    is_impressionable :counter_cache =\u003e true, :column_name =\u003e :my_column_name, :unique =\u003e true\n\nIf you'd like to specify what sort of unique impression you'd like to save? Fear not,\nAny option you pass to unique, impressionist_count will use it as its filter to update_counters based on that unique option.\n\n    # options are any column in the impressions' table.\n    is_impressionable :counter_cache =\u003e true, :column_name =\u003e :my_column_name, :unique =\u003e :request_hash\n    is_impressionable :counter_cache =\u003e true, :column_name =\u003e :my_column_name, :unique =\u003e :all\n\n\nAdding column to model\n----------------------\nIt is as simple as this:\n\n    t.integer :my_column_name, :default =\u003e 0\n\nIf you want to use the typical Rails 4 migration generator, you can:\n\n    rails g migration AddImpressionsCountToBook impressions_count:int\n\nWhat if I only want to record unique impressions?\n-------------------------------------------------\nMaybe you only care about unique impressions and would like to avoid\nunnecessary database records. You can specify conditions for recording\nimpressions in your controller:\n\n    # only record impression if the request has a unique combination of type, id, and session\n    impressionist :unique =\u003e [:impressionable_type, :impressionable_id, :session_hash]\n\n    # only record impression if the request has a unique combination of controller, action, and session\n    impressionist :unique =\u003e [:controller_name, :action_name, :session_hash]\n\n    # only record impression if session is unique\n    impressionist :unique =\u003e [:session_hash]\n\n    # only record impression if param is unique\n    impressionist :unique =\u003e [:params]\n\nOr you can use the `impressionist` method directly:\n\n    impressionist(impressionable, \"some message\", :unique =\u003e [:session_hash])\n\nAre you using Mongoid?\n---------------------\n\nExecute this command on your terminal/console:\n\n    rails g impressionist --orm mongoid\n\nThis command create a file `impression.rb` on `config/initializer` folder. Add `config.orm = :mongoid` to this file:\n\n    # Use this hook to configure impressionist parameters\n    Impressionist.setup do |config|\n      # Define ORM. Could be :active_record (default), :mongo_mapper or :mongoid\n      # config.orm = :active_record\n      config.orm = :mongoid\n    end\n\n\nContributing to impressionist\n-----------------------------\n* Check out the latest master to make sure the feature hasn't been implemented\n  or the bug hasn't been fixed yet\n* Check out the issue tracker to make sure someone already hasn't requested it\n  and/or contributed it\n* Fork the project\n* Start a feature/bugfix branch\n* Commit and push until you are happy with your contribution\n* Make sure to add rpsec tests for it. Patches or features without tests will\n  be ignored.  Also, try to write better tests than I do ;-)\n* If adding engine controller or view functionality, use HAML and Inherited\n  Resources.\n* All testing is done inside a small Rails app (test_app).  You will find specs\n  within this app.\n\n\nWant to run the tests? Ok mummy\n-------------------------------\n* bundle install\n* rails g impressionist\n* rake db:migrate \u0026\u0026 rake db:test:prepare\n* Run rake or rspec spec inside test_app dir\n* nothing else.\n* :wq\n\nContributors\n------------\nWE ARE CURRENTLY LOOKING FOR SOMEONE TO HELP MAINTAIN THIS REPOSITORY.  IF YOU ARE INTERESTED, MESSAGE @johnmcaliley.\n\n* [johnmcaliley - creator](https://github.com/johnmcaliley)\n* [jgrau](https://github.com/jgrau)\n* [acnalesso](https://github.com/acnalesso)\n* [coryschires](https://github.com/coryschires)\n* [georgmittendorfer](https://github.com/georgmittendorfer)\n\n\nCopyright (c) 2011 John McAliley. See LICENSE.txt for further details.\n","funding_links":[],"categories":["Ruby","Logging","日志","Analytics"],"sub_categories":["Omniauth"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharlotte-ruby%2Fimpressionist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcharlotte-ruby%2Fimpressionist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharlotte-ruby%2Fimpressionist/lists"}