# Integrate the Ad/Tracker Blocker SDK

## Prerequisites

1. [Complete the Getting Started Guide](/guides/getting-started.md)
2. [Integrate the User SDK](/guides/users/integrate-the-user-sdk.md)

## Get Started

* [Integrate the JS SDK](#integrate-the-web-sdk)
* [Integrate the iOS SDK](#integrate-the-ios-sdk)
* [Integrate the Android SDK](#integrate-the-android-sdk)

## Integrate the JS SDK

To use the **Ad/Tracker Blocker SDK** in a Web or Node.js project, you must add `@sudoplatform/sudo-ad-tracker-blocker` as a dependency to your project.

```bash
yarn add '@sudoplatform/sudo-ad-tracker-blocker'
# or
npm install --save '@sudoplatform/sudo-ad-tracker-blocker'
```

{% hint style="info" %}
In order to instantiate an Ad/Tracker Blocker client, make sure you have followed instructions for [Getting Started](/guides/getting-started.md) and [User SDK](/guides/users/integrate-the-user-sdk.md) (see [Prerequisites](#prerequisites) above).
{% endhint %}

### Initialize Web Assembly

The `SudoAdTrackerBlockerClient` class uses a [wasm](https://developer.mozilla.org/en-US/docs/WebAssembly) module to provide high performance filtering and thus needs to load a `.wasm` file at runtime. You can find this file in the following location after installing the Ad/Tracker Blocker package via `npm`or`yarn`:

`./node_modules/@sudoplatform/ad-tracker-blocker-client/wasm/filter_engine_bg.wasm`

You should instruct your bundler to add this file to your static assets, or deploy it to your CDN of choice.

Then use the `initWasm` helper function to instruct the SDK how to locate this file so that it can be fetched and loaded into the Web Assembly runtime. Check out the [Sample App](https://github.com/sudoplatform/samples-js/tree/main/ad-tracker-blocker) to see an example.

{% tabs %}
{% tab title="TypeScript" %}

```typescript
import { initWasm } from '@sudoplatform/sudo-ad-tracker-blocker'

async function initOnce() {
  await initWasm((file) => `/${file}`)
}
```

{% endtab %}
{% endtabs %}

**Important:** You should only invoke `initWasm` one time in your application. It does not need to be run every time you instantiate a `SudoAdTrackerBlockerClient`.

### Instantiate an Ad/Tracker Blocker Client

When creating a new instance of `SudoAdTrackerBlockerClient` you must provide an instance of `SudoUserClient` via the `sudoUserClient` property. This is used for obtaining platform authentication tokens. See the [Users](/guides/users.md)[ ](/guides/users.md)section for more information about `SudoUserClient`.

{% tabs %}
{% tab title="TypeScript" %}

```typescript
import { SudoAdTrackerBlockerClient } from '@sudoplatform/sudo-ad-tracker-blocker'
import { DefaultSudoUserClient } from '@sudoplatform/sudo-user'

const sudoUserClient = new DefaultSudoUserClient()

const client = new SudoAdTrackerBlockerClient({
  sudoUserClient,
})
```

{% endtab %}
{% endtabs %}

### Custom Storage Provider

By default, `DefaultSudoUserClient` will not persist any cached data or user preferences. To use persistent storage, you should pass a custom storage provider that implements the `StorageProvider` interface.

{% tabs %}
{% tab title="TypeScript" %}

```typescript
import { StorageProvider } from '@sudoplatform/sudo-ad-tracker-blocker'

class CustomStorage implements StorageProvider {
  // Implement StorageProvider functions here
  // See lib/storage-provider.d.ts for interface specifics
}

const client = new SudoAdTrackerBlockerClient({
  storageProvider: new CustomStorage()
  // ...
})
```

{% endtab %}
{% endtabs %}

### Check Entitlements

Import the `ENTITLEMENTS_NAME` string constant that can be compared with entitlements retrieved from the Entitlements SDK [`getEntitlements`](/guides/entitlements/end-user-api/retrieving-entitlements.md#getentitlements) method.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
// val client: SudoAdTrackerBlockerClient

val entitlementName = client.ENTITLEMENT_NAME
```

{% endtab %}
{% endtabs %}

### Reset

To reset the Ad/Tracker Blocker you can use the `reset` method. This will clear all cached data and reset user preferences back to defaults.

{% tabs %}
{% tab title="TypeScript" %}

```typescript
await client.reset()
```

{% endtab %}
{% endtabs %}

## Integrate the iOS SDK

To use the **Ad/Tracker Blocker SDK** in an iOS project add this line to your [Podfile](/guides/getting-started.md#ios-only-setup-cocoapods-in-a-project):

```swift
pod 'SudoAdTrackerBlocker'
```

Install pod dependencies by running the following command in your project directory:

```swift
pod install --repo-update
```

This will update the local CocoaPods repository and install the latest version of the Ad/Tracker Blocker SDK.

{% hint style="info" %}
In order to instantiate an Ad/Tracker Blocker client, make sure you have followed instructions for [Getting Started](/guides/getting-started.md) and [User SDK](/guides/users/integrate-the-user-sdk.md) (see [Prerequisites](#prerequisites) above)
{% endhint %}

To instantiate a client in your application, add the following:

{% tabs %}
{% tab title="Swift" %}

```swift
let userClient: SudoUserClient!
let config = try SudoAdTrackerBlockerConfig(userClient: userClient)
let client = DefaultSudoAdTrackerBlockerClient(config: config)
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
You only need one client instance for a given user per device. Instantiating multiple clients with the same configuration and using them at the same time may cause unexpected runtime errors to occur.
{% endhint %}

{% hint style="success" %}
**See it in action.** Be sure to take a look at the [open-source iOS sample app](https://github.com/sudoplatform/samples-ios/tree/master/ad-tracker-blocker) on GitHub that our team published as a reference for integrating the Ad/Tracker Blocker SDK into your app as quickly and seamlessly as possible.
{% endhint %}

## Integrate the Android SDK

To use the **Ad/Tracker Blocker SDK** in an Android project, add this line to the dependencies section of the app module `build.gradle` and run Gradle sync.

```kotlin
dependencies {
    implementation 'com.sudoplatform:sudoadtrackerblocker:1.0.0'
}
```

{% hint style="info" %}
In order to instantiate an Ad/Tracker Blocker client, make sure you have followed instructions for [Getting Started](/guides/getting-started.md) and [User SDK](/guides/users.md) (see [Prerequisites](#prerequisites) above)
{% endhint %}

To instantiate a client in your application, add the following:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
val logger = // ... use your implemenation of logger
val userClient = // ... see "Users" docs

val sudoAdTrackerBlocker = SudoAdTrackerBlockerClient.builder()
            .setContext(this)
            .setSudoUserClient(sudoUserClient)
            .setLogger(logger)
            .build()
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
You only need one client instance for a given user per device. Instantiating multiple clients with the same configuration and using them at the same time may cause unexpected runtime errors to occur.
{% endhint %}

{% hint style="success" %}
**See it in action.** Be sure to take a look at the open source [Android sample app](https://github.com/sudoplatform/samples-android/tree/master/adtrackerblocker) on GitHub that our team published as a reference for integrating the Ad/Tracker Blocker SDK into your app as quickly and seamlessly as possible.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sudoplatform.com/guides/ad-tracker-blocker/integrate-the-ad-tracker-blocker-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
