Search…
Manage Rulesets
Provides control over which sets of advertising, tracker and social media blocking rules are active.
Rulesets are a collection of patterns that the blocking engine can use to identify advertisements and tracking requests. The SDK provides methods to specify which rulesets are active, making it easy to customize the user's browsing experience.

List the Available Rulesets

To list all the available rulesets offered by the Ad/Tracker Blocker SDK you can use the listRulesets method to retrieve the metadata of all the rulesets.
TypeScript
Swift
Kotlin
1
const rulesets: Rulesets[] = await client.listRulesets()
Copied!
1
//let client: SudoAdTrackerBlockerClient
2
client.listRulesets { [weak self] result in
3
switch result {
4
case .success(let rulesets):
5
break
6
case .failure(let error):
7
break
8
}
9
}
Copied!
1
// val client: SudoAdTrackerBlockerClient
2
3
launch {
4
try {
5
val rulesets = withContext(Dispatchers.IO) {
6
client.listRulesets()
7
}
8
// Find the advertising blocking ruleset
9
val adBlockRuleset = rulesets.find { ruleset ->
10
ruleset.type == Ruleset.Type.AD_BLOCKING
11
}
12
} catch (e: SudoAdTrackerBlockerException) {
13
// Handle/notify user of exception
14
}
15
}
Copied!
The metadata of each ruleset provides the following elements.
type
Category of the ruleset. For example: Advertising, Privacy or Social Media
updatedAt
The date/time of when the ruleset was last updated by the Ad/Tracker Blocker service

Update Rulesets

To ensure that your users are protected by the very latest version of the ad and tracker blocking rulesets you can periodically request that the SDK re-fetches the rulesets by calling the updateRulesets method.
On iOS, the latest ruleset data is always returned when your application requests content blocker data from the SDK. See Blocking Ads and Trackers on iOS.
TypeScript
Kotlin
1
/*
2
* The `updateRulesets` method returns a promise that
3
* resolves when rulesets have been updated.
4
*
5
* The rulesets are cached via the StorageProvider
6
* provided to the client.
7
*/
8
9
await client.updateRulesets()
Copied!
1
// val client: SudoAdTrackerBlockerClient
2
3
launch {
4
try {
5
withContext(Dispatchers.IO) {
6
// For example, if only interested in ads and privacy blocking
7
client.updateRulesets(
8
Ruleset.Type.AD_BLOCKING,
9
Ruleset.Type.PRIVACY
10
)
11
}
12
} catch (e: SudoAdTrackerBlockerException) {
13
// Handle/notify user of exception
14
}
15
}
Copied!
The updateRulesets method performs an HTTP request to update the rulesets. The source of a ruleset is large, typically from 0.5 to over 1 MB. This means that this operation might take some time to complete.

Getting the Active Rulesets

You can allow your users to control which sets of blocking rules are active at any time. To find the current set of active rulesets call the getActiveRulesets method.
On iOS, your application can control which content blockers to add to a custom web view. If your application provides a Content Blocking Extension, your users can enable or disable your content blocker(s) in system settings. See Blocking Ads and Trackers on iOS.
TypeScript
Kotlin
1
const activeRulesets: RulesetType[] = await client.getActiveRulesets()
Copied!
1
// val client: SudoAdTrackerBlockerClient
2
3
launch {
4
try {
5
val activeRulesets = withContext(Dispatchers.IO) {
6
client.getActiveRulesets()
7
}
8
println("Active rulesets: $activeRulesets")
9
} catch (e: SudoAdTrackerBlockerException) {
10
// Handle/notify user of exception
11
}
12
}
Copied!

Setting the Active Rulesets

You can allow your users to control which sets of blocking rules are active at any time. The rulesets that are currently active can be controlled by calling the setActiveRulesets method.
On iOS, your application can control which content blockers to add to a custom web view. If your application provides a Content Blocking Extension, your users can enable or disable your content blocker(s) in system settings. See Blocking Ads and Trackers on iOS.
TypeScript
Kotlin
1
import { RulesetType } from '@sudoplatform/sudo-ad-tracker-blocker'
2
3
/*
4
* The `setActiveRulesets` will change the active rulesets
5
* in use by the client's filtering engine, and it will
6
* save the updated preference via the storage provider.
7
*/
8
9
await client.setActiveRulesets([
10
RulesetType.AdBlocking,
11
RulesetType.Privacy
12
])
Copied!
1
// val client: SudoAdTrackerBlockerClient
2
3
launch {
4
try {
5
withContext(Dispatchers.IO) {
6
// For example, if only interested in ads and privacy blocking
7
client.setActiveRulesets(
8
Ruleset.Type.AD_BLOCKING,
9
Ruleset.Type.PRIVACY
10
)
11
}
12
} catch (e: SudoAdTrackerBlockerException) {
13
// Handle/notify user of exception
14
}
15
}
Copied!
When you change the active rulesets, the filtering engine will be reinitialized with the new rulesets. This is not instantaneous, it can take a small amount of time. To monitor the status of the filtering engine you can monitor the statusproperty as described in Filtering Status.
Last modified 1mo ago