I'm opening my page inside a Trusted Web Activity and I want to detect when it's being opened inside it to customize behaviour and for analytics purposes. How can I detect that the page is being opened from the TWA?
I'm opening my page inside a Trusted Web Activity and I want to detect when it's being opened inside it to customize behaviour and for analytics purposes. How can I detect that the page is being opened from the TWA?
As andreban stated I used:
which returns true if it comes from TWA.
There are three options that will help detecting if the page is being opened from inside a TWA:
When opening the page, the Referral will be
android-app://<twa.package.name>
, where twa.package.name is the package name used on the Android side of the TWA.Adding an URL parameter. Append a query string to the end of the URL that is launched with the PWA.
Using Request-Headers. When creating the TWA Intent, add a Bundle containing the key/values for the a request header: