G. K.
G. K.

Reputation: 29

Deep linking - If opening URL on mobile should redirect to app or if opening on desktop should redirect to specified URL

I'm sharing image on Facebook, Twitter, Pinterest. I've landing page URL on click of that shared image. If user opening this URL in mobile, he/she should redirect to our mobile app or if opening URL in desktop should redirect to specific URL. I've searched for it, but not understanding what should I do for it. Please help!

Thank you!

Upvotes: 1

Views: 1602

Answers (1)

meshin
meshin

Reputation: 478

Recommend using Browser gem for detecting mobile: https://github.com/fnando/browser

All links from social media should be the same and point to same controller action. Then in your controller you can do something like this

# require the browser/aliases and extend the Browser::Base object
require "browser/aliases"
Browser::Base.include(Browser::Aliases)

# action
def social_link
  browser = Browser.new(request.user_agent)
  if browser.mobile?
    redirect_to 'MOBILE URL'
  else
    redirect_to 'DESKTOP URL'
  end
end

Upvotes: 1

Related Questions