Rails: count the click number of a link?

I want to count the number of users visiting a link on my site ( http://productchaseapp.herokuapp.com/ ). Specifically, I want to know the click number product.url

(the user visits the external url

product). This is how the link works:

link_to product.name, product.url, target: '_blank'

      

The problem is that by doing this, I cannot really update clickCount

product

, because after the user clicks on the link, they are outside of my website.

I think one solution is to change the link to

link_to product.name, product_path(product), target: '_blank'

      

And in ProductsController#Show

update the attribute and redirect the user outside of the website to product.url

.

I'm not sure if this is a good solution, or what other good ways to do this.

+3


source to share


2 answers


Try https://ankane.github.io/ahoy/

Ahoy provides a solid foundation for tracking visits and events in Ruby, JavaScript, and native applications.

Works with any data store so you can scale easily.



For example, you can:

ahoy.trackClicks();

      

+3


source


One way to deal with this is to override the click

corresponding link's event to fire PUT

back to your app's endpoint that tracks link clicks and then redirects to the external URL.



0


source







All Articles