Hi,
Firstly, I recommend reading the explanation here regarding the “page” and the “site” tabs of the code editor:
Moreover, I recommend creating a JS file in the public directory and import it. Code written in public files is shared by your site’s Backend, page code, and site code environments. Use public files to hold utility functions that can be called from multiple locations in your site’s code.
Tip:
Code that you add to the Site tab runs on every page in your site. This can impact your site’s performance so it’s important to consider if you need the code to run on every page. If you have code that needs to run on some, but not all pages you may want to put it in a Public file and import it as needed.