I have integrated Ahoy into our platform and it works great for tracking events etc. I am now trying to extend the functionality with enabling geocoding. The issue I am running into is as soon as I uncomment the
after_validation :geocode
line, visits stop recording in the database.
What am I doing wrong here?
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 (note the short visit duration for testing):
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
)
To re-iterate, when I comment out the geocoding line visits are recorded properly and ahoy works as expected. Thanks.
EDIT I am certain there is an exception being thrown but it is not bubbling up in the logs and I have debug logging enabled. Ahoy just states that "[ahoy] Event excluded since visit not created:" yet on the UI we can see that a visit is being started via these log statements from ahoy:
Visit started
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}