Preview 2.0 is now in Public Beta!
Read the Announcement

@nativescript/firebase-dynamic-links

Intro

This plugin allows you to add the Firebase Dynamic Links SDK to your app, create dynamic links and receive links that launch a screen on your app.

  • To set up and initialize Firebase for your NativeScript app, follow the instructions on the documentation of the @nativescript/firebase-core plugin.

  • Install and import the @nativescript/firebase-dynamic-links to add the Dynamic Links SDK.

    1. Install the plugin by running the following command in the root directory of your project.

      npm install @nativescript/firebase-dynamic-links
      
    2. To add the Dynamic Links SDK, import the @nativescript/firebase-dynamic-links plugin. You should import the plugin once in your app project and the ideal place to do that is the app bootstrapping file( app.ts, main.ts, etc).

Tip For an optimal experience with Dynamic Links, the Firebase Dynamic Links documentation recommends you to enable Google Analytics by adding the Firebase SDK for Google Analytics to your app. To add and use Firebase SDK for Google Analytics in your NativeScript app, see the @nativescript/firebase-analytics plugin documentation.

  • Add a URL prefix for your Dynamic Links with the following steps:

    • Go to the Firebase Console
    • Click on Dynamic Link
    • Click on Get started and enter your URL prefix in the form that follows.
  • Recommended: Specify the URL patterns allowed in your deep links and fallback links. For more information, refer to Allow specific URL patterns.

iOS: Confirm that your Firebase project is properly configured

For instructions to confirm that your Firebase project is properly configured to use Dynamic Links for iOS, see configuration step 4.

You can create a dynamic link via the Firebase console, your app or even your custom API. To create a dynamic link from parameters with the plugin, call the buildLink method on the DynamicLinks class instance passing it a literal object of parameters or an instance of DynamiclinkParameters returned by the createLink or createShortLink method.

ShortLinkType

enum ShortLinkType {
  DEFAULT = 'default',
  SHORT = 'short',
  UNGUESSABLE = 'unguessable'
}

dynamicLinks = firebase().dynamicLinks()

link: string = dynamicLinks.buildLink(linkParameters)

Builds a dynamic link from parameters and returns the link as a string. Use the returned link to direct the user to your desired content.

ParameterTypeDescription
linkParametersDynamicLinkParametersThe dynamic link parameters used to create a dynamic link.
dynamicLinks: DynamicLinks = firebase().dynamicLinks()
listener = (link: DynamicLink | null, error: FirebaseError | null) => {
  // handle the link event
}
dynamicLinks.onLink(listener)

Allows you to add a callback function that gets called when your app's screen is launched by a dynamic link.

ParameterTypeDescription
listenerOnLinkListenerThe function to be called when the app's screen is launched by a dynamic link.
OnLinkListener type
type OnLinkListener = (link: DynamicLink | null, error: FirebaseError | null) => void

dynamicLinks: DynamicLinks = firebase().dynamicLinks()

dynamicLinks.resolveLink(link).then((dynamicLink: DynamicLink) => {})

As mentioned in the Create a Dynamic Link from parameters section above, you can create a dynamic link's parameters with the createLink or createShortLink method. To create a dynamic link's parameters, call either of the methods with the deep link(the link to open when the dynamic link is clicked) and your URL prefix as the first and second arguments, respectively.

const dynamicLinks = firebase().dynamicLinks()

const link = dynamicLinks.createShortLink(
  'https://docs.nativescript.org',
  'https://triniwiz.page.link'
)

link.social = new DynamicLinkSocialParameters()
link.social.imageUrl =
  'https://art.nativescript.org/logo/export/NativeScript_Logo_White_Blue_Rounded.png'

let dynamiLink = await dynamicLinks.buildLink(link)

To receive a dynamic link with a deep link to your scheme, add an intent-filter to your app's AndroidManifest.xml file located at app/App_Resources/src/main as follows.

<activity ...>
	....
