Search code examples
htmlhttp-redirectbrowser-detection

Redirecting users to different external links based on browser type


My extension / add-on is live on multiple browser stores but if I want to direct someone to the extension, I have to provide them 4 different links (for e.g. shown here - http://credizian.gitlab.io/untrackme or in an email, as a list).

I'm trying to figure out how I can create one URL that will auto-redirect user to the relevant browser extension store - aka better user experience.

The process I've thought of is - creating a page that has javascript built-in to redirect users based on browser detection logic. I am thinking to host it in S3 and just put basic javascript only with a blank page for fastest redirect. Is that the best way?

Do browsers flag this from of redirect since it's going to external URLs? I see email links constantly opening a page and multiple redirects happening before the final page loading...not sure if they are doing something to not be considered spam

I've looked at other answers but they are focused on redirection to 'internal pages'


Solution

  • User agents for specified browsers will look like:

    Mozilla - Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1
    
    Chrome - Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.9 Safari/537.36
    
    Opera - Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.52
    
    Safari - Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27
    
    
    browser_dict = {'Safari': "safari url here",'OPR':"opera url here",'Chrome':"chrome url here", 'Firefox':"firefox url here"}
    

    What you can do is to split user-agent with space: Here is the pseudo code I am writing:

    useragent = user-agent.split(' ') //useragent will be list
    
    

    again splitting last and last second item of above list using '/':

    useragent-last = useragent[-1].split('/')
    useragent-lastsecond= useragent[-2].split('/')
    

    now checking if useragent-last or useragent-lastsecond present in browser dictionary

    for key, value in browser_dict.items():
        if useragent-last == key:
            go to url browser_dict[key] //url
        elif useragent-lastsecond == key:
            go to url browser_dict[key] //url
        else: 
              print (No known browser detected.)    
    

    This might help you.