Generate Dynamic Links in Cordova
This guide covers how to create a Dynamic Link directly from your Cordova app using JavaScript.
Using Capacitor or Ionic?
See Generate Dynamic Links in Capacitor instead.
Prerequisites
Before generating links, ensure:
Build a Dynamic Link
1. Basic link creation
document.addEventListener('deviceready', function () {
ChottuLink.createDynamicLink({
destinationURL: 'https://yourapp.com/content',
domain: 'yourapp.chottu.link'
}).then(function (result) {
console.log('✅ Created link:', result.shortURL);
}).catch(function (error) {
console.error('❌ Failed to create link:', error);
});
}, false);
2. Advanced link with all features
ChottuLink.createDynamicLink({
destinationURL: 'https://yourapp.com/content',
domain: 'yourapp.chottu.link',
linkName: 'summer-sale',
androidBehaviour: ChottuLink.CLDynamicLinkBehaviour.app, // or .browser
iosBehaviour: ChottuLink.CLDynamicLinkBehaviour.app, // or .browser
selectedPath: 'promo-summer', // Optional: custom URL path, must be unique for the domain
socialTitle: 'Summer Sale',
socialDescription: 'Check out our amazing deals!',
socialImageUrl: 'https://yourapp.com/images/sale.jpg',
utmSource: 'email',
utmMedium: 'newsletter',
utmCampaign: 'summer2025',
utmContent: 'banner',
utmTerm: 'summer'
}).then(function (result) {
console.log('✅ Created link:', result.shortURL);
}).catch(function (error) {
console.error('❌ Failed to create link:', error);
});
3. Create the Link
The Promise-based form is recommended; the classic Cordova (success, error) callback style is also supported on every method, for apps that still rely on it.
// Promise-based (recommended)
try {
const result = await ChottuLink.createDynamicLink({
destinationURL: 'https://yourapp.com/content',
domain: 'yourapp.chottu.link',
androidBehaviour: ChottuLink.CLDynamicLinkBehaviour.app,
iosBehaviour: ChottuLink.CLDynamicLinkBehaviour.app
});
console.log('✅ Created link:', result.shortURL);
} catch (error) {
console.error('❌ Failed to create link:', error);
}
// Callback-based (legacy)
ChottuLink.createDynamicLink(
{ destinationURL: 'https://yourapp.com/content', domain: 'yourapp.chottu.link' },
function (result) { console.log('✅ Created link:', result.shortURL); },
function (error) { console.error('❌ Failed to create link:', error); }
);
4. Error Handling
Note:
createDynamicLink can reject for several reasons. Always implement proper error handling.
- A missing
destinationURLordomainrejects immediately on the JavaScript side, before any native call is made - Otherwise, the rejection is a native-layer or network error, surfaced as a standard
Errorwhosemessagedescribes the failure (and, when the native side supplied one, a.codeproperty)
info
destinationURLanddomainare the only required fields- Default behavior is
appfor both platforms when omitted selectedPathis optional — if not provided, a random path is generated; it must be unique for the domainsocialTitle,socialDescription, andsocialImageUrlare optional — they enhance link previews when sharedutmSource,utmMedium,utmCampaign,utmContent, andutmTermare optional — they help track campaign performance- Important: a valid internet connection is required when creating links
Link Behaviors
androidBehaviour and iosBehaviour control how your dynamic link behaves on each platform independently, via the CLDynamicLinkBehaviour enum:
enum CLDynamicLinkBehaviour {
browser = 1,
app = 2
}
ChottuLink.CLDynamicLinkBehaviour.app— opens the app if installed, falls back to the browser (and from there to the App/Play Store)ChottuLink.CLDynamicLinkBehaviour.browser— always opens in the device browser
tip
Each behavior can be set independently for iOS and Android, allowing for platform-specific experiences — for example, browser on iOS and app on Android.
Complete Example
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Create a ChottuLink</title>
</head>
<body>
<button id="create-link-btn" disabled>Create Dynamic Link</button>
<p id="result"></p>
<script src="cordova.js"></script>
<script>
var button = document.getElementById('create-link-btn');
var result = document.getElementById('result');
document.addEventListener('deviceready', function () {
ChottuLink.initialize({ apiKey: 'YOUR_API_KEY' })
.then(function () {
button.disabled = false;
})
.catch(function (error) {
console.error('❌ Error initializing ChottuLink:', error);
});
}, false);
button.addEventListener('click', function () {
button.disabled = true;
button.textContent = 'Creating...';
ChottuLink.createDynamicLink({
destinationURL: 'https://example.com/product/123',
domain: 'yourapp.chottu.link',
linkName: 'product-123',
androidBehaviour: ChottuLink.CLDynamicLinkBehaviour.app,
iosBehaviour: ChottuLink.CLDynamicLinkBehaviour.app,
socialTitle: 'Check out this product!',
socialDescription: 'Amazing product at a great price',
socialImageUrl: 'https://yourapp.com/images/product.jpg',
utmSource: 'app',
utmMedium: 'share',
utmCampaign: 'product-promotion'
}).then(function (link) {
result.textContent = link.shortURL;
console.log('✅ Created link:', link.shortURL);
}).catch(function (error) {
console.error('❌ Failed to create link:', error);
alert('Failed to create link. Please try again.');
}).finally(function () {
button.disabled = false;
button.textContent = 'Create Dynamic Link';
});
});
</script>
</body>
</html>