If you want to detect opening by PWA you could try this code in javascript that tries to detect if the site was opened in standalone mode.
function isRunningStandalone() {
return (window.matchMedia('(display-mode: standalone)').matches);
}
...
if (isRunningStandalone()) {
/* código que sera executado se o site estiver em modo standalone */
}
There are other techniques, check if you can solve the problem with the code that I passed or take a look at this material.
PWA detect
In addition there is still a page in the google documentation to try to solve the problem you can check here Google PWA detect