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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7388e4fede60244368fbc17faba350e4427c9a028a7c4482b526836bc0f9f5ac
4
- data.tar.gz: 14969ae023b16f9ca1a5db5922abddddf35444b860d2aa0c86211f9c6ebf695b
3
+ metadata.gz: d18a288c4e90ba7ebfe5d5e215d8943fbd701fc97ac1e674d215af65e1594b42
4
+ data.tar.gz: '048f0b39f39390439d262ee0fe71954fca6c9c1795b4f37943aa212bac7caf68'
5
5
  SHA512:
6
- metadata.gz: c020e32d9d0f675d11873f5933cef9b100944a9067df91956f05015eedb55b1a5ffe36a1f3337b3033093f0cabdd27547507eacdfc006d3abcbadddc7517152d
7
- data.tar.gz: 02ce4de9492392cf993858d3f1d0a6b8713c915766357580bbda9c512f96df65c08e580bd8d470b6f2e23e81e83a5b86dab55156ae8f50a5ca518ca8ebf1dbe3
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 app:stejar:geoip:update
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: tracking_data['country_code'] || tracking_data[:country_code],
22
- country_name: tracking_data['country_name'] || tracking_data[:country_name],
23
- city: tracking_data['city'] || tracking_data[:city],
24
- region: tracking_data['region'] || tracking_data[:region],
25
- latitude: tracking_data['latitude'] || tracking_data[:latitude],
26
- longitude: tracking_data['longitude'] || tracking_data[: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 < ApplicationJob
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
- location_data = ContentSignals::VisitorLocationService.locate(@request.ip) || {}
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(location_data).merge(device_data)
109
+ }.merge(device_data)
108
110
  end
109
111
 
110
112
  def detect_app_context
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ContentSignals
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.4"
5
5
  end
@@ -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 app:stejar:geoip:update (or run the job manually)
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: content_signals
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ionuț Munteanu Alexandru