The resolveDeepLink() method resolves a Smler short link URL into its full metadata — including the original destination URL, domain, short code, and campaign (DLT) header. Use this both for deferred deep links (after first install) and for runtime deep links (when the app is already installed and a user taps a link).
How It Works
The SDK parses the short link URL to extract the
shortCode, optionaldltHeader, anddomainfrom the path and hostname.It sends a
GETrequest to the Smler API:https://smler.in/api/v1/short?short=<shortCode>&dltHeader=<dltHeader>&domain=<domain>The API returns the full metadata for that short link.
Basic Usage
import { SmlerDeferredLink } from '@smler/deferred-link';
import type { ResolvedDeepLinkData } from '@smler/deferred-link';
const data: ResolvedDeepLinkData = await SmlerDeferredLink.resolveDeepLink(
'https://go.yourdomain.com/abc123'
);
console.log('Short code:', data.shortCode);
console.log('Domain:', data.domain);
console.log('Original URL:', data.originalUrl);
console.log('DLT header:', data.dltHeader);ResolvedDeepLinkData Fields
Field | Type | Description |
|---|---|---|
|
| The short URL code |
|
| The domain the short link belongs to |
|
| Optional campaign/category header (e.g. |
|
| The original destination URL the short link points to |
|
| Error code if the request failed |
|
| Error message if the request failed |
The response may also contain additional fields returned by the Smler API.
With Webhook Trigger
You can instruct the Smler backend to fire the configured webhook automatically in the same API request by passing triggerWebhook: true. This eliminates the need for a separate webhook call:
const data = await SmlerDeferredLink.resolveDeepLink(
'https://go.yourdomain.com/abc123',
{ triggerWebhook: true }
);
// The webhook has already been triggered server-side
console.log('Resolved:', data.originalUrl);When triggerWebhook is provided, the SDK appends &triggerWebhook=true to the API request. The backend fires the webhook as part of the same request, so you do not need to call triggerWebhook() separately.
URL Path Parsing
The SDK parses the path of the short link URL to determine the shortCode and dltHeader:
https://go.yourdomain.com/abc123→shortCode: "abc123",dltHeader: undefinedhttps://go.yourdomain.com/BKMTCH/abc123→shortCode: "abc123",dltHeader: "BKMTCH"
The first path segment is treated as the dltHeader when two segments are present. If only one segment exists, it is the shortCode.
Runtime Deep Links
For users who already have the app installed, listen for incoming deep links using React Native's Linking API and resolve them:
import { Linking } from 'react-native';
import { SmlerDeferredLink } from '@smler/deferred-link';
// Listen for deep links while the app is running
Linking.addEventListener('url', async (event) => {
if (event.url) {
const data = await SmlerDeferredLink.resolveDeepLink(event.url, {
triggerWebhook: true,
});
console.log('Short code:', data.shortCode);
console.log('Original URL:', data.originalUrl);
// Navigate to the correct screen
}
});
// Check if the app was opened via a deep link (cold start)
const initialUrl = await Linking.getInitialURL();
if (initialUrl) {
const data = await SmlerDeferredLink.resolveDeepLink(initialUrl, {
triggerWebhook: true,
});
// Navigate based on data
}Error Handling
The method does not throw errors for API failures. Instead, it returns an object with error and message fields:
const data = await SmlerDeferredLink.resolveDeepLink(someUrl);
if (data.error) {
console.error('Resolution failed:', data.error, data.message);
} else {
console.log('Resolved to:', data.originalUrl);
}Possible error values:
"Invalid URL"— the provided URL could not be parsed"No short code found in URL"— the URL path had no segments"HTTP 4xx/5xx"— the Smler API returned an error status"Exception"— a network or unexpected error occurred
Using resolveDeepLinkData() Directly
SmlerDeferredLink.resolveDeepLink() is a convenience wrapper around HelperReferrer.resolveDeepLinkData(). They are functionally identical — use whichever fits your code style:
import { HelperReferrer } from '@smler/deferred-link';
// Equivalent to SmlerDeferredLink.resolveDeepLink()
const data = await HelperReferrer.resolveDeepLinkData(
'https://go.yourdomain.com/abc123',
{ triggerWebhook: true }
);
Published with LeafPad