Skip to main content

Cordova - Receive Dynamic Links

Enable your Cordova app to receive and handle ChottuLinks seamlessly. This allows users to open specific screens when they tap a dynamic link, whether the app is running, in the background, or launched from a cold start. Integrate link handling to ensure a smooth and context-aware user experience across platforms.

Using Capacitor or Ionic?

Prerequisites​

Before implementing dynamic link reception, ensure you have:

To respond to dynamic links, your app should listen for incoming deep link events using the ChottuLink SDK listeners.

// Listen for successful deep link resolution
ChottuLink.addListener('onDeepLinkResolved', function (data) {
console.log('Deep link resolved:', data.url);
console.log('Metadata:', data.metadata);
// data.metadata (all optional):
// - originalURL: string The short link that was opened, before resolution
// - shortLinkRaw: string The short link exactly as clicked, with all parameters intact
// - isDeferred: boolean True when the link was matched after install rather than on open
});

// Listen for failed deep link resolution
ChottuLink.addListener('onDeepLinkFailed', function (data) {
console.error('Deep link failed:', data.error);
console.log('Original URL:', data.originalURL);
});
Subscribe before you initialize

Register your addListener calls before calling ChottuLink.initialize(...). A link that launched the app cold is queued natively and replayed the moment both the SDK and your listeners are ready, so no link is lost — but only if the listener is already registered.

onDeepLinkFailed can fire on an ordinary launch

On a cold start, the plugin hands the launch intent (Android) or launch URL (iOS) to the SDK even when it carries no link, because that's what triggers the deferred attribution lookup — the check that matches an install back to a link clicked before the app existed. When there's nothing to match, the SDK reports a failure. Treat this event as informational rather than an error worth surfacing to users: log it, but only navigate on onDeepLinkResolved.

addListener resolves with a handle you can use to unsubscribe:

ChottuLink.addListener('onDeepLinkResolved', onLink).then(function (handle) {
// later, when you no longer need the listener:
handle.remove();
});

Complete Implementation Example​

var resolvedHandle;
var failedHandle;

document.addEventListener('deviceready', function () {
// Register listeners before initializing, so a cold-start link isn't missed
ChottuLink.addListener('onDeepLinkResolved', function (data) {
console.log('Deep link resolved:', data.url);
console.log('Metadata:', data.metadata);
// Navigate to the appropriate screen in your app
}).then(function (handle) {
resolvedHandle = handle;
});

ChottuLink.addListener('onDeepLinkFailed', function (data) {
console.error('Deep link failed:', data.error);
console.log('Original URL:', data.originalURL);
}).then(function (handle) {
failedHandle = handle;
});

ChottuLink.initialize({ apiKey: 'YOUR_API_KEY' })
.then(function () {
console.log('✅ ChottuLink initialized successfully');
})
.catch(function (error) {
console.error('❌ Error initializing ChottuLink:', error);
});
}, false);

Resolve a short URL to its underlying link data using the getAppLinkDataFromUrl method, without waiting for the user to open it. It returns a CLResolvedLink object, or null when the link isn't found.

Method Signature

getAppLinkDataFromUrl(options: { shortURL: string }): Promise<CLResolvedLink | null>

Parameters

ParameterTypeRequiredDescription
options.shortURLstring

Yes

The shortened URL string to be resolved

Return Value

A CLResolvedLink object (or null), containing:

interface CLResolvedLink {
isDeferred: boolean | null; // True when matched after install rather than on open
link: string | null; // The resolved destination URL
shortLink: string | null; // The short link that was opened
shortLinkRaw: string | null; // The short link before any redirect normalisation
}

Error Handling

Note: This method can reject for native-layer or network reasons. Always implement proper error handling.

  • A missing options.shortURL rejects immediately on the JavaScript side
  • Otherwise, rejections surface as a standard Error describing the native or network failure

Basic Implementation

ChottuLink.getAppLinkDataFromUrl({ shortURL: 'https://yourapp.chottu.link/abc123' })
.then(function (resolved) {
if (resolved) {
console.log('Destination:', resolved.link);
console.log('Deferred?', resolved.isDeferred);
// Navigate to the destination
}
})
.catch(function (error) {
console.error('❌ Failed to get app link data:', error);
});

Next Steps​

  1. Create Dynamic Links
  2. Explore REST API
  3. View Analytics

Troubleshooting​

For more troubleshooting help, see the Troubleshooting Guide.