Zend certified PHP/Magento developer

How to track from which category a user comes from ? Magento 2.3

Let’s say I have a product in category A and B.

On the product page, is there a way to know if the user clicked on the product from the category A or B (or came directly with product URL from outside link) ?

It would be useful to display some products from the same category the user clicked on and not the other category!
For now, I’m able to get the first category by number ID but not necessarily the good one !