Works only in preview mode

Why does code work only in preview mode? In a published site code doesn’t work (wixsite.com/…)

In most cases the reasons for this problem is one of the following issues:

  1. You forgot to sync the live collection with the sandbox

  2. The collection permissions are set to Admin Only.