I want to create some seed data for Ahoy Analytics Gem for a demo
How would I simulate page visits but also alter the date recorded in the db to simulate past visitor data?
Any help is appreciated Thanks
I want to create some seed data for Ahoy Analytics Gem for a demo
How would I simulate page visits but also alter the date recorded in the db to simulate past visitor data?
Any help is appreciated Thanks
could simulate in part with capybara, and could also alter value in capybara routine
also, https://github.com/jnicklas/capybara/ in case that may be of interest
I created my Ahoy::Visits
and Ahoy::Events
manually.
# use the Faker gem for fake data
request = OpenStruct.new(
params: { },
referer: Faker::Internet.url,
remote_ip: Faker::Internet.public_ip_v4_address,
user_agent: Faker::Internet.user_agent,
original_url: Rails.application.routes.url_helpers.root_url,
)
visit_properties = Ahoy::VisitProperties.new(request, api: nil)
properties = visit_properties.generate.select { |_, v| v }
example_visit = Ahoy::Visit.create!(properties.merge(
visit_token: SecureRandom.uuid,
visitor_token: SecureRandom.uuid,
started_at: Time.current
))
example_event = Ahoy::Event.create!(
visit: example_visit,
name: 'example_event',
properties: 'example properties',
time: Time.current
)