capacitor-chottulink-sdk
v1.0.4
Published
ChottuLink is your all-in-one solution for creating, managing, and tracking dynamic links across platforms. Boost your marketing campaigns with smart deep linking and comprehensive analytics.
Maintainers
Keywords
Readme
ChottuLink Capacitor SDK
ChottuLink is your all-in-one solution for creating, managing, and tracking dynamic links across platforms. Boost your marketing campaigns with smart deep linking and comprehensive analytics.
Features
- 🔗 Dynamic Link Creation - Create short, trackable links with custom parameters
- 📱 Deep Linking - Seamlessly route users to specific content in your app
- 📊 Analytics - Track link performance with UTM parameters
- 🎯 Platform-Specific Behavior - Control how links behave on iOS and Android
- 🔔 Event Listeners - Listen for deep link resolution events
- 🌐 Cross-Platform - Works on iOS, Android, and Web (with limitations)
Installation
npm install capacitor-chottulink-sdk
npx cap syncPrerequisites
Before installing this plugin, ensure you have the following set up:
- Node.js: 16.x or higher
- Capacitor: 5.0.0 or higher
- iOS Deployment Target: 15.0 or higher
- Android SDK: API 21 (Android 5.0) or higher
- ChottuLink Account: A valid ChottuLink account with an API key
Getting Started
1. Initialize the SDK
Before using any ChottuLink features, you must initialize the SDK with your API key:
import { ChottuLinkIonicSDK } from 'capacitor-chottulink-sdk';
await ChottuLinkIonicSDK.initialize({
apiKey: 'your-api-key-here'
});2. Create Dynamic Links
Create dynamic links with customizable parameters:
import { ChottuLinkIonicSDK, CLDynamicLinkBehaviour } from 'capacitor-chottulink-sdk';
const result = await ChottuLinkIonicSDK.createDynamicLink({
builder: {
destinationURL: 'https://example.com/product/123',
domain: 'your-domain.com',
linkName: 'product-link',
iosBehaviour: CLDynamicLinkBehaviour.app,
androidBehaviour: CLDynamicLinkBehaviour.app,
socialTitle: 'Check out this product!',
socialDescription: 'Amazing product description',
socialImageUrl: 'https://example.com/image.jpg',
utmSource: 'email',
utmMedium: 'campaign',
utmCampaign: 'summer-sale'
}
});
console.log('Short URL:', result.shortURL);3. Handle Incoming Links:
// Listen for successful deep link resolution
ChottuLinkIonicSDK.addListener('onDeepLinkResolved', (data) => {
console.log('Deep link resolved:', data.url);
console.log('Metadata:', data.metadata);
// Navigate to the appropriate screen in your app
});
// Listen for failed deep link resolution
ChottuLinkIonicSDK.addListener('onDeepLinkFailed', (data) => {
console.error('Deep link failed:', data.error);
console.log('Original URL:', data.originalURL);
});4. (Optional) Get AppLink Data from the Deeplink URL directly
const resolved = await ChottuLinkIonicSDK.getAppLinkDataFromUrl({
shortURL: 'https://your-domain.com/abc123'
});
if (resolved) {
console.log('Original link:', resolved.link);
console.log('Short link:', resolved.shortLink);
console.log('Short link Raw:', resolved.shortLinkRaw);
console.log('isDeferred:', resolved.isDeferred);
}Web
⚠️ Note: The plugin methods are not fully implemented on web. They will throw unimplemented errors. This plugin is primarily designed for native mobile platforms.
API
initialize(...)createDynamicLink(...)getAppLinkDataFromUrl(...)addListener('onDeepLinkResolved', ...)addListener('onDeepLinkFailed', ...)- Interfaces
- Type Aliases
- Enums
initialize(...)
initialize(options: { apiKey: string; }) => Promise<void>| Param | Type |
| ------------- | -------------------------------- |
| options | { apiKey: string; } |
createDynamicLink(...)
createDynamicLink(options: { builder: CLDynamicLinkBuilder; }) => Promise<{ shortURL: string | null; }>| Param | Type |
| ------------- | ----------------------------------------------------------------------------------- |
| options | { builder: CLDynamicLinkBuilder; } |
Returns: Promise<{ shortURL: string | null; }>
getAppLinkDataFromUrl(...)
getAppLinkDataFromUrl(options: { shortURL: string; }) => Promise<CLResolvedLink | null>| Param | Type |
| ------------- | ---------------------------------- |
| options | { shortURL: string; } |
Returns: Promise<CLResolvedLink | null>
addListener('onDeepLinkResolved', ...)
addListener(eventName: 'onDeepLinkResolved', listenerFunc: (data: { url: string; metadata?: Record<string, any>; }) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | ------------------------------------------------------------------------------------------------------------ |
| eventName | 'onDeepLinkResolved' |
| listenerFunc | (data: { url: string; metadata?: Record<string, any>; }) => void |
Returns: Promise<PluginListenerHandle>
addListener('onDeepLinkFailed', ...)
addListener(eventName: 'onDeepLinkFailed', listenerFunc: (data: { error: string; originalURL?: string; }) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | ------------------------------------------------------------------------ |
| eventName | 'onDeepLinkFailed' |
| listenerFunc | (data: { error: string; originalURL?: string; }) => void |
Returns: Promise<PluginListenerHandle>
Interfaces
CLDynamicLinkBuilder
| Prop | Type |
| ----------------------- | ------------------------------------------------------------------------- |
| destinationURL | string |
| domain | string |
| linkName | string |
| androidBehaviour | CLDynamicLinkBehaviour |
| iosBehaviour | CLDynamicLinkBehaviour |
| selectedPath | string |
| socialTitle | string |
| socialDescription | string |
| socialImageUrl | string |
| utmSource | string |
| utmMedium | string |
| utmCampaign | string |
| utmContent | string |
| utmTerm | string |
CLResolvedLink
| Prop | Type |
| ------------------ | ---------------------------- |
| isDeferred | boolean | null |
| link | string | null |
| shortLink | string | null |
| shortLinkRaw | string | null |
PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove | () => Promise<void> |
Type Aliases
Record
Construct a type with a set of properties K of type T
{ [P in K]: T; }
Enums
CLDynamicLinkBehaviour
| Members | Value |
| ------------- | -------------- |
| browser | 1 |
| app | 2 |
Complete Example
Here's a complete example of how to use the plugin in your Capacitor app:
import { ChottuLinkIonicSDK, CLDynamicLinkBehaviour } from 'capacitor-chottulink-sdk';
// Initialize on app startup
async function initChottuLink() {
try {
await ChottuLinkIonicSDK.initialize({
apiKey: 'your-api-key-here'
});
console.log('ChottuLink SDK initialized');
} catch (error) {
console.error('Failed to initialize ChottuLink:', error);
}
}
// Set up deep link listeners
function setupDeepLinkListeners() {
ChottuLinkIonicSDK.addListener('onDeepLinkResolved', (data) => {
console.log('Deep link resolved:', data.url);
// Navigate to the appropriate screen based on data.url
// Example: router.push(parseUrl(data.url));
});
ChottuLinkIonicSDK.addListener('onDeepLinkFailed', (data) => {
console.error('Deep link failed:', data.error);
// Handle error appropriately
});
}
// Create a dynamic link
async function shareProduct(productId: string) {
try {
const result = await ChottuLinkIonicSDK.createDynamicLink({
builder: {
destinationURL: `https://yourapp.com/products/${productId}`,
domain: 'your-domain.com',
linkName: `product-${productId}`,
iosBehaviour: CLDynamicLinkBehaviour.app,
androidBehaviour: CLDynamicLinkBehaviour.app,
socialTitle: 'Check out this amazing product!',
socialDescription: 'You won\'t believe what this product can do.',
socialImageUrl: `https://yourapp.com/images/products/${productId}.jpg`,
utmSource: 'app',
utmMedium: 'share',
utmCampaign: 'product-sharing'
}
});
if (result.shortURL) {
// Share the short URL
await Share.share({ url: result.shortURL });
}
} catch (error) {
console.error('Failed to create dynamic link:', error);
}
}
// Initialize on app load
initChottuLink();
setupDeepLinkListeners();Troubleshoot & Test Deep links
For more detailed troubleshooting steps and testing procedures, visit: https://docs.chottulink.com/troubleshooting
