> For the complete documentation index, see [llms.txt](https://docs.hackle.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hackle.io/en/development-guide/react-native/react-native-deeplink/react-native-deeplink-delegate.md).

# Handle Links with HackleDelegate

When you register a `HackleDelegate`, the SDK passes links to JavaScript without opening them.\
Use it when you want to handle links with your app's router or navigation logic, such as navigating only after checking whether the user is logged in.

## Push Links Clicked Before SDK Initialization

When a user clicks a Push Message while the app is not running, the link arrives before the SDK is initialized in JavaScript.

To receive these links through the delegate as well, configure both of the following.

* Use the native setting to defer push link handling until after SDK initialization.
* Register the delegate with the `delegate` option of `createInstance`. A delegate registered with `setDelegate` cannot receive these links.

{% tabs %}
{% tab title="iOS" %}
Add it to `Info.plist` as a Boolean value.\
Values entered as String type are ignored.

{% code title="Info.plist" %}

```xml
<key>HackleDeferPushLinkUntilInitialized</key>
<true/>
```

{% endcode %}
{% endtab %}

{% tab title="Android" %}
Add it inside `<application>` in `AndroidManifest.xml`.

{% code title="AndroidManifest.xml" %}

```xml
<meta-data
    android:name="io.hackle.android.defer_push_link_until_initialized"
    android:value="true" />
```

{% endcode %}
{% endtab %}
{% endtabs %}

<table><thead><tr><th width="200">Value</th><th>Behavior</th></tr></thead><tbody><tr><td>Not set or <code>false</code> (default)</td><td>The SDK opens push links clicked before SDK initialization right away and does not pass them to the delegate.</td></tr><tr><td><code>true</code></td><td>The SDK holds the link and delivers it once after SDK initialization.<br>If a delegate is registered, the link goes to the delegate. Otherwise, it is handled with the default behavior.</td></tr></tbody></table>

## Implementing HackleDelegate

`handleUrl` is called when the SDK needs to open a link.\
Use `channel` to distinguish Push Message links from In-App Message links.

```typescript
import { Linking } from 'react-native';
import type { HackleDelegate } from '@hackler/react-native-sdk';

const appDelegate: HackleDelegate = {
  handleUrl({ url, channel }) {
    if (channel === 'PUSH') {
      console.log('push link:', url);
    } else {
      console.log('in-app message link:', url);
    }

    if (url.startsWith('myapp://')) {
      // Handle the link with the app's router.
      AppRouter.route(url);
    } else {
      // Open http/https links the app does not handle in the browser.
      Linking.openURL(url);
    }
  },
};
```

The SDK catches and logs errors thrown in `handleUrl`.

## Registering the Delegate

* At initialization: register it with the `delegate` option of the `createInstance` config.
* After initialization: register it with `setDelegate`.
* Unregister: pass `null` to `setDelegate`.

```typescript
import { createInstance } from '@hackler/react-native-sdk';

// Register at initialization
const hackleClient = createInstance('YOUR_APP_SDK_KEY', {
  delegate: appDelegate,
});

// Register after initialization
await hackleClient.onReady();
hackleClient.setDelegate(appDelegate);

// Unregistering returns to the SDK's default link handling.
hackleClient.setDelegate(null);
```

{% hint style="warning" %}
`setDelegate` called before SDK initialization finishes may not be applied.\
To receive links from app launch, register the delegate with the `delegate` option of `createInstance`.
{% endhint %}

All clients share a single delegate, and the most recently registered delegate receives links.

## HackleUrlContext

These are the properties of the `HackleUrlContext` passed to `handleUrl`.

<table><thead><tr><th width="150">Property</th><th width="220">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>url</code></td><td><code>string</code></td><td>The link configured in the Push Message or In-App Message.<br>http/https links are also delivered.</td></tr><tr><td><code>channel</code></td><td><code>HackleUrlChannel</code></td><td><p>The path through which the link was delivered.</p><ul><li>Push Message click: <code>'PUSH'</code></li><li>In-App Message "Link" click action: <code>'IN_APP_MESSAGE'</code></li></ul></td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.hackle.io/en/development-guide/react-native/react-native-deeplink/react-native-deeplink-delegate.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
