I know I can extract that info and use it for example in notification message.
I am looking for something else: a history of clicks. How could I build a trace/history of clicks? Best case scenario would be similar to Zigbee buttons that have history of clicks.
You could log using logbook.log or set up a syslog server and log to that. But you need to set it up per entity. I do not know how to log everything of everything. You could look at events Home Assistant emits, but I believe you are not supposed to listen using a wildcard on everything.
With this approach I upload a name of person that triggered this script (which I only use with this button) and now I know who called a specific action or set of actions.
Thanks @Edwin_D. When I was responding to your last comment I got a spark of an idea
Why not use the logbook.log action that I mentioned before? Then you do not need to create a helper and you can log any text you need. You can use any information from the trigger variable (such as the entity id) or the context to create whatever message you like.