For first-party analytics, we use the ahoy.js
library, which tracks visits and events. This library works in conjunction with the ahoy_matey
gem, which is documented in our backend tracking guide.
The configuration for ahoy.js
lives in app/assets/javascripts/base.js.erb
. Since we do not track user cookies on the backend, we have configured ahoy.js
's defaults to match that on the frontend.
In order to track an event, use the ahoy.track
function:
1
ahoy.track(name, properties);
This function will send a POST
request to the /ahoy/events
endpoint on our backend with the name
and properties
of the event. The backend endpoint will also create a corresponding Ahoy::Visit
for the event if one does not exist already.