0

I'm trying to track views, clicks of listings in ecommerce store made in rails. I need to add a column in events table which has data of listing such as listing_id, name(listings).every listing has unique track data(no of visits,click track). Tried js way like this

document.addEventListener("turbolinks:load",function(){
document.querySelector("#BUYNOW").addEventListener("click",function(e){
ahoy.track("BUY IT NOW",e.target.dataset);
 });
});

this is the button I'm trying to track

<%= link_to "BUY IT NOW", new_listing_order_path(@listing), class: "btn btn-primary"%> |

ahoy events db shows --id,user_id,name,properties,time

I need to add a column stating the listing id

rocky
  • 45
  • 8

1 Answers1

0

It doesn't look like your queryselector is actually targeting that particular button. You'll likely need to add the id:

<%= link_to "BUY IT NOW", new_listing_order_path(@listing), class: "btn btn-primary", id: "BUYNOW" %> |
Yaakov Bressler
  • 9,056
  • 2
  • 45
  • 69
willrbot
  • 1
  • 2