We created a smart link unblnd.com/app
This link detects the device: desktop, iphone, or android. Depending on the device it goes to the main page or the specific app store.
The link is a 302 redirect which is not indexed.
Goal: Include the /app redirect route within google analytics and track the acquisition channels
Ideas:
Is there some clean, easy approach which is considered best practice?
More info:
To create the redirect we use this Laravel controller method
routes/web.php
Route::get('/app', 'LandingController@app');
LandingController
public function app(Request $request)
{
if (!Agent::isMobile()) {
return redirect('/');
}
else if(Agent::isAndroidOS()) {
return Redirect::away(config('app.android_url'));
}
else if (Agent::isIphone()) {
return Redirect::away(config('app.apple_url'));
}
return redirect('/');
}
Okay, I believe we found a good answer!
We changed the controller method to always redirect to the main page, but with a query string param:
public function app(Request $request)
{
if (!Agent::isMobile()) {
return redirect('/?app=desktop');
}
else if(Agent::isAndroidOS()) {
return redirect('/?app=android');
}
else if (Agent::isIphone()) {
return redirect('/?app=iphone');
}
return redirect('/?app=desktop');
}
When the main view in mounted in the browser it checks the query params and redirects if necessary:
let app_url = false;
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.get('app') && urlParams.get('app') === 'android') app_url = "{{config('app.android_url')}}";
if (urlParams.get('app') && urlParams.get('app') === 'iphone') app_url = "{{config('app.apple_url')}}";
if (app_url) {
window.location.href = app_url;
}