strongmind-pageviews 0.2.3 → 0.2.5
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 +4 -4
- data/Rakefile +6 -0
- data/app/controllers/pageviews_controller.rb +66 -0
- data/lib/generators/pageviews/pageviews_generator.rb +6 -2
- data/lib/generators/pageviews/templates/pageview.rb +8 -0
- data/lib/pageviews/version.rb +1 -1
- metadata +32 -18
- data/LICENSE +0 -21
- data/bin/console +0 -14
- data/bin/setup +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29b39fe3c330afcf296b212e981261f7705092079dac9defe83726d9bed36b39
|
4
|
+
data.tar.gz: 5f42c34fcc5c5d1edc44f596b244093d0c5c97b632d38a0163431af41ac7847a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 514d0906f83eb8458a7e1767cd3139d596bcf4f9d916ca10324dfcbb5d8a81a3e72240bbedec99e9359ee7bb705d0bc8002548b127bc7ad6b359e6727cd957f4
|
7
|
+
data.tar.gz: 791ba4d0ea41f8ea45081e20184f2ccad580067e17a8d887e610e149df7c17d8d3c739a606ca1999f5778d5a7d3eccc6dc71d2e51cf19b11120372c3dae52fa7
|
data/Rakefile
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
module PageviewsController
|
2
|
+
module ClassMethods
|
3
|
+
def track_views(opts = {})
|
4
|
+
before_action { |c| c.track_views_filter(opts[:actions], opts[:unique]) }
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
module InstanceMethods
|
9
|
+
def track_views_filter(actions = nil, unique_opts = nil)
|
10
|
+
return if bypass_tracking?
|
11
|
+
|
12
|
+
actions = Array(actions).map(&:to_s)
|
13
|
+
if (actions.blank? || actions.include?(action_name)) && unique?(unique_opts)
|
14
|
+
Pageview.create(create_pageview_params)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def bypass_tracking?
|
21
|
+
bot_user_agent?(request.user_agent)
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_pageview_params
|
25
|
+
{
|
26
|
+
pageview_type: controller_name.singularize.camelize,
|
27
|
+
pageview_id: params[:id],
|
28
|
+
controller_name: controller_name,
|
29
|
+
action_name: action_name,
|
30
|
+
user_id: current_user_id,
|
31
|
+
session_hash: request.session.id,
|
32
|
+
ip_address: request.remote_ip,
|
33
|
+
params: filtered_params,
|
34
|
+
referrer: request.referer
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def filtered_params
|
39
|
+
params.except(:controller, :action, :id).permit!.to_h
|
40
|
+
end
|
41
|
+
|
42
|
+
def current_user_id
|
43
|
+
current_user&.id
|
44
|
+
end
|
45
|
+
|
46
|
+
def unique?(unique_opts)
|
47
|
+
return true if unique_opts.blank?
|
48
|
+
|
49
|
+
conditions = create_pageview_params.slice(*unique_opts)
|
50
|
+
!Pageview.exists?(conditions)
|
51
|
+
end
|
52
|
+
|
53
|
+
def bot_user_agent?(user_agent)
|
54
|
+
return false if user_agent.blank?
|
55
|
+
|
56
|
+
bot_patterns = [
|
57
|
+
/bot/i,
|
58
|
+
/crawler/i,
|
59
|
+
/spider/i,
|
60
|
+
/\b(Baidu|Gigabot|Googlebot|libwww-perl|lwp-trivial|msnbot|SiteUptime|Slurp|WordPress|ZIBB|ZyBorg|Yandex|Jyxobot|ApacheBench|YandexBot)\b/i
|
61
|
+
]
|
62
|
+
|
63
|
+
bot_patterns.any? { |pattern| user_agent =~ pattern }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -6,11 +6,15 @@ class PageviewsGenerator < Rails::Generators::Base
|
|
6
6
|
source_root File.join(File.dirname(__FILE__), 'templates')
|
7
7
|
|
8
8
|
def self.next_migration_number(_dirname)
|
9
|
-
Time.now.utc.strftime(
|
9
|
+
Time.now.utc.strftime('%Y%m%d%H%M%S')
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate_model
|
13
|
+
template 'pageview.rb', 'app/models/pageview.rb'
|
10
14
|
end
|
11
15
|
|
12
16
|
def create_migration_file
|
13
17
|
migration_template 'create_pageviews_table.rb', 'db/migrate/create_pageviews_table.rb'
|
14
18
|
end
|
15
19
|
end
|
16
|
-
# Compare this snippet from lib/pageviews/version.rb:
|
20
|
+
# Compare this snippet from lib/pageviews/version.rb:
|
data/lib/pageviews/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strongmind-pageviews
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- StrongMind
|
@@ -10,6 +10,34 @@ bindir: exe
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2024-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 8.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 8.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '8.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '8.0'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: bundler
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,20 +108,6 @@ dependencies:
|
|
80
108
|
- - "~>"
|
81
109
|
- !ruby/object:Gem::Version
|
82
110
|
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
111
|
description: Pageviews is a page views counting gem for Rails. Log views from Rails
|
98
112
|
controller actions.
|
99
113
|
email:
|
@@ -102,12 +116,12 @@ executables: []
|
|
102
116
|
extensions: []
|
103
117
|
extra_rdoc_files: []
|
104
118
|
files:
|
105
|
-
- LICENSE
|
106
119
|
- README.md
|
107
|
-
-
|
108
|
-
-
|
120
|
+
- Rakefile
|
121
|
+
- app/controllers/pageviews_controller.rb
|
109
122
|
- lib/generators/pageviews/pageviews_generator.rb
|
110
123
|
- lib/generators/pageviews/templates/create_pageviews_table.rb
|
124
|
+
- lib/generators/pageviews/templates/pageview.rb
|
111
125
|
- lib/pageviews.rb
|
112
126
|
- lib/pageviews/acts_as_pageviews.rb
|
113
127
|
- lib/pageviews/engine.rb
|
data/LICENSE
DELETED
@@ -1,21 +0,0 @@
|
|
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/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
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
|