App Store redirect

We have an app-based service with apps published to Apple AppStore and Google PlayStore and would like users from Android or iOS devices to be redirected directly to their app store instead of being shown the generic Download page.
Currently we are using onelink to to accomplish this, but for several reasons we would like a solution native to Wix and our domain.

I have made some progress but getting stuck and looking for help.

import wixLocation from ‘wix-location’;

$w.onReady( function () {
// Write your JavaScript here

if (navigator.userAgent.toLowerCase().indexOf(“iphone”) > -1){ wixLocation.to(" h t t p s ://apps . apple . com/se/app/ourapp/id0000000");
}
if (navigator.userAgent.toLowerCase().indexOf(“android”) > -1){
wixLocation.to(" h t t p s ://play.google . c o m/store/apps/details?id=com . ourapp . app");
}

It seams I can not read userAgent successfully and I would like to see if anyone here could guide us before I abandon a Wix native solution and set up a custom external subdomain with the rather simple JS to enable this functionality.

https://www.wix.com/velo/forum/coding-with-velo/getting-useragent-and-user-ip-values