没有使用after_validation创建的Ahoy访问:geocode未注释

时间:2018-08-07 15:48:15

标签: ruby-on-rails ruby-on-rails-4 ahoy

我已经将Ahoy集成到我们的平台中,并且非常适合跟踪事件等。我现在正尝试通过启用地理编码来扩展功能。我碰到的问题是我取消注释

after_validation :geocode

行,访问停止在数据库中记录。

我在这里做什么错了?

visit.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

geocoder.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]由于未创建访问而排除了事件:”,但在UI上,我们可以通过ahoy的以下日志语句看到访问正在开始:

  

访问开始

     

ahoy.self-01ef77de70801670c1f7f2f12fea979d59ba70488a77db75270b57ec5b1a2f8e.js?body = 1:175   {visit_token:“ 4c7e0bcb-7afb-48cd-91ed-1bdf0d614767”,visitor_token:   “ 374bf981-d843-45c3-953d-0f0b8fd5a6a7”,平台:“ Web”,登陆页面:   “ http://localhost:3000/”,screen_width:1680,...}

     

ahoy.self-01ef77de70801670c1f7f2f12fea979d59ba70488a77db75270b57ec5b1a2f8e.js?body = 1:175   {name:“ $ click”,属性:{…},时间:1533656941.084,id:   “ c967b67f-96f7-4f18-a9a8-df3735fdc1c2”,js:true}

0 个答案:

没有答案