0

Can anybody please help me how to create a event into ahoy_gem and how the visits will be tracked. I already follow the documentation provided by the gem developer, but it can't help me how to properly use it. Please help me.

Aman
  • 3
  • 6

1 Answers1

0

Firstly check if it track visits, head to rails console and run Visit.any? if it returns true then it is tracking the visits!

If it doesn't track visits, you can add the code below to application_controller.rb:

after_action :ahoy_track

protected

def ahoy_track
  ahoy.track_visit
end

now it will track the visits.

In order to track events you have 2 options:

  1. track events in the server side.
  2. track events in the client side using js.

to track in the server side you should use the:

ahoy.track "Event name", properties: { one: "val", two: "val" }

This will create a record in the db with event named "Event name" with the properties one: "val", two: "val"

to track events in the client side using js:

ahoy.track("Event name", {one: "val"});
  • tracking in js won't create records in the db, but A POST request is sent to /ahoy/events with (from the documentation) and you will need to handle it there.

another thing: if you want to check events you can access them as Ahoy::Event or from a visit: visit.ahoy_events

Ziv Galili
  • 1,405
  • 16
  • 20
  • Can you provide a link to the documentation? I cannot seem to find anything except the github page which makes no mention of a post request...nor do I see one outgoing in the network pane of dev tools – gwnp Aug 01 '20 at 18:31
  • Hi, i actually don't remember where i found this in the docs ( its 4 years old :D ), but maybe you can try it yourself, just add the `ahoy.track` function to your js file, and then see what happens... – Ziv Galili Aug 03 '20 at 17:29