2

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

Eali
  • 29
  • 6
  • I'm having this same issue. I'm trying to create a number of events in `seeds.rb` without any luck - I'm stuck on the event failing to save due to the visit missing. Any chance you found a working solution? – krsyoung Jul 17 '18 at 17:14

2 Answers2

0

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

Drew
  • 2,583
  • 5
  • 36
  • 54
0

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
)
Tim Krins
  • 3,134
  • 1
  • 23
  • 25