1

This applies both to Android and iOS. My web page may be sometimes opened by an app (you go to the app, and click a link there which opens the page). I want to know if the page was accessed through an app or if the user got to it, let's say, by typing the address on the browser. If accessed through an app, I don't need to know which app it was.

The only thing I know of is document.referrer, but it seems to return "" when the page has been opened by the app. Unfortunately using "" as an indicator is not possible, as other ways of getting to the page may also show "" (for example typing the address). The history object does not seem to contain the info I'm looking for either. I am using a Zendesk Help Center, so I only have access to the javascript of the page in order to detect this. I can't make changes on the server-side of my page.

Alternatively, I may be able to talk to the people in charge of the app so that they include something when the app opens the browser which would allow me to access that info on the browser, but I am not sure what that could be. Any ideas?

Thank you!

Polar
  • 124
  • 1
  • 10

1 Answers1

1

It seems to me like your best bet would be to have specific links for your site that will let you know that the link came from the app.

Like so: http://www.yoursite.com/?openedFromApp

You will use those links inside the app that will be directing users to your website.

That way, if you were using PHP as your server-side language you'd be able to check if the openedFromApp URL parameter was set like so:

<?php
if(isset($_GET['openedFromApp'])) {
    echo "The website was opened by an app";
}
else { echo "The website was opened normally"; }
?>

If you want to check if the openedFromApp URL parameter is set using Javascript you'd have to create your own function for accessing URL parameters as Javascript does not have a built-in way of accessing them.

But this link could help you access the URL parameters with Javascript: https://stackoverflow.com/questions/...

Community
  • 1
  • 1
Droid1001
  • 38
  • 8
  • This is actually a great idea that will help lots of people with the same problem! Unfortunately, in my case I do not have access to the server-side of my site, only to the js/html/css (I will add this to the question now). I can type mysite.com/?test, but that is opened by the browser as mysite.com, as I am not able to create that route. I wonder if there is a way to detect that the page was requested with a query string url even if the browser translated it to the regular url. – Polar Oct 17 '15 at 00:58
  • But do you have access to the app that sends users to your website? – Droid1001 Oct 17 '15 at 01:11
  • Because if you do have access to the app even just having access to the client-side you can use the solution I suggested above. – Droid1001 Oct 17 '15 at 01:16
  • I think it will work! I just had to do `mysite.com?test` instead of `mysite.com/?test`. – Polar Oct 20 '15 at 01:07