我想为Ahoy Analytics Gem创建一些种子数据以进行演示
我将如何模拟页面访问,同时更改数据库中记录的日期以模拟过去的访问者数据?
感谢任何帮助谢谢
可以部分模拟水豚,也可以改变水豚例程中的值
我手动创建了我的Ahoy::Visits
和。Ahoy::Events
# 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
)