you need user model that will have many visits
putting the line below in the desired view will track visit for this view and create new Visit object record
ahoy.track("Viewed book", {title: "The World is Flat"});
if you want to track event easily, just use ajax call to create event
function sendTracker(vars) {
$.ajax({
url: "/ahoy/events",
dataType: "json",
type: "post",
async:false,
data: {
name: vars[0],
properties: vars[1],
time: timeNow,
visit_id: <%= current_visit.nil? ? 0 : current_visit.id %>
},
success:function(){
}
});
this will create Ahoy::Event object with the parameters you choose
Finally, I needed to track with Ahoy AND to track event for ab testing (vanity). In this case I used intermediate technic
in the view
<%= link_to "#{ab_test(:campaign_1_cta)}",{:controller => :campaigns, :action => :rich_link, :url => "http://url.to/redirect", :name => "cp1_cta", :props => "data", :abtest => ":cp1_click"} %>
and my campaigns controller
def rich_link
ahoy.track(params[:name], params[:props])
var = params[:abtest].parameterize.underscore.to_sym
Vanity.track!(var)
redirect_to params[:url]
end