Search…
Integrate the Ad/Tracker Blocker SDK
Integrate the Ad/Tracker Blocker SDK into your application

Prerequisites

Get Started

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.
1
yarn add '@sudoplatform/sudo-ad-tracker-blocker'
2
# or
3
npm install --save '@sudoplatform/sudo-ad-tracker-blocker'
Copied!
In order to instantiate an Ad/Tracker Blocker client, make sure you have followed instructions for Getting Started and User SDK (see Prerequisites above).

Initialize Web Assembly

The SudoAdTrackerBlockerClient class uses a wasm 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 npmoryarn:
./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 to see an example.
TypeScript
1
import { initWasm } from '@sudoplatform/sudo-ad-tracker-blocker'
2
​
3
async function initOnce() {
4
await initWasm((file) => `/${file}`)
5
}
Copied!
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​ section for more information about SudoUserClient.
TypeScript
1
import { SudoAdTrackerBlockerClient } from '@sudoplatform/sudo-ad-tracker-blocker'
2
import { DefaultSudoUserClient } from '@sudoplatform/sudo-user'
3
​
4
const sudoUserClient = new DefaultSudoUserClient()
5
​
6
const client = new SudoAdTrackerBlockerClient({
7
sudoUserClient,
8
})
Copied!

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.
TypeScript
1
import { StorageProvider } from '@sudoplatform/sudo-ad-tracker-blocker'
2
​
3
class CustomStorage implements StorageProvider {
4
// Implement StorageProvider functions here
5
// See lib/storage-provider.d.ts for interface specifics
6
}
7
​
8
const client = new SudoAdTrackerBlockerClient({
9
storageProvider: new CustomStorage()
10
// ...
11
})
Copied!

Check Entitlements

Import the ENTITLEMENTS_NAME string constant that can be compared with entitlements retrieved from the Entitlements SDK getEntitlements method.
Kotlin
1
// val client: SudoAdTrackerBlockerClient
2
​
3
val entitlementName = client.ENTITLEMENT_NAME
Copied!

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.
TypeScript
1
await client.reset()
Copied!

Integrate the iOS SDK

To use the Ad/Tracker Blocker SDK in an iOS project add this line to your Podfile:
1
pod 'SudoAdTrackerBlocker'
Copied!
Install pod dependencies by running the following command in your project directory:
1
pod install --repo-update
Copied!
This will update the local CocoaPods repository and install the latest version of the Ad/Tracker Blocker SDK.
In order to instantiate an Ad/Tracker Blocker client, make sure you have followed instructions for Getting Started and User SDK (see Prerequisites above)
To instantiate a client in your application, add the following:
Swift
1
let userClient: SudoUserClient!
2
let config = try SudoAdTrackerBlockerConfig(userClient: userClient)
3
let client = DefaultSudoAdTrackerBlockerClient(config: config)
Copied!
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.
See it in action. Be sure to take a look at the open-source iOS sample app 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.

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.
1
dependencies {
2
implementation 'com.sudoplatform:sudoadtrackerblocker:1.0.0'
3
}
Copied!
In order to instantiate an Ad/Tracker Blocker client, make sure you have followed instructions for Getting Started and User SDK (see Prerequisites above)
To instantiate a client in your application, add the following:
Kotlin
1
val logger = // ... use your implemenation of logger
2
val userClient = // ... see "Users" docs
3
​
4
val sudoAdTrackerBlocker = SudoAdTrackerBlockerClient.builder()
5
.setContext(this)
6
.setSudoUserClient(sudoUserClient)
7
.setLogger(logger)
8
.build()
Copied!
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.
See it in action. Be sure to take a look at the open source Android sample app 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.
Last modified 1mo ago