<intent-filter>
        		<action android:name="android.intent.action.VIEW" />
        		<category android:name="android.intent.category.DEFAULT" />
        		<category android:name="android.intent.category.BROWSABLE" />
        		<data android:scheme="YOUR_SCHEME" />
    		</intent-filter>
</activity>

To receive the deep link that launches a screen of your app, call the onLink method on an instance of the DynamicLinks class with the function to be notified with the link.

const dynamicLinks = firebase().dynamicLinks()

dynamicLinks.onLink((link: DynamicLink) => {
  console.log('onLink', link)
})

API

ios

dynamicLinks = firebase().dynamicLinks()
dynamicLinksIOS: FIRDynamicLinks = firebase().dynamicLinks().ios

A readonly property that returns the iOS instance of FIRDynamicLinks wrapped by the DynamicLinks class.


android

dynamicLinks = firebase().dynamicLinks()
dynamicLinksAndroid = firebase().dynamicLinks().android

A readonly property that returns the Android instance of FirebaseDynamicLinks wrapped by the DynamicLinks class.


app

dynamicLinks = firebase().dynamicLinks()
dynamicLinksApp: FirebaseApp = firebase().dynamicLinks().app

A readonly property that returns the FirebaseApp instance.


dynamicLinks = firebase().dynamicLinks()

dynamicLinkParameters: DynamicLinkParameters = dynamicLinks.createLink(link, domainUri)

Creates parameters for a dynamic link and returns a DynamicLinkParameters object to be passed to the method to create a dynamic link.

ParameterTypeDescription
linkstringThe link the app will open when the dynamic link is tapped. For more information, see the description at Dynamic Link parameters.
domainUriPrefixstringYour domain prefix registered under Dynamic Links on Firebase Console.

dynamicLinks = firebase().dynamicLinks()

dynamicLinkParameters: DynamicLinkParameters = dynamicLinks.createShortLink(
  link,
  domainUri,
  shortLinkType
)

Creates parameters for a dynamic link and returns a DynamicLinkParameters object to be passed to the method to create a dynamic link.

ParameterTypeDescription
linkstringThe link the app will open when the dynamic link is tapped. For more information, see the description at Dynamic Link parameters.
domainUriPrefixstringYour domain prefix registered under Dynamic Links on Firebase Console.
shortLinkTypeShortLinkTypeOptional

ShortLinkType

enum ShortLinkType {
  DEFAULT = 'default',
  SHORT = 'short',
  UNGUESSABLE = 'unguessable'
}

dynamicLinks = firebase().dynamicLinks()

link: string = dynamicLinks.buildLink(linkParameters)

Builds a dynamic link from parameters and returns the link as a string. Use the returned link to direct the user to your desired content.

ParameterTypeDescription
linkParametersDynamicLinkParametersThe dynamic link parameters used to create a dynamic link.
dynamicLinks: DynamicLinks = firebase().dynamicLinks()
listener = (link: DynamicLink | null, error: FirebaseError | null) => {
  // handle the link event
}
dynamicLinks.onLink(listener)

Allows you to add a callback function that gets called when your app's screen is launched by a dynamic link.

ParameterTypeDescription
listenerOnLinkListenerThe function to be called when the app's screen is launched by a dynamic link.
OnLinkListener type
type OnLinkListener = (link: DynamicLink | null, error: FirebaseError | null) => void

dynamicLinks: DynamicLinks = firebase().dynamicLinks()

dynamicLinks.resolveLink(link).then((dynamicLink: DynamicLink) => {})

Resolves the passed string and returns it as a DynamicLink if it's valid. Otherwise, it returns an error.

ParameterTypeDescription
linkstringThe string to be resolved.

DynamicLinkAnalyticsParameters class

Used to create Analytics parameters for a dynamic link.

ios

ios = dynamicLinkAnalyticsParameters.ios

--

android

android = dynamicLinkAnalyticsParameters.android

campaign

campaign: undefined | string = dynamicLinkAnalyticsParameters.campign

content

content: undefined | string = dynamicLinkAnalyticsParameters.content
// or

source

