我已将 Ahoy 集成到我们的平台中,它非常适合跟踪事件等。我现在正在尝试通过启用地理编码来扩展功能。我遇到的问题是,一旦我取消注释
after_validation :geocode
行,访问停止记录在数据库中。
我在这里做错了什么?
访问.rb
class Ahoy::Visit < ActiveRecord::Base
self.table_name = "ahoy_visits"
# ahoy_visit
geocoded_by :ip
# after_validation :geocode
has_many :events, class_name: "Ahoy::Event"
belongs_to :user
end
ahoy.rb (注意测试的短暂访问时间):
class Ahoy::Store < Ahoy::DatabaseStore
end
# set to true for JavaScript tracking
Ahoy.api = true
# better user agent parsing
Ahoy.user_agent_parser = :device_detector
Ahoy.geocode = true
# Ahoy.server_side_visits = :when_needed
Ahoy.visit_duration = 10.seconds
# Ahoy.visit_duration = Rails.application.secrets.visit_duration
Ahoy.quiet = false
地理编码器.rb
Geocoder.configure(
# Geocoding options
timeout: 15, # geocoding service timeout (secs)
lookup: :google, # name of geocoding service (symbol)
:ip_lookup => :maxmind, # IP address geocoding service (see below for supported options):
language: :en, # ISO-639 language code
use_https: true, # use HTTPS for lookup requests? (if supported)
# http_proxy: nil, # HTTP proxy server (user:pass@host:port)
# https_proxy: nil, # HTTPS proxy server (user:pass@host:port)
api_key: Rails.application.secrets.google_server_api_key, # API key for geocoding service
# cache: nil, # cache object (must respond to #[], #[]=, and #keys)
# cache_prefix: 'geocoder:', # prefix (string) to use for all cache keys
# Exceptions that should not be rescued by default
# (if you want to implement custom error handling);
# supports SocketError and Timeout::Error
# always_raise: [],
# Calculation options
units: :km, # :km for kilometers or :mi for miles
# distances: :linear # :spherical or :linear
)
重申一下,当我注释掉地理编码行访问时,会正确记录并且 ahoy 按预期工作。谢谢。
编辑 我确定有一个异常被抛出,但它没有在日志中冒泡,并且我启用了调试日志记录。Ahoy 只是声明“[ahoy] Event 由于访问未创建而被排除:”但在 UI 上我们可以看到访问正在通过来自 ahoy 的这些日志语句开始:
访问开始
ahoy.self-01ef77de70801670c1f7f2f12fea979d59ba70488a77db75270b57ec5b1a2f8e.js?body=1:175 {visit_token: "4c7e0bcb-7afb-48cd-91ed-1bdf0d614767", visitor_token: "374bf981-d843-45c3-953d-0f0b8fd5a6a7", platform: "Web", landing_page: " http://localhost:3000/ ", screen_width: 1680, ...}
ahoy.self-01ef77de70801670c1f7f2f12fea979d59ba70488a77db75270b57ec5b1a2f8e.js?body=1:175 {name: "$click", properties: {…}, time: 1533656941.084, id: "c967b67f-96f7-4f18-a9a8-df3735fdc1c2", js: true}