I want to count the number of user visiting a link in my website(http://productchaseapp.herokuapp.com/). Specificly, I want to know the click number of the product.url (user visiting the external url of a product).
This is how the link works:
link_to product.name, product.url, target: '_blank'
The problem is that, by doing this, there is no way that I can actually update the clickCount of the product, after all, after user clicks the link, they are outside of my website.
I think one solution, is to change the 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, and what are other good ways of doing this.
Try https://ankane.github.io/ahoy/
Ahoy provides a solid foundation to track visits and events in Ruby, JavaScript, and native apps.
Works with any data store so you can easily scale.
For example, you can do:
ahoy.trackClicks();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With