Is there any way to execute some JS code when the "Create new Issue dialog" is triggered?

There seem to be two ways of creating an issue, when opening the “Create issue” modal window, or when you end up on the dedicated “create issue” page. I need to track this event, and run some code when the create issue is initiated. Is there any way to do this? Can be wither way (client side in JS, or sever side in Java plugin)

There is server side event for issue creation which happens afterwards.
Why would you want a pre-issue-create event? What are you trying to achieve?

I’ve developed a custom plugin to be used internally within the company and we want to be able to to track some data to see how many users after initiating a “Create Issue” dialog proceed with creating the issue and how many close that dialog/page and don’t proceed with creating the issue.

My initial idea was to track how many times the create dialog has been opened vs how many issues have been created.

There is very likely existing analytics events that you can use to get this data.
Try going to <jira>/plugins/servlet/event/report

See if you have this plugin, if yes try open/closing issue dialogues and see what events are being captured

Try to use Mozilla. F12 -> Inspector -> click on “Create” button

You will see the events which linked to this button:

hope it helps)