{"id":16726870,"url":"https://github.com/tpitale/staccato-rails","last_synced_at":"2025-03-23T15:31:00.311Z","repository":{"id":9969071,"uuid":"11993709","full_name":"tpitale/staccato-rails","owner":"tpitale","description":"Seamless Rails integration with Staccato","archived":true,"fork":false,"pushed_at":"2020-09-18T16:20:31.000Z","size":27,"stargazers_count":26,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-18T21:50:51.083Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/tpitale.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2013-08-09T05:20:32.000Z","updated_at":"2025-02-14T14:52:35.000Z","dependencies_parsed_at":"2022-09-02T14:12:08.014Z","dependency_job_id":null,"html_url":"https://github.com/tpitale/staccato-rails","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpitale%2Fstaccato-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpitale%2Fstaccato-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpitale%2Fstaccato-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpitale%2Fstaccato-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tpitale","download_url":"https://codeload.github.com/tpitale/staccato-rails/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245122682,"owners_count":20564357,"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":[],"created_at":"2024-10-12T22:54:48.112Z","updated_at":"2025-03-23T15:31:00.022Z","avatar_url":"https://github.com/tpitale.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Staccato::Rails\n\nProvides seamless integration with basic tracking of rails (timing and pageviews) into the Google Analytics Measurement API.\n\n[![Build Status](https://travis-ci.org/tpitale/staccato-rails.png?branch=master)](https://travis-ci.org/tpitale/staccato-rails)\n[![Code Climate](https://codeclimate.com/github/tpitale/staccato-rails.png)](https://codeclimate.com/github/tpitale/staccato-rails)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'staccato-rails'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install staccato-rails\n\n## Provides\n\n* Timing from instrumentation (total duration, db_runtime, view_runtime)\n* Pageview tracking on GETs\n* Event tracking hooks in controllers, models that use the request session client id\n* Exception tracking (tracks only the exception name)\n\nSession UUID for the `client_id` is handled for you. Can be overridden easily, see [Overriding the client_id](#overriding-the-client_id).\n\n## Usage ##\n\n### Configuration ###\n\nIn **environments/production.rb** (leave blank in development/test to not track):\n\n```ruby\nconfig.staccato.tracker_id = 'UA-XXXX-Y'\nconfig.staccato.hostname = 'domain.com' # optional, but recommended\n```\n\n**Note:** Because this is a Rails-specific gem, we leverage Rails' method of configuration. As such configuration should be placed in the appropriate environment file, specifically `production.rb`. It is _ill-advised_ to configure in Development or Test environments as that may cause false tracking during local work.\n\n### Tracking ###\n\nIn controllers, `tracker` is made available to you:\n\n```ruby\ntracker.event(category: 'video', action: 'play', label: 'cars', value: 1)\n```\n\nNote: if you have an existing method named `tracker`, this is also available with the more verbose `staccato_tracker`.\n\n## Overriding the client_id ##\n\nA method is added to your controller called `staccato_client_id`. By default, it's implementation looks like:\n\n```ruby\nsession['staccato.client_id'] ||= Staccato.build_client_id\n```\n\nIf you wish to not store the `client_id` in session, or you wish to use another UUID value, you may override the method `staccato_client_id` as you see fit. Make sure that the `client_id` you generate fits with Google Analytics requirements. It _must_ remain the same `client_id` for an individual user's \"session\" (by GA standards) if you wish to track a user as they move through your application.\n\n## Setting a pageview prefix ##\n\n```ruby\nconfig.staccato.pageview_prefix = '/staccato'\n```\n\n## Tracking exceptions ##\n\n```ruby\nconfig.staccato.exceptions = true\n```\n\nTracking exceptions happens by adding to `ActionController::Base` a `rescue_from` for Exception. Because of this, it will only rescue exceptions that have not already been rescued from in your own code. If you wish to track those exceptions, as well, you can call `track_exception_with_staccato(exception)` to your own `rescue_from` methods.\n\n## Disable some, or all, tracking\n\nInside of your `environment` files, as appropriate\n\n```ruby\nconfig.staccato.timing = false\nconfig.staccato.pageviews = false\nconfig.staccato.exceptions = false # default\n```\n\n## Disable tracking for a controller\n\nYou can disable tracking of a specific controller by adding a class method.\n\n```ruby\nclass SomeController\n  def self.staccato_page_disabled?; true; end\n  def self.staccato_timing_disabled?; true; end\nend\n```\n\n## Adding Global and Hit context ##\n\nTo add values like `user_ip` to all hits called by `tracker` (in both your own code, and staccato-rails) create a method `global_context` in your controller and return a hash:\n\n```ruby\ndef global_context\n  {\n    user_ip: request.remote_ip\n  }\nend\n```\n\nTo add values only to the hits sent by staccato-rails (but not your own use of `tracker`) for pageviews and timing create a method `hit_context` in your controller and return a hash:\n\n```ruby\ndef hit_context\n  {\n    user_agent: \"cURL\"\n  }\nend\n```\n\nIf per-action control over the hits sent to GA is required you're better off just using `Staccato` directly at this point.\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftpitale%2Fstaccato-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftpitale%2Fstaccato-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftpitale%2Fstaccato-rails/lists"}