So, I actually was inspired by this question to do some more digging. I found out that the URL fetched by
RequestParameter('PageURL') differes, depending on whether the page is presented in the "Publish" context, or accessed through the proper URL, e.g. http://cloud.example.com/cloudpage
The URL in "publish" is internal and contains e.g. Preview part, e.g.:
Hence you can use following AmpScript to check for whether or not the Ampscript is executed in Publish or View context:
SET @isPreview = indexOf(lowercase(RequestParameter('PageURL')), "preview")
URL is %%=RequestParameter('PageURL')=%%
and context is: %%=IIF(@isPreview > 0,"Publish","View")=%%
This will help you prevent undesirable execution of the code, leading to strange records in data extensions. However in some cases this might not be sufficient, hence doing an additional check for e.g. form submission (like here: SFMC Cloudpage Execution Context is always load ) or presence of particular parameters with EMPTY() function, would be beneficial.