Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 3: Getting value from PlayStore link

I have an Ionic 3 app and I want to set some variable inside it based on the download link from Playstore. For example, http://linktoplaystore.com/app?account=4 would set the account variable inside my app to be 4. Is there any way to achieve this?

like image 884
Alexandru Pufan Avatar asked Aug 17 '18 10:08

Alexandru Pufan


3 Answers

You can do this in code by parsing and defining an array

private urlParameters: Array<any> = [];

if (YOURURLVARIABLE.indexOf("?") > 0) {
    let splitURL = document.URL.split("?");
    let splitParams = splitURL[1].split("&");
    let i: any;
    for (i in splitParams){
        let singleURLParam = splitParams[i].split('=');
        let urlParameter = {
        'name': singleURLParam[0],
        'value': singleURLParam[1]
    };
    this.urlParameters.push(urlParameter);
    }
}

this.urlParamID = navParams.get('account').value;
like image 173
ldrrp Avatar answered Nov 03 '22 23:11

ldrrp


I don't think it's possible from the Playstore, but from an external source of your own you could access in app functions via Deeplinks. See https://ionicframework.com/docs/native/deeplinks/ for more information.

this.deeplinks.route({
    '/account/:accountId': AccountPage
}).subscribe(match => {
    console.log(match.$args);
}, nomatch => {
    console.error('Got a deeplink that didn\'t match', nomatch);
});
like image 2
Grant Avatar answered Nov 03 '22 23:11

Grant


Parse link in JavaScript to get the required value

Code Snippet

var link = "http://linktoplaystore.com/app?account=4";
var variable = link.split('?')[1].split('=')[1];

Also, you should open an API to send this link from server, so you don't need to push app-update in case of any changes in the link.

Hope it helps!

like image 2
nkshio Avatar answered Nov 04 '22 00:11

nkshio