source: undefined | string = dynamicLinkAnalyticsParameters.source

term

term: undefined | string = dynamicLinkAnalyticsParameters.term

DynamicLinkParameters class

analytics

dynamicAnalytics: DynamicLinkAnalyticsParameters = dynamicLinkParameters.analytics

android

dynamicLinkParametersAndroid: DynamicLinkAnalyticsParameters =
  dynamicLinkParameters.android

ios

dynamicLinkParametersIOS: DynamicLinkAnalyticsParameters = dynamicLinkParameters.ios

domainUriPrefix

dynamicDomainUriPrefix: string = dynamicLinkParameters.domainUriPrefix

The URL prefix of the dynamic link.


itunes

dynamicLinkITunesParameters: DynamicLinkITunesParameters = dynamicLinkParameters.itunes

dynamicLinkNavigationParameters: DynamicLinkNavigationParameters =
  dynamicLinkParameters.navigation

Gets or sets navigation info parameters.


social

dynamicLinkSocialParameters: DynamicLinkSocialParameters = dynamicLinkParameters.social

This object represents data of the link received by your app.

ios

linkIOS: FIRDynamicLink = link.ios

android

linkAndroid: com.google.firebase.dynamiclinks.PendingDynamicLinkData = link.android

minimumAppVersion

minimumAppVersion: string = link.minimumAppVersion

For the description of this property, see the description of getMinimumAppVersion() on the PendingDynamicLinkData class documentation.


url

url: string = link.url

For the description of this property, see the description of getUrl() on the PendingDynamicLinkData class documentation.


utmParameters

utmParameters: Record<string, string> = link.utmParameters

For the description of this property, see the description of getUtmParameters() on the PendingDynamicLinkData class documentation.

Resolves the passed string and returns it as a DynamicLink if it's valid. Otherwise, it returns an error.

ParameterTypeDescription
linkstringThe string to be resolved.

DynamicLinkAnalyticsParameters class

Used to create Analytics parameters for a dynamic link.

ios

ios = dynamicLinkAnalyticsParameters.ios

--

android

android = dynamicLinkAnalyticsParameters.android

campaign

campaign: undefined | string = dynamicLinkAnalyticsParameters.campign

content

content: undefined | string = dynamicLinkAnalyticsParameters.content
// or

source

source: undefined | string = dynamicLinkAnalyticsParameters.source

term

term: undefined | string = dynamicLinkAnalyticsParameters.term

DynamicLinkParameters class

analytics

dynamicAnalytics: DynamicLinkAnalyticsParameters = dynamicLinkParameters.analytics

android

dynamicLinkParametersAndroid: DynamicLinkAnalyticsParameters =
  dynamicLinkParameters.android

ios

dynamicLinkParametersIOS: DynamicLinkAnalyticsParameters = dynamicLinkParameters.ios

domainUriPrefix

dynamicDomainUriPrefix: string = dynamicLinkParameters.domainUriPrefix

The URL prefix of the dynamic link.


itunes

dynamicLinkITunesParameters: DynamicLinkITunesParameters = dynamicLinkParameters.itunes

dynamicLinkNavigationParameters: DynamicLinkNavigationParameters =
  dynamicLinkParameters.navigation

Gets or sets navigation info parameters.


social

dynamicLinkSocialParameters: DynamicLinkSocialParameters = dynamicLinkParameters.social

This object represents data of the link received by your app.

ios

linkIOS: FIRDynamicLink = link.ios

android

linkAndroid: com.google.firebase.dynamiclinks.PendingDynamicLinkData = link.android

minimumAppVersion

minimumAppVersion: string = link.minimumAppVersion

For the description of this property, see the description of getMinimumAppVersion() on the PendingDynamicLinkData class documentation.


url

url: string = link.url

For the description of this property, see the description of getUrl() on the PendingDynamicLinkData class documentation.


utmParameters

utmParameters: Record<string, string> = link.utmParameters

For the description of this property, see the description of getUtmParameters() on the PendingDynamicLinkData class documentation.

License

Apache License Version 2.0