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.

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

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.

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

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

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.

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

const sudoUserClient = new DefaultSudoUserClient()

const client = new SudoAdTrackerBlockerClient({
  sudoUserClient,
})

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.

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()
  // ...
})

Check Entitlements

Import the ENTITLEMENTS_NAME string constant that can be compared with entitlements retrieved from the Entitlements SDK getEntitlements method.

// val client: SudoAdTrackerBlockerClient

val entitlementName = client.ENTITLEMENT_NAME

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.

await client.reset()

Integrate the iOS SDK

To use the Ad/Tracker Blocker SDK in an iOS project add this line to your Podfile:

pod 'SudoAdTrackerBlocker'

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

pod install --repo-update

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:

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

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.

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

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:

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

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

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 updated