I have a function that retrieves a visiting user's country name by doing an ip lookup. I currently have this function running through the execute method in my module's controller. The problem is that I need this to run on every page and not just the single controller page.
Since every controller is tied to a particular action I am not sure if keeping it in a controller is the correct solution, nor do I know how to run my controller on every page request.
Does anybody know how to do this?
Best Answer
Per Robbie's suggestion I created:
etc/events.xml
Then created observer class
From here I injected the required classes for my function and was able to get everything working. Thanks for pointing me in the right direction.