Custom facts are a client-side technology for extracting arbitrary information from the node during the execution of the agent run, and they may be utilized in Puppet manifests or templates, along with any other distributed facts. Facts are executed on the Puppet agent.
The best way to create and distribute a new custom fact is to place it in a module, in the facter subdirectory of the lib directory, and it will then be distributed to the agent machine via pluginsync.
This documentation page at https://puppet.com/docs/puppet/5.3/plugins_in_modules.html#adding-plug-ins-to-a-module shows you exactly where in a module to place your code, and the section at https://puppet.com/docs/puppet/5.3/plugins_in_modules.html#installing-plug-ins, in the same documentation, shows the technical details for pluginsync.
The following diagram illustrates the pluginsync...