我们创建了一个智能链接unblnd.com/app
此链接检测设备:桌面、iphone或android。根据设备的不同,它会进入主页面或特定的应用程序商店。
链接是没有索引的302重定向。
目标:在google分析中包括/app重定向路径,并跟踪收购渠道
想法:
是否有一些干净、简单的方法被认为是最佳实践?
更多信息:
为了创建重定向,我们使用了这个Laravel控制器方法
路由/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('/');
}发布于 2021-01-03 13:13:31
好吧,我相信我们找到了一个很好的答案!
我们将控制器方法更改为始终重定向到主页面,但使用的是查询字符串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');
}当在浏览器中挂载的主视图时,它检查查询参数并在必要时重定向:
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;
}https://stackoverflow.com/questions/65539052
复制相似问题