# React Native SDK

Use the `smartlinks` JavaScript package together with the `react-native-smartlinks` native bridge. The examples here use the published 2.0.3 releases and require an iOS/Android native build.

## Install

```bash
npm install smartlinks@^2.0.3 react-native-smartlinks@^2.0.3 react-native-safe-area-context
```

For iOS, run `pod install` from your `ios` directory. Rebuild the native app after installation; refreshing Metro does not install native modules. Expo Go does not contain this custom bridge—use a native development build with the required platform setup.

Feedback file attachments additionally use `react-native-document-picker`; add it only when that workflow is needed.

## Initialize once

Run initialization in your app's startup flow before calling analytics or opening SDK screens:

```typescript
import { SmartLinks } from 'smartlinks';

await SmartLinks.initialize({
  apiKey: 'YOUR_API_KEY',
  isDebug: __DEV__,
  initializeAds: false,
  appVersion: '1.0.0', // Replace with your actual app version.
});

SmartLinks.analytics.sendEvent('integration_test', { screen: 'home' });

SmartLinks.analytics.getLink((route) => {
  // Validate route.route and route.params.
  // Navigate only after your app's navigator is ready.
});
```

Keep the public placeholder unchanged in shared examples. Supply your app-specific key only in your own development/build configuration. Catch initialization errors in the host app and keep normal startup usable during a network failure.

## Android links

The native bridge resolves its core SDK from Maven Central. Configure your actual application ID and signing fingerprints in SmartLinks, and add a link filter to the receiving Android Activity:

```xml
<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="https"
          android:host="smartlinks.live"
          android:pathPrefix="/l/YOUR_APP_SLUG/" />
</intent-filter>
```

Replace the slug and domain. Short links use different paths; include the routes you actually distribute rather than assuming this long-form example covers them all.

## iOS links

Autolinking uses CocoaPods. Add **Associated Domains** with `applinks:smartlinks.live` or your configured domain, and check the Apple Team ID and bundle identifier in the private dashboard. Follow the native setup reference when wiring AppDelegate or SceneDelegate link callbacks.

## Optional modules

| Module | Entry point |
| --- | --- |
| Feedback | `SmartLinks.openFeedback(navigation)` |
| App list | `SmartLinks.openApps(navigation)` |
| Community | `SmartLinks.community.open(navigation)` |
| Blogs | `SmartLinks.blogs.open(navigation)` |
| AI Gateway | `SmartLinks.ai.chat()` and `SmartLinks.ai.runPipeline()` |

Provide the appropriate navigation adapter when opening a screen. Configure community authentication, ads and AI Gateway separately before enabling them. Provider secrets stay in private server-side configuration.

## Verify and learn more

Send `integration_test` from a native build and confirm it in the matching app's private analytics page. Test deep links on devices before shipping.

- [Published JavaScript package](https://www.npmjs.com/package/smartlinks)
- [Published native bridge](https://www.npmjs.com/package/react-native-smartlinks)
- [Native setup reference](https://gitlab.com/elmansoryanas/smartlinks-react-native/-/blob/main/docs/native-setup.md)
- [API keys and troubleshooting](/docs/authentication)
