content_signals 0.1.2 → 0.1.4
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/lib/content_signals/geoip/maxmind_provider.rb +1 -1
- data/lib/content_signals/jobs/track_page_view_job.rb +9 -6
- data/lib/content_signals/jobs/update_geoip_database_job.rb +1 -1
- data/lib/content_signals/services/page_view_tracker.rb +4 -2
- data/lib/content_signals/version.rb +1 -1
- data/lib/generators/content_signals/templates/content_signals.rb.erb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d18a288c4e90ba7ebfe5d5e215d8943fbd701fc97ac1e674d215af65e1594b42
|
|
4
|
+
data.tar.gz: '048f0b39f39390439d262ee0fe71954fca6c9c1795b4f37943aa212bac7caf68'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e1026652e3f2707ca157f141188bccbaf6493e2ea648e1ddee4d132bca17bad20cf2d58cd01288d67713fd95532a647f163c04405caaf6ceed0c6e5cd1802e8d
|
|
7
|
+
data.tar.gz: 85ce20acf9f36205215f71eddee8a2361b5af4ac34c63f289fa1c320cacaff8e29aad2da029b06fb2a80fee962e256a05a541bab874cc32f6e93929649a24995
|
|
@@ -4,7 +4,7 @@ module ContentSignals
|
|
|
4
4
|
module Geoip
|
|
5
5
|
# Offline geolocation using a local MaxMind GeoLite2-City .mmdb file.
|
|
6
6
|
# Requires the maxminddb gem.
|
|
7
|
-
# Download/update the database: bundle exec rake
|
|
7
|
+
# Download/update the database: bundle exec rake stejar:geoip:update
|
|
8
8
|
class MaxmindProvider < BaseProvider
|
|
9
9
|
def self.locate(ip_address)
|
|
10
10
|
return nil if ip_address.blank? || local_ip?(ip_address)
|
|
@@ -9,6 +9,9 @@ module ContentSignals
|
|
|
9
9
|
discard_on ActiveRecord::RecordInvalid
|
|
10
10
|
|
|
11
11
|
def perform(trackable_type, trackable_id, user_id, tracking_data)
|
|
12
|
+
ip = tracking_data["ip_address"] || tracking_data[:ip_address]
|
|
13
|
+
location_data = ContentSignals::VisitorLocationService.locate(ip) || {}
|
|
14
|
+
|
|
12
15
|
PageView.create!(
|
|
13
16
|
tenant_id: tracking_data['tenant_id'] || tracking_data[:tenant_id],
|
|
14
17
|
trackable_type: trackable_type,
|
|
@@ -18,12 +21,12 @@ module ContentSignals
|
|
|
18
21
|
ip_address: tracking_data['ip_address'] || tracking_data[:ip_address],
|
|
19
22
|
user_agent: tracking_data['user_agent'] || tracking_data[:user_agent],
|
|
20
23
|
referrer: tracking_data['referrer'] || tracking_data[:referrer],
|
|
21
|
-
country_code:
|
|
22
|
-
country_name:
|
|
23
|
-
city:
|
|
24
|
-
region:
|
|
25
|
-
latitude:
|
|
26
|
-
longitude:
|
|
24
|
+
country_code: location_data[:country_code],
|
|
25
|
+
country_name: location_data[:country_name],
|
|
26
|
+
city: location_data[:city],
|
|
27
|
+
region: location_data[:region],
|
|
28
|
+
latitude: location_data[:latitude],
|
|
29
|
+
longitude: location_data[:longitude],
|
|
27
30
|
locale: tracking_data['locale'] || tracking_data[:locale],
|
|
28
31
|
device_type: tracking_data['device_type'] || tracking_data[:device_type],
|
|
29
32
|
browser: tracking_data['browser'] || tracking_data[:browser],
|
|
@@ -4,7 +4,7 @@ module ContentSignals
|
|
|
4
4
|
# Downloads/refreshes the MaxMind GeoLite2-City database from the public mirror.
|
|
5
5
|
# Only runs when geoip_provider is :maxmind and maxmind_db_path is configured.
|
|
6
6
|
# Schedule via config/recurring.yml (added by `rails generate content_signals:install`).
|
|
7
|
-
class UpdateGeoipDatabaseJob <
|
|
7
|
+
class UpdateGeoipDatabaseJob < ActiveJob::Base
|
|
8
8
|
queue_as :default
|
|
9
9
|
|
|
10
10
|
MIRROR_URL = "https://github.com/P3TERX/GeoLite.mmdb/raw/download/GeoLite2-City.mmdb"
|
|
@@ -86,7 +86,9 @@ module ContentSignals
|
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
def compile_tracking_data
|
|
89
|
-
|
|
89
|
+
# Note: IP geolocation (MaxMind/IPinfo) is intentionally NOT resolved here.
|
|
90
|
+
# It happens in TrackPageViewJob so the web request stays fast and the DB
|
|
91
|
+
# file is only needed on the worker, not on every web server.
|
|
90
92
|
app_context = detect_app_context
|
|
91
93
|
device_data = ContentSignals::DeviceDetectorService.detect(
|
|
92
94
|
@request.user_agent,
|
|
@@ -104,7 +106,7 @@ module ContentSignals
|
|
|
104
106
|
app_platform: app_context[:app_platform],
|
|
105
107
|
app_version: app_context[:app_version],
|
|
106
108
|
device_id: app_context[:device_id]
|
|
107
|
-
}.merge(
|
|
109
|
+
}.merge(device_data)
|
|
108
110
|
end
|
|
109
111
|
|
|
110
112
|
def detect_app_context
|
|
@@ -18,7 +18,7 @@ ContentSignals.configure do |config|
|
|
|
18
18
|
config.geoip_provider = :maxmind
|
|
19
19
|
|
|
20
20
|
# MaxMind GeoLite2 database path (used when geoip_provider = :maxmind)
|
|
21
|
-
# Initial download: bundle exec rake
|
|
21
|
+
# Initial download: bundle exec rake stejar:geoip:update (or run the job manually)
|
|
22
22
|
# Auto-updated weekly via ContentSignals::UpdateGeoipDatabaseJob (see config/recurring.yml)
|
|
23
23
|
config.maxmind_db_path = Rails.root.join("db", "GeoLite2-City.mmdb")
|
|
24
24
|
|