Step 2: Create a browser view pointing to the class
In src/my.product/my/product/browser/configure.zcml, I added a browser view pointing to GlobalJS, gave it a name, and added a permission. Note that the name of the file containing GlobalJS is CommonUtils.py
<browser:view for="*" name="global_js.js" class=".CommonUtils.GlobalJS" permission="zope2.View" />
Here, I register the browser view in src/my.product/my/product/profiles/default/jsregistry.xml. I needed access to portal_url before jquery was loaded, so I added the insert-before property. Note that the id is the same as the name registered in the browser view.
Hope this helps someone.