@deeplinx/sdk
v1.0.1
Published
Official JavaScript SDK for DeepLinx - Smart Deep Linking Platform
Maintainers
Readme
@deeplinx/sdk
Official JavaScript SDK for DeepLinx - Smart Deep Linking Platform.
Features
- 🔗 Deferred Deep Linking - Capture context before app install
- 📊 Event Tracking - Track custom events and conversions
- 👤 User Identification - Link anonymous users to accounts
- 🔒 Install Attribution - Track which links drive installs
- 💾 Offline Support - Works without network connectivity
- 📱 Cross-Platform - Works in browsers and React Native
Installation
npm install @deeplinx/sdk
# or
yarn add @deeplinx/sdk
# or
pnpm add @deeplinx/sdkQuick Start
Initialize the SDK
import { DeepLinx } from '@deeplinx/sdk';
const deeplinx = new DeepLinx({
apiKey: 'your-api-key',
debug: true, // Enable console logging
});
// Initialize on page load
await deeplinx.init();Deferred Deep Linking
When a user clicks your DeepLinx short link and doesn't have your app installed:
- They arrive on your landing page with
?_dl=short-slugparameter - The SDK captures their device fingerprint
- After they install your app, call
match()to retrieve the original context
// In your mobile app (React Native/Capacitor/etc.)
const context = await deeplinx.match();
if (context) {
console.log('User came from:', context.slug);
console.log('Original link:', context.longUrl);
console.log('Custom data:', context.context);
// Navigate to the intended content
navigation.navigate(context.context.screen, context.context.params);
}Track Events
// Track a simple event
deeplinx.track('button_click');
// Track with properties
deeplinx.track('purchase', {
productId: 'sku-123',
amount: 99.99,
currency: 'USD',
});
// Track page views
deeplinx.track('page_view', {
page: '/products/shoes',
category: 'footwear',
});Identify Users
// After user logs in
deeplinx.identify('user-123', {
email: '[email protected]',
name: 'John Doe',
plan: 'premium',
signupDate: '2024-01-15',
});Get User Information
// Get current user ID (null if not identified)
const userId = deeplinx.getUserId();
// Get anonymous ID (always available)
const anonId = deeplinx.getAnonymousId();
// Get stored deferred context
const context = deeplinx.getDeferredContext();Reset on Logout
// Clear all stored data when user logs out
deeplinx.reset();Configuration Options
const deeplinx = new DeepLinx({
// Required: Your API key
apiKey: 'your-api-key',
// Optional: Custom API endpoint (default: https://api.deeplinx.tech)
baseUrl: 'https://your-custom-domain.com',
// Optional: Enable debug logging (default: false)
debug: true,
// Optional: Custom storage adapter
storage: customStorageAdapter,
});TypeScript Support
Full TypeScript support with exported types:
import type {
DeepLinxConfig,
DeferredContext,
TrackEventProperties,
UserTraits,
Fingerprint,
} from '@deeplinx/sdk';
// Use in your code
const config: DeepLinxConfig = {
apiKey: 'your-api-key',
};
const handleContext = (context: DeferredContext | null) => {
if (context) {
// ...
}
};Custom Storage
For environments without localStorage (like React Native):
import { DeepLinx, MemoryStorageAdapter, StorageAdapter } from '@deeplinx/sdk';
// Use built-in memory adapter
const deeplinx = new DeepLinx({
apiKey: 'your-api-key',
storage: new MemoryStorageAdapter(),
});
// Or implement your own
class AsyncStorageAdapter implements StorageAdapter {
getItem(key: string) {
return AsyncStorage.getItem(key);
}
setItem(key: string, value: string) {
AsyncStorage.setItem(key, value);
}
removeItem(key: string) {
AsyncStorage.removeItem(key);
}
}UMD/Browser Usage
<script src="https://cdn.deeplinx.tech/sdk/1.0.0/index.umd.js"></script>
<script>
const deeplinx = new DeepLinx.DeepLinx({
apiKey: 'your-api-key',
});
deeplinx.init().then(() => {
deeplinx.track('page_loaded');
});
</script>API Reference
DeepLinx(config)
Create a new SDK instance.
deeplinx.init(): Promise<void>
Initialize the SDK. Call on page load.
deeplinx.match(): Promise<DeferredContext | null>
Attempt to match the current device with a previous click.
deeplinx.track(event, properties?): Promise<void>
Track a custom event.
deeplinx.identify(userId, traits?): Promise<void>
Identify the current user.
deeplinx.getUserId(): string | null
Get the current user ID.
deeplinx.getAnonymousId(): string
Get the anonymous ID.
deeplinx.getDeferredContext(): DeferredContext | null
Get stored deferred context.
deeplinx.clearDeferredContext(): void
Clear stored deferred context.
deeplinx.reset(): void
Reset SDK state (use on logout).
License
MIT © DeepLinx
