strongmind-pageviews 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +89 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/generators/pageviews/pageviews_generator.rb +20 -0
- data/lib/generators/pageviews/templates/create_pageviews_table.rb +30 -0
- data/lib/pageviews/acts_as_pageviews.rb +21 -0
- data/lib/pageviews/engine.rb +15 -0
- data/lib/pageviews/version.rb +3 -0
- data/lib/pageviews.rb +10 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bc87f3d132f28d4832ee629573f7e9297be1de55450ea1c7d73d07c1b6aa71e3
|
4
|
+
data.tar.gz: 9e0c31fbb68ed70f6fada87f4f2c621182e2824a204fddae2b74c20dab5eef12
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c82279018abc6329e12301c11eaa10f9c4f83d6962203f0d082cc7d3cee0ab305fd64bdd16c98fe4c549b14c752132623a8784617536420d2d9ccc192e5508f3
|
7
|
+
data.tar.gz: fb3a0532a36ddd08eb814379665b76031b34843e612bd048b2a91cc022e115d5bda151cfbc4b9cc94c7fc9ae44656bd0483a746f71722039de122e46816ec449
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Bernard Banta
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# Pageviews
|
2
|
+
Pageviews is a lightweight ruby gem for tracking page views for rails application.
|
3
|
+
What about bots? They are ignored. 1200 known bots have been added to the ignore list as of
|
4
|
+
February 1, 2011. Impressionist uses this list: http://www.user-agents.org/allagents.xml
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'pageviews'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle install
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install pageviews
|
21
|
+
|
22
|
+
Generate the impressions table migration
|
23
|
+
|
24
|
+
rails g pageviews
|
25
|
+
|
26
|
+
Run the migration
|
27
|
+
|
28
|
+
rake db:migrate
|
29
|
+
|
30
|
+
The following fields will be generated in the migration:
|
31
|
+
|
32
|
+
t.string "pageview_type" # model type: Widget
|
33
|
+
t.integer "pageview_id" # model instance ID: @blog_post.id
|
34
|
+
t.integer "user_id" # automatically logs @current_user.id
|
35
|
+
t.string "controller_name" # logs the controller name
|
36
|
+
t.string "action_name" # logs the action_name
|
37
|
+
t.string "view_name" # TODO: log individual views (as well as partials and nested partials)
|
38
|
+
t.string "request_hash" # unique ID per request, in case you want to log multiple impressions and group them
|
39
|
+
t.string "session_hash" # logs the rails session
|
40
|
+
t.string "ip_address" # request.remote_ip
|
41
|
+
t.text "params" # request.params, except action name, controller name and resource id
|
42
|
+
t.string "referrer" # request.referer
|
43
|
+
t.datetime "created_at" # I am not sure what this is.... Any clue?
|
44
|
+
t.datetime "updated_at" # never seen this one before either.... Your guess is as good as mine?? ;-)
|
45
|
+
|
46
|
+
## Usage
|
47
|
+
|
48
|
+
|
49
|
+
1. Log all actions in a controller
|
50
|
+
|
51
|
+
class BlogPostController < ApplicationController
|
52
|
+
track_views
|
53
|
+
end
|
54
|
+
|
55
|
+
2. Specify actions you want logged in a controller
|
56
|
+
|
57
|
+
class BlogPostController < ApplicationController
|
58
|
+
track_views actions: [:show,:index]
|
59
|
+
end
|
60
|
+
|
61
|
+
3. Make use of the `:session_hash` to keep track of unique views only.
|
62
|
+
|
63
|
+
class BlogPostController < ApplicationController
|
64
|
+
track_views actions: [:show], unique: [:session_hash]
|
65
|
+
end
|
66
|
+
|
67
|
+
4. Add `acts_as_pageviews` in your model. This allows you to attach pageviews to
|
68
|
+
an Active Record model instance.
|
69
|
+
|
70
|
+
class BlogPost < ActiveRecord::Base
|
71
|
+
acts_as_pageviews
|
72
|
+
end
|
73
|
+
|
74
|
+
5. Get unique pageviews count from a model.
|
75
|
+
|
76
|
+
@blog_post.views
|
77
|
+
|
78
|
+
6. You can also specify pageviews count for specific actions.
|
79
|
+
|
80
|
+
@blog_post.views('show')
|
81
|
+
|
82
|
+
## Contributing
|
83
|
+
|
84
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Banta/pageviews. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
85
|
+
|
86
|
+
## License
|
87
|
+
|
88
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
89
|
+
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "pageviews"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
class PageviewsGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
source_root File.join(File.dirname(__FILE__), 'templates')
|
7
|
+
|
8
|
+
def self.next_migration_number(dirname)
|
9
|
+
sleep 1
|
10
|
+
if ActiveRecord::Base.timestamped_migrations
|
11
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
12
|
+
else
|
13
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_migration_file
|
18
|
+
migration_template 'create_pageviews_table.rb', 'db/migrate/create_pageviews_table.rb'
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class CreatePageviewsTable < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :pageviews, :force => true do |t|
|
4
|
+
t.string :pageview_type
|
5
|
+
t.integer :pageview_id
|
6
|
+
t.integer :user_id
|
7
|
+
t.string :controller_name
|
8
|
+
t.string :action_name
|
9
|
+
t.string :view_name
|
10
|
+
t.string :request_hash
|
11
|
+
t.string :ip_address
|
12
|
+
t.string :session_hash
|
13
|
+
t.text :referrer
|
14
|
+
t.text :params
|
15
|
+
t.timestamps
|
16
|
+
end
|
17
|
+
add_index :pageviews, [:pageview_type, :pageview_id, :request_hash], :name => "poly_request_index", :unique => false
|
18
|
+
add_index :pageviews, [:pageview_type, :pageview_id, :ip_address], :name => "poly_ip_index", :unique => false
|
19
|
+
add_index :pageviews, [:pageview_type, :pageview_id, :session_hash], :name => "poly_session_index", :unique => false
|
20
|
+
add_index :pageviews, [:controller_name,:action_name,:request_hash], :name => "controlleraction_request_index", :unique => false
|
21
|
+
add_index :pageviews, [:controller_name,:action_name,:ip_address], :name => "controlleraction_ip_index", :unique => false
|
22
|
+
add_index :pageviews, [:controller_name,:action_name,:session_hash], :name => "controlleraction_session_index", :unique => false
|
23
|
+
add_index :pageviews, [:pageview_type, :pageview_id, :params], :name => "poly_params_request_index", :unique => false
|
24
|
+
add_index :pageviews, :user_id
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.down
|
28
|
+
drop_table :pageviews
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Pageviews
|
2
|
+
module ActiveRecord
|
3
|
+
module InstanceMethods
|
4
|
+
def views(action=nil)
|
5
|
+
if action
|
6
|
+
pageviews.where(action_name: action).count
|
7
|
+
else
|
8
|
+
pageviews.count
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class ActiveRecord::Base
|
16
|
+
def self.acts_as_pageviews
|
17
|
+
include Pageviews::ActiveRecord::InstanceMethods
|
18
|
+
has_many :pageviews, as: :pageview, dependent: :destroy
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'pageviews'
|
2
|
+
require 'rails'
|
3
|
+
require 'active_record'
|
4
|
+
# require 'active_support'
|
5
|
+
|
6
|
+
module Pageviews
|
7
|
+
class Engine < Rails::Engine
|
8
|
+
initializer 'pageviews.controller' do
|
9
|
+
ActiveSupport.on_load(:action_controller) do
|
10
|
+
include PageviewsController::InstanceMethods
|
11
|
+
extend PageviewsController::ClassMethods
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/pageviews.rb
ADDED
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: strongmind-pageviews
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- StrongMind
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-12-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.60'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.60'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.22'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.22'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activerecord
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '8.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '8.0'
|
97
|
+
description: Pageviews is a page views counting gem for Rails. Log views from Rails
|
98
|
+
controller actions.
|
99
|
+
email:
|
100
|
+
- vendor@strongmind.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- LICENSE
|
106
|
+
- README.md
|
107
|
+
- bin/console
|
108
|
+
- bin/setup
|
109
|
+
- lib/generators/pageviews/pageviews_generator.rb
|
110
|
+
- lib/generators/pageviews/templates/create_pageviews_table.rb
|
111
|
+
- lib/pageviews.rb
|
112
|
+
- lib/pageviews/acts_as_pageviews.rb
|
113
|
+
- lib/pageviews/engine.rb
|
114
|
+
- lib/pageviews/version.rb
|
115
|
+
homepage: https://github.com/StrongMind/pageviews
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
metadata:
|
119
|
+
allowed_push_host: https://rubygems.org
|
120
|
+
homepage_uri: https://github.com/StrongMind/pageviews
|
121
|
+
source_code_uri: https://github.com/StrongMind/pageviews
|
122
|
+
changelog_uri: https://github.com/StrongMind/pageviews/CHANGELOG.md
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubygems_version: 3.4.19
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Easy way to log Rails page views
|
142
|
+
test_files: []
|