Warm tip: This article is reproduced from serverfault.com, please click

Track acquisition channels for 302 redirects (/app) to app stores

发布于 2021-01-02 12:24:17

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:

  • change unblnd.com/sitemap.xml
  • do not use redirect, just go the mainpage
  • use google tag manager
  • some third party

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('/');
    }
Questioner
Adriaan De Bolle
Viewed
0
Adriaan De Bolle 2021-01-03 21:13:31

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;
    }