Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
This repository was archived by the owner on Mar 20, 2019. It is now read-only.
/ahoy-viewsPublic archive

Track views of ActiveRecord objects in Rails

License

NotificationsYou must be signed in to change notification settings

jonhue/ahoy-views

Repository files navigation

Gem Version

Track views of ActiveRecord objects in Rails. Ahoy Views depends onAhoy.


Table of Contents


Installation

Note: Before installing Ahoy Views make sure to setup the originalAhoy gem.

Ahoy Views works with Rails 5 onwards. You can add it to yourGemfile with:

gem'ahoy-views'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ahoy-views

If you always want to be up to date fetch the latest from GitHub in yourGemfile:

gem'ahoy-views',github:'jonhue/ahoy-views'

Now run the generator:

$ rails g ahoy_views

Lastly make sure to callahoy_views from yourAhoy::Event class:

moduleAhoyclassEvent <ApplicationRecordahoy_viewsendend

Usage

Tracking

You can track views for ActiveRecord objects from your controllers:

classArticleController <ApplicationControllerdefindex@articles=Article.allahoy_view@articlesenddefshow@article=Article.findparams[:id]ahoy_view@articleendend

Note: This will create anAhoy::Event object for every record passed.

Thecurrent_visit object, if present, will be automatically associated with every visit.

You are also able to associate other records with views.Learn more.

Types

You can pass an array oftypes toahoy_view. Types allow you to track multiple types of visits. The:types option defaults to[:view].

ahoy_view@article,types:[:view,:visitor,:returnee,:unique_visitor,:unique_returnee]

Here is a list of available types:

  • :view stores every call toahoy_view for an object.

  • :visitor stores only one view per visit.

  • :returnee stores only one view per visit if the visitor has viewed the object before.

  • :unique_visitor stores only one view per visitor.

  • :unique_returnee stores only one view per visitor if the visitor has viewed the object before.

ahoy_viewable

Addahoy_viewable to an ActiveRecord class.

classArticle <ApplicationRecordahoy_viewableenda=Article.first# All belonging Ahoy::Event objects that are a viewa.ahoy_views# All viewer records that have a view objecta.ahoy_viewers# Scope to order Article records by viewsArticle.trending# Whether or not a is one of the 5 "most trending" articlesa.trending?5

ahoy_viewer

Addahoy_viewer to an ActiveRecord class.

classUser <ApplicationRecordahoy_viewerendu=User.first# All belonging Ahoy::Event objects that are a viewu.ahoy_visits# All records that this user has taken a look atu.ahoy_viewed

Here is how to associate a viewer with a view:

ahoy_view@article,viewer:current_user

To Do

Here is the full list of current projects.

To propose your ideas, initiate the discussion by adding anew issue.


Contributing

We hope that you will consider contributing to Ahoy Views. Please read this short overview for some information about how to get started:

Learn more about contributing to this repository,Code of Conduct

Contributors

Give the people some ❤️ who are working on this project. See them all at:

https://github.com/jonhue/ahoy-views/graphs/contributors

Semantic Versioning

Ahoy Views follows Semantic Versioning 2.0 as defined athttp://semver.org.

License

MIT License

Copyright (c) 2018 Jonas Hübotter

Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.

About

Track views of ActiveRecord objects in Rails

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp