⚡ Generate Dynamic Links in Capacitor
This guide covers how to create a Dynamic Link directly from your Capacitor app using TypeScript/JavaScript.
🛠 Prerequisites
Before generating links, ensure:
🔗 Build a Dynamic Link
1. Basic link creation
import { ChottuLinkIonicSDK, CLDynamicLinkBehaviour } from 'capacitor-chottulink-sdk';
// Create a basic dynamic link
const link = await ChottuLinkIonicSDK.createDynamicLink({
link: 'https://yourapp.com/content',
domain: 'yourapp.chottu.link'
});
2. Advanced link with all features
import { ChottuLinkIonicSDK, CLDynamicLinkBehaviour } from 'capacitor-chottulink-sdk';
// Create an advanced dynamic link with all features
const link = await ChottuLinkIonicSDK.createDynamicLink({
link: 'https://yourapp.com/content',
domain: 'yourapp.chottu.link',
iosBehaviour: CLDynamicLinkBehaviour.app, // 'app' or 'browser'
androidBehaviour: CLDynamicLinkBehaviour.app, // 'app' or 'browser'
linkName: 'summer-sale',
selectedPath: 'promo-summer', // Optional: Customize the URL path
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'
});
3. Create the Link
Recommended: Promise-based Method
import { ChottuLinkIonicSDK, CLDynamicLinkBehaviour } from 'capacitor-chottulink-sdk';
try {
const result = await ChottuLinkIonicSDK.createDynamicLink({
link: 'https://yourapp.com/content',
domain: 'yourapp.chottu.link',
iosBehaviour: CLDynamicLinkBehaviour.app,
androidBehaviour: CLDynamicLinkBehaviour.app
});
console.log('✅ Created link:', result.shortURL);
// Share the link with your users
} catch (error) {
console.error('❌ Failed to create link:', error);
// Handle the error appropriately
}
4. ⚠️ Error Handling
Note:
The method can throw various errors. Always implement proper error handling.
Possible errors:
notInitialized– If SDK is not initializedinvalidAPIKey– If the API key is not availablemissingKeys– If required configuration is missingduplicatePath– If the path already existsbadRequest– If the request is invalid- Network errors if the request fails
info
- Default behavior is set to
'app'for both platforms selectedPathis optional - if not provided, a random path will be generatedsocialTitle,socialDescription, andsocialImageUrlare optional - enhances link previews when sharedutmSource,utmMedium,utmCampaign,utmContent, andutmTermare optional - helps track campaign performance- Important: Make sure you have a valid internet connection when creating links
🔄 Link Behaviors
The behavior parameter controls how your dynamic link behaves on different platforms.
Available Behaviors
type CLDynamicLinkBehaviour = 'app' | 'browser';
'app'- Opens the app if installed, falls back to browser/App Store/Play Store'browser'- Always opens in browser
tip
Each behavior can be set independently for iOS and Android platforms, allowing for platform-specific user experiences.
Open in App
'CLDynamicLinkBehaviour.app'How it works
- Opens your app if installed
- Falls back to browser if app is not installed
- Best for deep linking to specific content
When to Use 'app'
- Deep linking to specific app content
- Providing seamless user experience
- App functionality is required
Example
iosBehaviour: 'CLDynamicLinkBehaviour.app'
Always Browser
'CLDynamicLinkBehaviour.browser'How it works
- Always opens in browser
- Useful for marketing campaigns
- Good for analytics tracking
When to Use 'browser'
- Running marketing campaigns
- Sharing content that works well in browser
- Need consistent analytics tracking
Example
iosBehaviour: 'CLDynamicLinkBehaviour.browser'
💡 Complete Example
- Angular
- React
- Vue
import { Component } from '@angular/core';
import { ChottuLinkIonicSDK, CLDynamicLinkBehaviour } from 'capacitor-chottulink-sdk';
import { NgIf } from '@angular/common';
@Component({
selector: 'app-share',
standalone: true,
template: `
<div>
<button (click)="createLink()" [disabled]="loading">
{{ loading ? 'Creating...' : 'Create Dynamic Link' }}
</button>
<p *ngIf="link" style="margin-top: 10px;">Link: {{ link }}</p>
</div>
`,
imports: [
NgIf
],
styles: [`
div {
text-align: center;
margin-top: 20px;
}
button {
padding: 10px 20px;
background-color: #007aff;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
}
button:disabled {
background-color: #888;
cursor: not-allowed;
}
`]
})
export class ShareComponent {
link: string | undefined = '';
loading: boolean = false;
async createLink() {
this.loading = true;
try {
const link = await ChottuLinkIonicSDK.createDynamicLink({
builder : {
destinationURL: 'https://example.com',
domain: 'your-domain.chottu.link',
iosBehaviour: CLDynamicLinkBehaviour.app,
androidBehaviour: CLDynamicLinkBehaviour.app,
linkName: 'product-123',
socialTitle: 'Check out this product!',
socialDescription: 'Amazing product at great price',
socialImageUrl: 'https://yourapp.com/images/product.jpg',
utmSource: 'app',
utmMedium: 'share',
utmCampaign: 'product-promotion'
}
});
this.link = link.shortURL?.toString();
console.log('✅ Created link:', link);
} catch (error) {
console.error('❌ Failed to create link:', error);
alert('Failed to create link. Please try again.');
} finally {
this.loading = false;
}
}
}
import React, { useEffect, useState } from 'react';
import { ChottuLinkIonicSDK, CLDynamicLinkBehaviour } from 'capacitor-chottulink-sdk';
function ShareButton() {
const [link, setLink] = useState('');
const [loading, setLoading] = useState(false);
const createLink = async () => {
setLoading(true);
try {
const link = await ChottuLinkIonicSDK.createDynamicLink({
builder: {
domain: 'your-domain.chottu.link',
destinationURL: 'https://yourapp.com/product/123',
iosBehaviour: CLDynamicLinkBehaviour.app,
androidBehaviour: CLDynamicLinkBehaviour.app,
linkName: 'product-123',
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',
}
});
setLink(link.shortURL);
console.log('✅ Created link:', link.shortURL);
} catch (error) {
console.error('❌ Failed to create link:', error);
alert('Failed to create link. Please try again.');
} finally {
setLoading(false);
}
};
return (
<div style={{ marginTop: 20 }}>
<button onClick={createLink} disabled={loading}>
{loading ? 'Creating...' : 'Create Dynamic Link'}
</button>
{link && (
<p style={{ marginTop: 10 }}>
{link}
</p>
)}
</div>
);
}
<template>
<div style="margin-top: 20px;">
<button @click="createLink" :disabled="loading">
{{ loading ? 'Creating...' : 'Create Dynamic Link' }}
</button>
<p v-if="link" style="margin-top: 10px;">
{{ link }}
</p>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { ChottuLinkIonicSDK, CLDynamicLinkBehaviour } from 'capacitor-chottulink-sdk';
const link = ref('');
const loading = ref(false);
const createLink = async () => {
loading.value = true;
try {
const result = await ChottuLinkIonicSDK.createDynamicLink({
builder: {
domain: 'your-domain.chottu.link',
destinationURL: 'https://yourapp.com/product/123',
iosBehaviour: CLDynamicLinkBehaviour.app,
androidBehaviour: CLDynamicLinkBehaviour.app,
linkName: 'product-123',
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'
}
});
link.value = result.shortURL;
console.log('✅ Created link:', result.shortURL);
} catch (error) {
console.error('❌ Failed to create link:', error);
alert('Failed to create link. Please try again.');
} finally {
loading.value = false;
}
};
</script>
<style scoped>
button {
padding: 10px 20px;
background-color: #007aff;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
}
button:disabled {
background-color: #888;
cursor: not-allowed;
}
</style>