9

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?

Alexandru Pufan
  • 1,842
  • 3
  • 26
  • 44
  • 4
    The only way would be Firebase Dynamic links to achieve this I would say. But the links have to be created somewhere (manually or in code). Take a look at https://firebase.google.com/docs/dynamic-links/. The Ionic plugin for this is still in beta though: https://ionicframework.com/docs/native/firebase-dynamic-links/ – Alex Aug 20 '18 at 18:28
  • https://developer.android.com/training/app-links/ this might be what you are looking for. – user1496463 Aug 26 '18 at 11:06
  • @Alex is this query resolved? take advantage of losing your points :) – nkshio Aug 27 '18 at 01:15

5 Answers5

2

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;
ldrrp
  • 666
  • 1
  • 7
  • 24
2

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);
});
Grant
  • 5,709
  • 2
  • 38
  • 50
2

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!

nkshio
  • 1,060
  • 1
  • 14
  • 23
  • But how can I get the installation link inside the app? – Alexandru Pufan Aug 27 '18 at 08:06
  • unfortunately, there is no way (as of yet) to get the link from the app stores, as mentioned above you will have to maintain & send this link from your own server – nkshio Aug 27 '18 at 11:21
  • This method assumes account is the first parameter. You should use a key based function to get the account. If playstore adds other parameters like language= then your array keys will be off. – ldrrp Aug 31 '18 at 17:47
1

The only way would be Firebase Dynamic links to achieve this (as stated in my comment earlier).

Dynamic links can survive the app installation process. And because of that, you can use the parameters. But the links have to be created somewhere (manually or in code).

Take a look at https://firebase.google.com/docs/dynamic-links/. The Ionic plugin for this is still in beta though: https://ionicframework.com/docs/native/firebase-dynamic-links/

Alex
  • 1,650
  • 16
  • 15
  • Hi Alex, thank u.. Could u place how to do so. I knew how to subscribe, but do I need to create the link on firebase console? Then how to send the dynamic link? – Galilo Galilo Apr 08 '20 at 05:36
1

I finally managed to make it work using Firebase Dynamic Links.

After I've setup my app in the Firebase console, I manually created a link which looks like this:

https://myapp.page.link/?link=https://play.google.com/store/apps/details?id=com.ionicframework.myapp?account4

In my Ionic app, I've installed and configured Firebase Dynamic Links plugin: https://ionicframework.com/docs/native/firebase-dynamic-links/

Then, inside app.component.ts, after the platform is initialized, I use this code:

firebaseDynamicLinks.onDynamicLink().subscribe((res: any) => {
 let link = res;
}, err => {
  alert(err);
});

The link will be a JavaScript object that looks like this:

{"deepLink":"https://play.google.com/store/apps/details?id=com.ionicframework.couriermanagerclient1234?account4","clickTimestamp":1535449992657,"minimumAppVersion":0}

From here, I can parse the result and extract the account parameter from inside the deepLink property

Alexandru Pufan
  • 1,842
  • 3
  • 26
  • 44