2

I want to track the visit clicking my links.

I need to know the percentage of browser, OS... of every link.

Does it mean I should add that in link.rb ?

class Link < ActiveRecord::Base
    has_many :visits 
end

But after clicking links lots of times, the links' visits aren't generated.

I really don't know how Ahoy's visit work, when to create a new visit.

orde
  • 5,233
  • 6
  • 31
  • 33
dalai
  • 51
  • 5

1 Answers1

0

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
ruby ninja
  • 36
  • 5